From e412535ca2e501e78ce74e888be3cb895003694b Mon Sep 17 00:00:00 2001 From: abirembaut Date: Tue, 11 Jun 2024 10:04:58 +0200 Subject: [PATCH] fix(advanced application): fix filtering in REST API (#3030) * fix(advanced application): fix filtering * convert field to boolean in ApplicationSearchDescriptorConverter --- .../api/application/APIApplicationIT.java | 68 +++++++++---------- .../ApplicationSearchDescriptorConverter.java | 6 +- 2 files changed, 38 insertions(+), 36 deletions(-) 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 a2534ed53e..48f182a33c 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 @@ -14,8 +14,7 @@ package org.bonitasoft.web.rest.server.api.application; import static org.bonitasoft.web.rest.server.api.page.builder.PageItemBuilder.aPageItem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.Assert.*; import static org.mockito.Mockito.spy; import java.io.File; @@ -37,11 +36,7 @@ import org.bonitasoft.engine.search.SearchOptions; import org.bonitasoft.engine.search.SearchOptionsBuilder; import org.bonitasoft.engine.session.APISession; -import org.bonitasoft.web.rest.model.application.AbstractApplicationItem; -import org.bonitasoft.web.rest.model.application.AdvancedApplicationDefinition; -import org.bonitasoft.web.rest.model.application.AdvancedApplicationItem; -import org.bonitasoft.web.rest.model.application.ApplicationDefinition; -import org.bonitasoft.web.rest.model.application.ApplicationItem; +import org.bonitasoft.web.rest.model.application.*; import org.bonitasoft.web.rest.model.portal.page.PageItem; import org.bonitasoft.web.rest.server.api.applicationpage.APIApplicationDataStoreFactory; import org.bonitasoft.web.rest.server.datastore.application.ApplicationDataStoreCreator; @@ -127,27 +122,12 @@ public void add_AdvancedApplication_is_forbidden() { @Test public void should_add_LegacyApplication() throws Exception { // Given - final PageItem pageItem = addPage(HOME_PAGE_ZIP); - final PageItem layout = addPage(LAYOUT_ZIP); - final PageItem theme = addPage(THEME_ZIP); - final ApplicationItem legacyItem = ApplicationDefinition.get().createItem(); - legacyItem.setToken("tokenLegacy"); - legacyItem.setDisplayName("Legacy"); - 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()); - - // When - var createdItem = apiApplication.add(legacyItem); + var legacyApp = createLegacyApplication(); // Then - Map attributes = new HashMap<>(legacyItem.getAttributes().size()); - legacyItem.getAttributes().keySet().forEach(k -> attributes.put(k, createdItem.getAttributes().get(k))); - Assert.assertEquals(new HashMap<>(legacyItem.getAttributes()), attributes); + Map attributes = new HashMap<>(legacyApp.getAttributes().size()); + legacyApp.getAttributes().keySet().forEach(k -> attributes.put(k, legacyApp.getAttributes().get(k))); + Assert.assertEquals(new HashMap<>(legacyApp.getAttributes()), attributes); } @Test @@ -171,6 +151,33 @@ public void update_AdvancedApplication_is_forbidden_and_not_effective() throws E @Test public void should_update_LegacyApplication() throws Exception { // Given + var legacyApp = createLegacyApplication(); + + // When + Map attributes = Map.of(AbstractApplicationItem.ATTRIBUTE_DISPLAY_NAME, "Legacy Updated"); + var updatedItem = apiApplication.update(legacyApp.getId(), attributes); + + // Then + assertEquals("Legacy Updated", updatedItem.getDisplayName()); + } + + @Test + public void should_search_filter_AdvancedApplications() throws Exception { + // Given + var legacyApp = createLegacyApplication(); + + // When + final String search = legacyApp.getDisplayName(); + 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()); + } + + private AbstractApplicationItem createLegacyApplication() throws Exception { final PageItem pageItem = addPage(HOME_PAGE_ZIP); final PageItem layout = addPage(LAYOUT_ZIP); final PageItem theme = addPage(THEME_ZIP); @@ -185,14 +192,7 @@ public void should_update_LegacyApplication() throws Exception { legacyItem.setLayoutId(layout.getId().toLong()); legacyItem.setThemeId(theme.getId().toLong()); - var createdItem = apiApplication.add(legacyItem); - Map attributes = Map.of(AbstractApplicationItem.ATTRIBUTE_DISPLAY_NAME, "Legacy Updated"); - - // When - var updatedItem = apiApplication.update(createdItem.getId(), attributes); - - // Then - assertEquals("Legacy Updated", updatedItem.getDisplayName()); + return apiApplication.add(legacyItem); } } diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationSearchDescriptorConverter.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationSearchDescriptorConverter.java index d8b7251953..e4b7342e36 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationSearchDescriptorConverter.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/application/ApplicationSearchDescriptorConverter.java @@ -13,7 +13,6 @@ **/ package org.bonitasoft.web.rest.server.datastore.application; -import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -28,6 +27,8 @@ public class ApplicationSearchDescriptorConverter implements AttributeConverter private final Map mapping; + private final Map valueTypeMapping = new HashMap<>(); + public ApplicationSearchDescriptorConverter() { mapping = createMapping(); } @@ -36,6 +37,7 @@ private Map createMapping() { final Map mapping = new HashMap<>(); mapping.put(AbstractApplicationItem.ATTRIBUTE_ID, ApplicationSearchDescriptor.ID); mapping.put(AbstractApplicationItem.ATTRIBUTE_ADVANCED, ApplicationSearchDescriptor.ADVANCED); + valueTypeMapping.put(AbstractApplicationItem.ATTRIBUTE_ADVANCED, ItemAttribute.TYPE.BOOLEAN); mapping.put(AbstractApplicationItem.ATTRIBUTE_TOKEN, ApplicationSearchDescriptor.TOKEN); mapping.put(AbstractApplicationItem.ATTRIBUTE_DISPLAY_NAME, ApplicationSearchDescriptor.DISPLAY_NAME); mapping.put(AbstractApplicationItem.ATTRIBUTE_STATE, ApplicationSearchDescriptor.STATE); @@ -60,7 +62,7 @@ public String convert(final String attribute) { @Override public Map getValueTypeMapping() { - return Collections.emptyMap(); + return valueTypeMapping; } }