Skip to content

Commit

Permalink
chore(merge): release-10.2.0 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bonita-ci committed Sep 20, 2024
2 parents 1863757 + d3a5df0 commit a969393
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LicensesResourceVisitor extends SimpleFileVisitor<Path> {

private final List<BonitaConfiguration> 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<BonitaConfiguration> bonitaConfigurations) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -56,6 +58,29 @@ public String retrieveDatabaseSchemaVersion() throws PlatformException {
return strings.get(0);
}

@Override
public String retrievePlatformInformation() throws PlatformException {
final List<String> 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<String> strings) {
return strings == null || strings.size() != 1;
}
Expand Down

0 comments on commit a969393

Please sign in to comment.