Skip to content

Commit

Permalink
feat(application-installer): remove install-provided-pages property (…
Browse files Browse the repository at this point in the history
…#2726)
  • Loading branch information
akantcheff authored Sep 25, 2023
1 parent 9c679cd commit df841cf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,9 @@
import static java.lang.System.lineSeparator;
import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.bonitasoft.engine.api.result.Status.errorStatus;
import static org.bonitasoft.engine.api.result.Status.infoStatus;
import static org.bonitasoft.engine.api.result.Status.warningStatus;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_DEPLOYMENT;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_APPLICATION_PAGE;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_LAYOUT;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_PAGE;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_PROFILE;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_THEME;
import static org.bonitasoft.engine.api.result.StatusCode.ORGANIZATION_IMPORT_WARNING;
import static org.bonitasoft.engine.api.result.StatusCode.PAGE_DEPLOYMENT_CREATE_NEW;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_CREATE_NEW;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_DISABLEMENT_OK;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_ENABLEMENT_KO;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_ENABLEMENT_OK;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_SKIP_INSTALL;
import static org.bonitasoft.engine.api.result.StatusContext.LIVING_APPLICATION_IMPORT_STATUS_KEY;
import static org.bonitasoft.engine.api.result.StatusContext.LIVING_APPLICATION_INVALID_ELEMENT_NAME;
import static org.bonitasoft.engine.api.result.StatusContext.LIVING_APPLICATION_INVALID_ELEMENT_TYPE;
import static org.bonitasoft.engine.api.result.StatusContext.LIVING_APPLICATION_TOKEN_KEY;
import static org.bonitasoft.engine.api.result.StatusContext.PAGE_NAME_KEY;
import static org.bonitasoft.engine.api.result.StatusContext.PROCESS_NAME_KEY;
import static org.bonitasoft.engine.api.result.StatusContext.PROCESS_VERSION_KEY;
import static org.bonitasoft.engine.api.result.Status.*;
import static org.bonitasoft.engine.api.result.StatusCode.*;
import static org.bonitasoft.engine.api.result.StatusContext.*;
import static org.bonitasoft.engine.bpm.process.ActivationState.DISABLED;
import static org.bonitasoft.engine.bpm.process.ConfigurationState.RESOLVED;
import static org.bonitasoft.engine.business.application.ApplicationImportPolicy.FAIL_ON_DUPLICATES;
Expand All @@ -60,7 +40,6 @@
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import javax.xml.bind.JAXBException;
Expand Down Expand Up @@ -164,14 +143,6 @@ public class ApplicationInstaller {
private final Long tenantId;
private final ApplicationNodeContainerConverter appXmlConverter = new ApplicationNodeContainerConverter();

@VisibleForTesting
static final String WARNING_MISSING_PAGE_MESSAGE = "If your are using pages from Bonita Admin or User applications, "
+
"ensure to set the Bonita runtime property " +
"'bonita.runtime.custom-application.install-provided-pages=true' " +
"or the environment variable 'INSTALL_PROVIDED_PAGES=true " +
"(if you are in docker context) in order to install those pages";

@Autowired
public ApplicationInstaller(InstallationService installationService,
@Qualifier("businessDataModelRepository") BusinessDataModelRepository bdmRepository,
Expand Down Expand Up @@ -542,7 +513,6 @@ protected void installLivingApplications(ApplicationArchive applicationArchive,
throws AlreadyExistsException, ImportException, ApplicationInstallationException {
try {
boolean atLeastOneBlockingProblem = false;
var displaySpecificErrorMessage = new AtomicBoolean(false);
for (File livingApplicationFile : applicationArchive.getApplications()) {
log.info("Installing Living Application from file '{}'", livingApplicationFile.getName());
var appContainer = appXmlConverter
Expand All @@ -558,10 +528,6 @@ protected void installLivingApplications(ApplicationArchive applicationArchive,
errors.forEach(error -> {
Status errorStatus = buildErrorStatus(error, livingApplicationFile.getName());
executionResult.addStatus(errorStatus);
if (!displaySpecificErrorMessage.get()
&& errorStatus.getCode() == LIVING_APP_REFERENCES_UNKNOWN_PAGE) {
displaySpecificErrorMessage.set(true);
}
});

atLeastOneBlockingProblem = true;
Expand All @@ -577,11 +543,6 @@ protected void installLivingApplications(ApplicationArchive applicationArchive,
}

if (atLeastOneBlockingProblem) {
if (displaySpecificErrorMessage.get()) {
executionResult.addStatus(
warningStatus(LIVING_APP_REFERENCES_UNKNOWN_PAGE, WARNING_MISSING_PAGE_MESSAGE,
null));
}
throw new ApplicationInstallationException(
"At least one application failed to be installed. Canceling installation.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public class CustomOrDefaultApplicationInstaller {
@Getter
protected String applicationInstallFolder;

@Value("${bonita.runtime.custom-application.install-provided-pages:false}")
@Getter
protected boolean addDefaultPages;

protected final ApplicationInstaller applicationInstaller;

private final DefaultLivingApplicationImporter defaultLivingApplicationImporter;
Expand Down Expand Up @@ -101,11 +97,6 @@ public void autoDeployDetectedCustomApplication(PlatformStartedEvent event)
customApplication.getFilename(),
applicationInstallFolder);
if (isPlatformFirstInitialization()) {
// install default page
if (isAddDefaultPages()) {
//TODO do we want to change this behaviour?
installDefaultProvidedPages();
}
// install application if it exists and if it is the first init of the platform
log.info("Bonita now tries to install it automatically...");
installCustomApplication(customApplication, newVersion);
Expand Down Expand Up @@ -201,7 +192,7 @@ Resource[] getCustomAppResourcesFromClasspath() throws IOException {

/**
* @param customApplication custom application resource
* @param version
* @param version version of the custom application
* @throws ApplicationInstallationException if unable to install the application
*/
protected void updateCustomApplication(final Resource customApplication, Semver version)
Expand Down Expand Up @@ -230,7 +221,7 @@ private void setConfigurationFile(ApplicationArchive applicationArchive)

/**
* @param customApplication custom application resource
* @param version
* @param version version of the custom application
* @throws ApplicationInstallationException if unable to install the application
*/
protected void installCustomApplication(final Resource customApplication, Semver version) throws Exception {
Expand Down Expand Up @@ -266,19 +257,6 @@ void installDefaultProvidedApplications() throws ApplicationInstallationExceptio
}
}

@VisibleForTesting
void installDefaultProvidedPages() throws ApplicationInstallationException {
try {
// default app importer requires a tenant session and to be executed inside a transaction
tenantServicesManager.inTenantSessionTransaction(() -> {
defaultLivingApplicationImporter.importDefaultPages();
return null;
});
} catch (Exception e) {
throw new ApplicationInstallationException("Unable to import default pages", e);
}
}

protected Optional<Resource> detectConfigurationFile() throws IOException, ApplicationInstallationException {
log.info("Trying to detect configuration file (.bconf file from folder {})", applicationInstallFolder);
return Optional.ofNullable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void execute() {
log.info("Import of Bonita default applications completed");
}

public void importDefaultPages() {
private void importDefaultPages() {
try {
if (addRemovablePagesIfMissing) {
log.info("Detected a first run (a tenant creation or an installation from scratch), "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,3 @@ org.quartz.jobStore.acquireTriggersWithinLock=false
org.quartz.scheduler.batchTriggerAcquisitionMaxCount=1
# consider that a job can fire this amount of ms before its actual fire time
org.quartz.scheduler.batchTriggerAcquisitionFireAheadTimeWindow=0

#install non-mandatory default page, even if a custom app is detected.
bonita.runtime.custom-application.install-provided-pages=false
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,18 @@
package org.bonitasoft.engine.api.impl.application.installer;

import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.from;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.Assertions.*;
import static org.bonitasoft.engine.api.result.Status.Level.ERROR;
import static org.bonitasoft.engine.api.result.Status.Level.INFO;
import static org.bonitasoft.engine.api.result.Status.Level.WARNING;
import static org.bonitasoft.engine.api.result.StatusCode.LIVING_APP_REFERENCES_UNKNOWN_PAGE;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_ENABLEMENT_KO;
import static org.bonitasoft.engine.api.result.StatusCode.PROCESS_DEPLOYMENT_SKIP_INSTALL;
import static org.bonitasoft.engine.api.result.StatusCode.*;
import static org.bonitasoft.engine.api.result.StatusContext.PROCESS_NAME_KEY;
import static org.bonitasoft.engine.api.result.StatusContext.PROCESS_VERSION_KEY;
import static org.bonitasoft.engine.business.application.ApplicationImportPolicy.FAIL_ON_DUPLICATES;
import static org.bonitasoft.engine.io.FileAndContentUtils.file;
import static org.bonitasoft.engine.io.FileAndContentUtils.zip;
import static org.bonitasoft.engine.io.IOUtils.createTempFile;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -201,13 +187,12 @@ public void should_not_install_living_applications_if_page_missing() throws Exce
}
verify(applicationInstaller).importApplication(any(), any(), eq(FAIL_ON_DUPLICATES));

assertThat(result.getAllStatus()).hasSize(3).extracting("code")
assertThat(result.getAllStatus()).hasSize(2).extracting("code")
.containsOnly(LIVING_APP_REFERENCES_UNKNOWN_PAGE);
assertThat(result.getAllStatus()).extracting("message")
.containsExactly("Unknown PAGE named 'page'", "Unknown PAGE named 'test'",
ApplicationInstaller.WARNING_MISSING_PAGE_MESSAGE);
.containsExactly("Unknown PAGE named 'page'", "Unknown PAGE named 'test'");
assertThat(result.getAllStatus()).extracting("level")
.containsExactly(ERROR, ERROR, WARNING);
.containsExactly(ERROR, ERROR);
}

private byte[] applicationContent(ApplicationNode application) throws JAXBException, IOException, SAXException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.bonitasoft.engine.tenant.TenantServicesManager;
import org.bonitasoft.platform.version.ApplicationVersionService;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,6 +30,7 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(Enclosed.class)
public class CustomOrDefaultApplicationInstallerConfigTest {

@RunWith(SpringRunner.class)
Expand Down Expand Up @@ -56,20 +58,17 @@ public static class CustomOrDefaultApplicationInstallerDefaultConfigTest extends
@Test
public void should_application_install_folder_have_default_value() {
assertThat(installer.getApplicationInstallFolder()).isEqualTo("my-application");
assertThat(installer.isAddDefaultPages()).isFalse();
}
}

@TestPropertySource(properties = {
"bonita.runtime.custom-application.install-folder=my-carpeta-personalizada",
"bonita.runtime.custom-application.install-provided-pages=true",
})
public static class CustomOrDefaultApplicationInstallerOverwrittenConfigTest extends AbstractConfigTest {

@Test
public void should_support_application_install_folder_overwrite() {
assertThat(installer.getApplicationInstallFolder()).isEqualTo("my-carpeta-personalizada");
assertThat(installer.isAddDefaultPages()).isTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void supportedApplicationVersions(String version)
}

@Test
void should_install_custom_application_if_detected_and_platform_first_init_and_install_provided_resources_is_false()
void should_install_custom_application_if_detected_and_platform_first_init()
throws Exception {
//given
Resource resource1 = mockResource("resource1", true, true, 0L);
Expand All @@ -175,38 +175,11 @@ void should_install_custom_application_if_detected_and_platform_first_init_and_i
final ApplicationArchive applicationArchive = mock(ApplicationArchive.class);
doReturn(applicationArchive).when(listener).getApplicationArchive(resourceStream1);
doReturn(true).when(listener).isPlatformFirstInitialization();
doReturn(false).when(listener).isAddDefaultPages();
//when
listener.autoDeployDetectedCustomApplication(any());

//then
verify(defaultLivingApplicationImporter, never()).importDefaultPages();
verify(applicationInstaller).install(applicationArchive, "1.0.0");

verify(defaultLivingApplicationImporter, never()).execute();
}

@Test
void should_install_custom_application_and_provided_provide_page_if_detected_and_platform_first_init_and_install_provided_resources_is_true()
throws Exception {
//given
Resource resource1 = mockResource("resource1", true, true, 0L);
InputStream resourceStream1 = mock(InputStream.class);

doReturn(resource1).when(listener).detectCustomApplication();
doReturn(Optional.of(new Semver("1.0.0"))).when(listener).readApplicationVersion(resource1);
doReturn(resourceStream1).when(resource1).getInputStream();
final ApplicationArchive applicationArchive = mock(ApplicationArchive.class);
doReturn(applicationArchive).when(listener).getApplicationArchive(resourceStream1);
doReturn(true).when(listener).isPlatformFirstInitialization();
doReturn(true).when(listener).isAddDefaultPages();
//when
listener.autoDeployDetectedCustomApplication(any());

//then
InOrder inOrder = inOrder(defaultLivingApplicationImporter, applicationInstaller);
inOrder.verify(defaultLivingApplicationImporter).importDefaultPages();
inOrder.verify(applicationInstaller).install(applicationArchive, "1.0.0");
verify(defaultLivingApplicationImporter, never()).execute();
}

Expand Down Expand Up @@ -284,7 +257,6 @@ void should_install_default_applications_if_no_custom_app_detected()
//then
verify(applicationInstaller, never()).install(any(), eq("1.0.0"));
verify(defaultLivingApplicationImporter).execute();
verify(defaultLivingApplicationImporter, never()).importDefaultPages();
}

@Test
Expand Down

0 comments on commit df841cf

Please sign in to comment.