From 03522c9f64e498269d8ff3f4abc0f13fb5e7b5fc Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Tue, 2 May 2023 21:15:14 +0200 Subject: [PATCH] [DEV] implement first model of migration interface --- back/.classpath | 19 +++- back/src/org/kar/karso/WebLauncher.java | 95 ++----------------- .../kar/karso/migration/Initialization.java | 56 +++++++++++ 3 files changed, 82 insertions(+), 88 deletions(-) create mode 100644 back/src/org/kar/karso/migration/Initialization.java diff --git a/back/.classpath b/back/.classpath index e705f7e..f08c943 100644 --- a/back/.classpath +++ b/back/.classpath @@ -1,6 +1,6 @@ - + @@ -30,5 +30,22 @@ + + + + + + + + + + + + + + + + + diff --git a/back/src/org/kar/karso/WebLauncher.java b/back/src/org/kar/karso/WebLauncher.java index ca3aefe..509ed2d 100755 --- a/back/src/org/kar/karso/WebLauncher.java +++ b/back/src/org/kar/karso/WebLauncher.java @@ -2,6 +2,7 @@ package org.kar.karso; import org.kar.archidata.filter.OptionFilter; +import org.kar.archidata.migration.MigrationEngine; import org.kar.karso.api.ApplicationResource; import org.kar.karso.api.ApplicationTokenResource; import org.kar.karso.api.Front; @@ -11,22 +12,18 @@ import org.kar.karso.api.RightResource; import org.kar.karso.api.SystemConfigResource; import org.kar.karso.api.UserResource; import org.kar.karso.filter.KarsoAuthenticationFilter; -import org.kar.karso.model.Application; -import org.kar.karso.model.ApplicationToken; -import org.kar.karso.model.Right; -import org.kar.karso.model.RightDescription; -import org.kar.karso.model.Settings; -import org.kar.karso.model.UserAuth; +import org.kar.karso.migration.Initialization; import org.kar.karso.util.ConfigVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.kar.archidata.GlobalConfiguration; //import org.kar.archidata.model.Migration; -import org.kar.archidata.SqlWrapper; import org.kar.archidata.catcher.ExceptionCatcher; import org.kar.archidata.catcher.FailException404API; import org.kar.archidata.catcher.FailExceptionCatcher; import org.kar.archidata.catcher.InputExceptionCatcher; import org.kar.archidata.catcher.SystemExceptionCatcher; +import org.kar.archidata.db.DBEntry; import org.kar.archidata.filter.CORSFilter; import org.kar.archidata.util.ConfigBaseVariable; import org.kar.archidata.util.JWTWrapper; @@ -55,86 +52,10 @@ public class WebLauncher { WebLauncher.LOGGER.info("STOP the REST server:"); } - public void generateDB() { - - // generate the BDD: - try { - String out = ""; - out += SqlWrapper.createTable(Settings.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += SqlWrapper.createTable(UserAuth.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += SqlWrapper.createTable(Application.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += SqlWrapper.createTable(ApplicationToken.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += SqlWrapper.createTable(RightDescription.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += SqlWrapper.createTable(Right.class); - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - // default admin: "karadmin" password: "adminA@666" - out += """ - INSERT INTO `application` (`id`, `name`, `description`, `redirect`, `redirectDev`, `notification`, `ttl`) VALUES - ('0', 'karso', 'Root SSO interface', 'http://atria-soft/karso', '', '', '666'); - """; - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += """ - INSERT INTO `user` (`id`, `login`, `password`, `email`, `admin`) VALUES - ('0', 'karadmin', '0ddcac5ede3f1300a1ce5948ab15112f2810130531d578ab8bc4dc131652d7cf7a3ff6e827eb957bff43bc2c65a6a1d46722e5b3a2343ac3176a33ea7250080b', - 'admin@admin.ZZZ', 1); - """; - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += """ - INSERT INTO `settings` (`key`, `right`, `type`, `value`) VALUES - ('SIGN_UP_ENABLE', 'rwr-r-', 'BOOLEAN', 'false'), - ('SIGN_IN_ENABLE', 'rwr-r-', 'BOOLEAN', 'true'), - ('SIGN_UP_FILTER', 'rw----', 'STRING', '.*'), - ('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false'); - """; - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += """ - INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`) VALUES - (0, 0, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN'); - """; - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - out += """ - INSERT INTO `right` (`applicationId`, `userId`, `rightDescriptionId`, `value`) VALUES - (0, 0, 0, 'true'); - """; - LOGGER.debug(out); - SqlWrapper.executeSimpleQuerry(out); - out = ""; - //out += SqlWrapper.createTable(Migration.class); - LOGGER.debug(out); - - // Do initialization or migration: - SqlWrapper.executeSimpleQuerry(out); - - } catch (Exception e) { - // TODO Auto-generated catch block - LOGGER.error("can not generate the BD: {}", e.getMessage()); - e.printStackTrace(); - } + public void generateDB() throws Exception { + MigrationEngine migrationEngine = new MigrationEngine(); + migrationEngine.setInit(new Initialization()); + migrationEngine.migrate(DBEntry.createInterface(GlobalConfiguration.dbConfig)); } public void process() throws InterruptedException { diff --git a/back/src/org/kar/karso/migration/Initialization.java b/back/src/org/kar/karso/migration/Initialization.java new file mode 100644 index 0000000..c1b7a7e --- /dev/null +++ b/back/src/org/kar/karso/migration/Initialization.java @@ -0,0 +1,56 @@ +package org.kar.karso.migration; + +import org.kar.archidata.migration.MigrationModel; +import org.kar.archidata.migration.MigrationSqlStep; +import org.kar.karso.model.Application; +import org.kar.karso.model.ApplicationToken; +import org.kar.karso.model.Right; +import org.kar.karso.model.RightDescription; +import org.kar.karso.model.Settings; +import org.kar.karso.model.UserAuth; + +public class Initialization extends MigrationSqlStep { + + @Override + public String getName() { + return Initialization.class.getCanonicalName(); + } + + public Initialization() throws Exception { + + addClass(Settings.class); + addClass(UserAuth.class); + addClass(Application.class); + addClass(ApplicationToken.class); + addClass(RightDescription.class); + addClass(Right.class); + addClass(MigrationModel.class); + + // default admin: "karadmin" password: "adminA@666" + addAction(""" + INSERT INTO `application` (`id`, `name`, `description`, `redirect`, `redirectDev`, `notification`, `ttl`) VALUES + ('0', 'karso', 'Root SSO interface', 'http://atria-soft/karso', '', '', '666'); + """); + addAction(""" + INSERT INTO `user` (`id`, `login`, `password`, `email`, `admin`) VALUES + ('0', 'karadmin', '0ddcac5ede3f1300a1ce5948ab15112f2810130531d578ab8bc4dc131652d7cf7a3ff6e827eb957bff43bc2c65a6a1d46722e5b3a2343ac3176a33ea7250080b', + 'admin@admin.ZZZ', 1); + """); + addAction(""" + INSERT INTO `settings` (`key`, `right`, `type`, `value`) VALUES + ('SIGN_UP_ENABLE', 'rwr-r-', 'BOOLEAN', 'false'), + ('SIGN_IN_ENABLE', 'rwr-r-', 'BOOLEAN', 'true'), + ('SIGN_UP_FILTER', 'rw----', 'STRING', '.*'), + ('EMAIL_VALIDATION_REQUIRED', 'rwr-r-', 'BOOLEAN', 'false'); + """); + addAction(""" + INSERT INTO `rightDescription` (`id`, `applicationId`, `key`, `title`, `description`, `type`) VALUES + (0, 0, 'ADMIN', 'Administrator', 'Full administrator Right', 'BOOLEAN'); + """); + addAction(""" + INSERT INTO `right` (`applicationId`, `userId`, `rightDescriptionId`, `value`) VALUES + (0, 0, 0, 'true'); + """); + } + +}