From a6357f6a7da812a2cd8a965af0419ee22a4b1cb3 Mon Sep 17 00:00:00 2001 From: abirembaut Date: Tue, 18 Jun 2024 16:55:54 +0200 Subject: [PATCH] feat(advanced application): add licence check (#3035) * add licence check to advanced application filter * move it to correct edition Covers [BPM-105](https://bonitasoft.atlassian.net/browse/BPM-105) Co-authored-by: Haroun EL ALAMI --- .../api/page/builder/PageItemBuilder.java | 0 .../api/application/APIApplicationIT.java | 25 +++++++------------ .../ApplicationSearchDescriptor.java | 14 +++++++---- .../engine/api/impl/ApplicationAPIImpl.java | 5 ++++ .../SearchApplicationDescriptor.java | 4 +-- .../ApplicationDataStoreCreator.java | 17 +++++++++++-- 6 files changed, 39 insertions(+), 26 deletions(-) rename bonita-integration-tests/bonita-integration-tests-web/src/{test => main}/java/org/bonitasoft/web/rest/server/api/page/builder/PageItemBuilder.java (100%) diff --git a/bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/page/builder/PageItemBuilder.java b/bonita-integration-tests/bonita-integration-tests-web/src/main/java/org/bonitasoft/web/rest/server/api/page/builder/PageItemBuilder.java similarity index 100% rename from bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/page/builder/PageItemBuilder.java rename to bonita-integration-tests/bonita-integration-tests-web/src/main/java/org/bonitasoft/web/rest/server/api/page/builder/PageItemBuilder.java diff --git a/bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/application/APIApplicationIT.java b/bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/application/APIApplicationIT.java index 48f182a33cf..43d050f013d 100644 --- a/bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/application/APIApplicationIT.java +++ b/bonita-integration-tests/bonita-integration-tests-web/src/test/java/org/bonitasoft/web/rest/server/api/application/APIApplicationIT.java @@ -17,21 +17,19 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.spy; -import java.io.File; -import java.net.URL; +import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.bonitasoft.console.common.server.preferences.constants.WebBonitaConstantsUtils; import org.bonitasoft.engine.api.ApplicationAPI; import org.bonitasoft.engine.api.PageAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.business.application.Application; import org.bonitasoft.engine.business.application.ApplicationImportPolicy; +import org.bonitasoft.engine.exception.BonitaRuntimeException; import org.bonitasoft.engine.page.Page; import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; @@ -91,12 +89,8 @@ public void cleanPagesAndApplications() throws Exception { private PageItem addPage(String pageFileName) throws Exception { final PageItem pageItem = aPageItem().build(); - final URL zipFileUrl = getClass().getResource(pageFileName); - - final File zipFile = new File(zipFileUrl.toURI()); - FileUtils.copyFileToDirectory(zipFile, WebBonitaConstantsUtils.getTenantInstance().getTempFolder()); - - final byte[] pageContent = FileUtils.readFileToByteArray(new File(zipFileUrl.toURI())); + final InputStream pageInputStream = getClass().getResourceAsStream(pageFileName); + final byte[] pageContent = IOUtils.toByteArray(pageInputStream); return addPageItemToRepository(pageItem.getContentName(), pageContent); } @@ -162,7 +156,7 @@ public void should_update_LegacyApplication() throws Exception { } @Test - public void should_search_filter_AdvancedApplications() throws Exception { + public void should_search_not_support_filtering_on_AdvancedApplications() throws Exception { // Given var legacyApp = createLegacyApplication(); @@ -171,14 +165,15 @@ public void should_search_filter_AdvancedApplications() throws Exception { final String orders = ApplicationItem.ATTRIBUTE_TOKEN + " DESC"; final HashMap filters = new HashMap<>(); filters.put(ApplicationItem.ATTRIBUTE_ADVANCED, "true"); - var searchResult = apiApplication.search(0, 1, search, orders, filters); // Then - assertTrue(searchResult.getResults().isEmpty()); + assertThrows( + "Expected exception: The search does not support filtering on advanced applications in this edition.", + BonitaRuntimeException.class, () -> apiApplication.search(0, 1, search, orders, filters)); } private AbstractApplicationItem createLegacyApplication() throws Exception { - final PageItem pageItem = addPage(HOME_PAGE_ZIP); + addPage(HOME_PAGE_ZIP); final PageItem layout = addPage(LAYOUT_ZIP); final PageItem theme = addPage(THEME_ZIP); final ApplicationItem legacyItem = ApplicationDefinition.get().createItem(); @@ -187,8 +182,6 @@ private AbstractApplicationItem createLegacyApplication() throws Exception { legacyItem.setVersion("1.0"); legacyItem.setProfileId(2L); legacyItem.setState("ACTIVATED"); - // That's the default and gets saved as -1 - // legacyItem.setHomePageId(pageItem.getId().toLong()); legacyItem.setLayoutId(layout.getId().toLong()); legacyItem.setThemeId(theme.getId().toLong()); diff --git a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/business/application/ApplicationSearchDescriptor.java b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/business/application/ApplicationSearchDescriptor.java index 83eaf08f387..ae69b4ca7e8 100755 --- a/bpm/bonita-common/src/main/java/org/bonitasoft/engine/business/application/ApplicationSearchDescriptor.java +++ b/bpm/bonita-common/src/main/java/org/bonitasoft/engine/business/application/ApplicationSearchDescriptor.java @@ -34,11 +34,6 @@ public class ApplicationSearchDescriptor { */ public static final String ID = "id"; - /** - * Used to filter or order Application items by legacy or advanced criteria - */ - public static final String ADVANCED = "advanced"; - /** * Used to filter or order by the Application token */ @@ -123,4 +118,13 @@ public class ApplicationSearchDescriptor { * @see Application */ public static final String USER_ID = "userId"; + + /** + * Used to filter or order Application items by legacy or advanced criteria + * + * @since 10.2.0 for some Subscription editions only + */ + public static final String ADVANCED = "advanced"; + // keeping this constant here for convenience reasons + // having a subscription descriptor with just this field would not be user-friendly } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java index 60d577c0069..22a100a5fd4 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java @@ -193,6 +193,11 @@ public SearchResult searchIApplications(final SearchOptions search final ServiceAccessor serviceAccessor = getServiceAccessor(); final SearchApplicationDescriptor appSearchDescriptor = serviceAccessor.getSearchEntitiesDescriptor() .getSearchApplicationDescriptor(); + return internalSearchIApplications(serviceAccessor, appSearchDescriptor, searchOptions); + } + + protected SearchResult internalSearchIApplications(ServiceAccessor serviceAccessor, + SearchApplicationDescriptor appSearchDescriptor, SearchOptions searchOptions) throws SearchException { final ApplicationModelConverter converter = getApplicationModelConverter(serviceAccessor.getPageService()); final ApplicationService applicationService = serviceAccessor.getApplicationService(); final Optional filterOnUserId = searchOptions.getFilters().stream() diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/search/descriptor/SearchApplicationDescriptor.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/search/descriptor/SearchApplicationDescriptor.java index 28feaf05963..40b31637f91 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/search/descriptor/SearchApplicationDescriptor.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/search/descriptor/SearchApplicationDescriptor.java @@ -33,7 +33,7 @@ public class SearchApplicationDescriptor extends SearchEntityDescriptor { private final Map, Set> allFields; - SearchApplicationDescriptor() { + protected SearchApplicationDescriptor() { keys = new HashMap<>(13); keys.put(ApplicationSearchDescriptor.ID, new FieldDescriptor(SApplication.class, AbstractSApplication.ID)); @@ -61,8 +61,6 @@ public class SearchApplicationDescriptor extends SearchEntityDescriptor { new FieldDescriptor(SApplication.class, AbstractSApplication.LAYOUT_ID)); keys.put(ApplicationSearchDescriptor.THEME_ID, new FieldDescriptor(SApplication.class, AbstractSApplication.THEME_ID)); - keys.put(ApplicationSearchDescriptor.ADVANCED, - new FieldDescriptor(SApplication.class, AbstractSApplication.ADVANCED)); // internal usage only for now (as it would require a conversion of the Visibility enum): keys.put(APPLICATION_VISIBILITY, new FieldDescriptor(SApplication.class, AbstractSApplication.INTERNAL_PROFILE)); diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java index 08c2f607de8..31198cc018f 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationDataStoreCreator.java @@ -18,6 +18,9 @@ import org.bonitasoft.engine.api.PageAPI; import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.exception.BonitaException; +import org.bonitasoft.engine.exception.BonitaHomeNotSetException; +import org.bonitasoft.engine.exception.ServerAPIException; +import org.bonitasoft.engine.exception.UnknownAPITypeException; import org.bonitasoft.engine.session.APISession; import org.bonitasoft.web.toolkit.client.common.exception.api.APIException; @@ -30,14 +33,24 @@ public ApplicationDataStore create(final APISession session) { ApplicationAPI applicationAPI; PageAPI pageAPI; try { - applicationAPI = TenantAPIAccessor.getLivingApplicationAPI(session); - pageAPI = TenantAPIAccessor.getCustomPageAPI(session); + applicationAPI = getLivingApplicationAPI(session); + pageAPI = getCustomPageAPI(session); return new ApplicationDataStore(session, applicationAPI, pageAPI, getApplicationConverter()); } catch (final BonitaException e) { throw new APIException(e); } } + protected PageAPI getCustomPageAPI(APISession session) + throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { + return TenantAPIAccessor.getCustomPageAPI(session); + } + + protected ApplicationAPI getLivingApplicationAPI(APISession session) + throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException { + return TenantAPIAccessor.getLivingApplicationAPI(session); + } + protected ApplicationItemConverter getApplicationConverter() { return new ApplicationItemConverter(new BonitaHomeFolderAccessor()); }