From 4618c90ec9d8b005bb1bc5e30b915577f749612c Mon Sep 17 00:00:00 2001 From: Vincent HEMERY Date: Thu, 26 Sep 2024 10:12:02 +0200 Subject: [PATCH] fix: Set updatedBy and icon correctly on application import (#3171) * Fix: Set updatedBy and icon correctly on application import These must be set, regardless of link or legacy. Closes [BPM-252](https://bonitasoft.atlassian.net/browse/BPM-252) --- .../converter/NodeToApplicationConverter.java | 5 +++-- .../application/importer/LivingApplicationImporter.java | 4 ++-- .../converter/NodeToApplicationConverterTest.java | 9 ++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverter.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverter.java index 03b7844f647..1810f797b67 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverter.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverter.java @@ -64,6 +64,7 @@ public ImportResult toSApplication(final AbstractApplicationNode applicationNode application.setCreationDate(currentDate); application.setLastUpdateDate(currentDate); application.setCreatedBy(createdBy); + application.setUpdatedBy(createdBy); application.setIconPath(applicationNode.getIconPath()); application.setDescription(applicationNode.getDescription()); application.setState(applicationNode.getState()); @@ -73,9 +74,9 @@ public ImportResult toSApplication(final AbstractApplicationNode applicationNode if (applicationNode instanceof ApplicationNode legacy) { application.setLayoutId(getLayoutId(getLayoutName(legacy), token, importStatus)); application.setThemeId(getThemeId(getThemeName(legacy), token, importStatus)); - application.setIconContent(iconContent); - application.setIconMimeType(iconMimeType); } + application.setIconContent(iconContent); + application.setIconMimeType(iconMimeType); if (applicationNode.getProfile() != null) { setProfile(applicationNode.getProfile(), application, importStatus); diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/importer/LivingApplicationImporter.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/importer/LivingApplicationImporter.java index 4c36a977c0c..5e407f4f439 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/importer/LivingApplicationImporter.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/business/application/importer/LivingApplicationImporter.java @@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.bonitasoft.engine.api.ImportStatus; -import org.bonitasoft.engine.business.application.xml.ApplicationNode; +import org.bonitasoft.engine.business.application.xml.AbstractApplicationNode; import org.bonitasoft.engine.business.application.xml.ApplicationNodeContainer; import org.bonitasoft.engine.commons.exceptions.SBonitaException; import org.bonitasoft.engine.exception.AlreadyExistsException; @@ -137,7 +137,7 @@ protected List importProvidedApplications(final byte[] xmlContent, throws ImportException, AlreadyExistsException { List importStatuses = new ArrayList<>(); ApplicationNodeContainer applicationNodeContainer = applicationImporter.getApplicationNodeContainer(xmlContent); - for (ApplicationNode applicationNode : applicationNodeContainer.getApplications()) { + for (AbstractApplicationNode applicationNode : applicationNodeContainer.getAllApplications()) { // set the strategy to skip it if a version already exists importStatuses.add( applicationImporter.importApplication(applicationNode, editable, SessionService.SYSTEM_ID, diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverterTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverterTest.java index 8f9733e0185..6cfe9f75af9 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverterTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/business/application/converter/NodeToApplicationConverterTest.java @@ -85,7 +85,7 @@ public void setUp() throws Exception { private ImportResult convertToSApplication(final AbstractApplicationNode applicationNode, final long createdBy) throws Exception { - return converter.toSApplication(applicationNode, null, "", createdBy, true); + return converter.toSApplication(applicationNode, null, null, createdBy, true); } @Test @@ -128,6 +128,7 @@ public void toSApplication_should_return_ImportResult_with_no_errors_and_applica final SProfile profile = mock(SProfile.class); given(profile.getId()).willReturn(profileId); given(profileService.getProfileByName("admin")).willReturn(profile); + final long before = System.currentTimeMillis(); //when long createdBy = 1L; @@ -154,6 +155,12 @@ public void toSApplication_should_return_ImportResult_with_no_errors_and_applica assertThat(application.isEditable()).isEqualTo(editable); assertThat(application.isLink()).isFalse(); + // also check auto fields + final long after = System.currentTimeMillis(); + assertThat(application.getUpdatedBy()).isEqualTo(createdBy); + assertThat(application.getCreationDate()).isBetween(before, after); + assertThat(application.getLastUpdateDate()).isEqualTo(application.getCreationDate()); + final ImportStatus importStatus = importResult.getImportStatus(); assertThat(importStatus.getName()).isEqualTo("app"); assertThat(importStatus.getStatus()).isEqualTo(ImportStatus.Status.ADDED);