diff --git a/platform/platform-resources/src/main/java/org/bonitasoft/platform/configuration/util/LicensesResourceVisitor.java b/platform/platform-resources/src/main/java/org/bonitasoft/platform/configuration/util/LicensesResourceVisitor.java index b79ca6f322a..ecc860b7238 100644 --- a/platform/platform-resources/src/main/java/org/bonitasoft/platform/configuration/util/LicensesResourceVisitor.java +++ b/platform/platform-resources/src/main/java/org/bonitasoft/platform/configuration/util/LicensesResourceVisitor.java @@ -35,7 +35,7 @@ public class LicensesResourceVisitor extends SimpleFileVisitor { private final List bonitaConfigurations; - private final static Logger LOGGER = LoggerFactory.getLogger(LicensesResourceVisitor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(LicensesResourceVisitor.class); private Path dir; public LicensesResourceVisitor(List bonitaConfigurations) { @@ -64,7 +64,7 @@ private void initRootFolder(Path dir) { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { if (isLicenseFile(path)) { - LOGGER.info("found license file: " + path.getFileName()); + LOGGER.info("Found license file: {}", path.getFileName()); bonitaConfigurations.add(new BonitaConfiguration(path.getFileName().toString(), Files.readAllBytes(path))); } return CONTINUE; diff --git a/platform/platform-resources/src/main/java/org/bonitasoft/platform/setup/PlatformSetup.java b/platform/platform-resources/src/main/java/org/bonitasoft/platform/setup/PlatformSetup.java index 568dcfc9e57..4ef9db49834 100644 --- a/platform/platform-resources/src/main/java/org/bonitasoft/platform/setup/PlatformSetup.java +++ b/platform/platform-resources/src/main/java/org/bonitasoft/platform/setup/PlatformSetup.java @@ -81,6 +81,7 @@ public class PlatformSetup { @Getter // Used by distrib bundle tests private final ConfigurationService configurationService; + @Getter private final VersionService versionService; private final DataSource dataSource; @@ -90,7 +91,7 @@ public class PlatformSetup { private Path initialConfigurationFolder; private Path currentConfigurationFolder; private Path backupConfigurationFolder; - private Path licensesFolder; + protected Path licensesFolder; private Path backupLicensesFolder; private final ResourcePatternResolver cpResourceResolver = new PathMatchingResourcePatternResolver( PlatformSetup.class.getClassLoader()); @@ -150,7 +151,7 @@ public void init() throws PlatformException { LOGGER.warn("Database will be initialized with configuration files from classpath"); insertNewConfigurationsFromClasspathIfExist(); } - pushLicenses(); + pushLicenses(true); LOGGER.info("Initial configuration files successfully pushed to database"); initializeTenant(); @@ -215,9 +216,10 @@ public void push(boolean forcePush) throws PlatformException { ensureNoCriticalFoldersAreDeleted(forcePush); pull(backupConfigurationFolder, backupLicensesFolder); LOGGER.info("Backup directory created: {}", backupConfigurationFolder); + var hasLicenses = !getConfigurationService().getLicenses().isEmpty(); clean(); pushFromFolder(currentConfigurationFolder); - pushLicenses(); + pushLicenses(hasLicenses); LOGGER.info( "Configuration files successfully pushed to database. You can now restart Bonita to reflect your changes."); } @@ -332,13 +334,8 @@ private void checkPlatformVersion() throws PlatformException { /** * lookup for license file and push them to database */ - private void pushLicenses() throws PlatformException { - if (!Files.isDirectory(licensesFolder)) { - //do nothing in community - return; - } - LOGGER.info("Pushing license files from folder: {}", licensesFolder); - configurationService.storeLicenses(licensesFolder.toFile()); + protected void pushLicenses(boolean hasLicenses) throws PlatformException { + // Nothing to do in community } private void initializePlatform() throws PlatformException { diff --git a/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/VersionService.java b/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/VersionService.java index b47f880c0b2..0bb91a91661 100644 --- a/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/VersionService.java +++ b/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/VersionService.java @@ -27,6 +27,21 @@ public interface VersionService { */ String retrieveDatabaseSchemaVersion() throws PlatformException; + /** + * Retrieves the platform information in database + * + * @return platform information + * @throws PlatformException + */ + String retrievePlatformInformation() throws PlatformException; + + /** + * Clear platform information + * + * @throws PlatformException + */ + void clearPlatformInformation() throws PlatformException; + /** * Retrieves the platform setup tool version * diff --git a/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/impl/VersionServiceImpl.java b/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/impl/VersionServiceImpl.java index 9cfc46b226d..10c414a465a 100644 --- a/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/impl/VersionServiceImpl.java +++ b/platform/platform-resources/src/main/java/org/bonitasoft/platform/version/impl/VersionServiceImpl.java @@ -33,7 +33,9 @@ @Service public class VersionServiceImpl implements VersionService { - private static final String SQL_PLATFORM_VERSION = "SELECT p.version FROM platform p ORDER BY p.id"; + private static final String SQL_PLATFORM_VERSION = "SELECT p.version FROM platform p"; + private static final String SQL_PLATFORM_INFORMATION = "SELECT p.information FROM platform p"; + private static final String SQL_CLEAR_PLATFORM_INFORMATION = "UPDATE platform SET information = NULL"; private JdbcTemplate jdbcTemplate; @@ -56,6 +58,29 @@ public String retrieveDatabaseSchemaVersion() throws PlatformException { return strings.get(0); } + @Override + public String retrievePlatformInformation() throws PlatformException { + final List strings; + try { + strings = jdbcTemplate.queryForList(SQL_PLATFORM_INFORMATION, String.class); + } catch (DataAccessException e) { + throw new PlatformException("Platform is not created. Run 'setup init' first.", e); + } + if (hasNotSingleResult(strings)) { + throw new PlatformException("Platform is not created. Run 'setup init' first."); + } + return strings.get(0); + } + + @Override + public void clearPlatformInformation() throws PlatformException { + try { + jdbcTemplate.execute(SQL_CLEAR_PLATFORM_INFORMATION); + } catch (DataAccessException e) { + throw new PlatformException("Unable to clear platform information", e); + } + } + private boolean hasNotSingleResult(List strings) { return strings == null || strings.size() != 1; }