From bf842c67aa83e6b6274ce4d6fd5837c6bc718760 Mon Sep 17 00:00:00 2001 From: bonita-ci Date: Wed, 28 Feb 2024 10:59:06 +0100 Subject: [PATCH] WIP: report modifications coming from bonitasoft/bonita-web-sp#8.0.x (#2874) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix(api): Consider "caller" filter when searching for archived cases. When searching for an archived case, the "caller" filter should be taken in account similarly to how it behaves for active cases. Fixes [RUNTIME-1824](https://bonitasoft.atlassian.net/browse/RUNTIME-1824) Co-authored-by: Vincent Hémery --- .../bpm/cases/ArchivedCaseDatastore.java | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDatastore.java b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDatastore.java index d7975917b13..bb5f543de8d 100644 --- a/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDatastore.java +++ b/bpm/bonita-web-server/src/main/java/org/bonitasoft/web/rest/server/datastore/bpm/cases/ArchivedCaseDatastore.java @@ -21,7 +21,6 @@ import org.bonitasoft.engine.api.TenantAPIAccessor; import org.bonitasoft.engine.bpm.process.ArchivedProcessInstance; import org.bonitasoft.engine.bpm.process.ArchivedProcessInstancesSearchDescriptor; -import org.bonitasoft.engine.bpm.process.ProcessInstanceSearchDescriptor; import org.bonitasoft.engine.bpm.process.ProcessInstanceState; import org.bonitasoft.engine.exception.BonitaHomeNotSetException; import org.bonitasoft.engine.exception.ServerAPIException; @@ -86,28 +85,50 @@ public ItemSearchResult search(final int page, final int resul final String orders, final Map filters) { + final SearchOptionsBuilder builder = buildSearchOptions(page, resultsByPage, search, orders, filters); + + // Run search depending on filters passed + final SearchResult searchResult = runSearch(filters, builder); + + // Convert to ConsoleItems + return new ItemSearchResult<>( + page, + resultsByPage, + searchResult.getCount(), + convertEngineToConsoleItemsList(searchResult.getResult())); + } + + protected SearchOptionsBuilder buildSearchOptions(final int page, final int resultsByPage, final String search, + final String orders, final Map filters) { // Build search final SearchOptionsBuilder builder = SearchOptionsBuilderUtil.buildSearchOptions(page, resultsByPage, orders, search); addStringFilterToSearchBuilder(filters, builder, ArchivedCaseItem.ATTRIBUTE_PROCESS_NAME, - ProcessInstanceSearchDescriptor.NAME); + ArchivedProcessInstancesSearchDescriptor.NAME); addLongFilterToSearchBuilder(filters, builder, ArchivedCaseItem.ATTRIBUTE_PROCESS_ID, - ProcessInstanceSearchDescriptor.PROCESS_DEFINITION_ID); + ArchivedProcessInstancesSearchDescriptor.PROCESS_DEFINITION_ID); addLongFilterToSearchBuilder(filters, builder, ArchivedCaseItem.ATTRIBUTE_STARTED_BY_USER_ID, - ProcessInstanceSearchDescriptor.STARTED_BY); + ArchivedProcessInstancesSearchDescriptor.STARTED_BY); addLongFilterToSearchBuilder(filters, builder, ArchivedCaseItem.ATTRIBUTE_SOURCE_OBJECT_ID, ArchivedProcessInstancesSearchDescriptor.SOURCE_OBJECT_ID); - // Run search depending on filters passed - final SearchResult searchResult = runSearch(filters, builder); + addCallerFilterToSearchBuilderIfNecessary(filters, builder); + return builder; + } - // Convert to ConsoleItems - return new ItemSearchResult<>( - page, - resultsByPage, - searchResult.getCount(), - convertEngineToConsoleItemsList(searchResult.getResult())); + void addCallerFilterToSearchBuilderIfNecessary(final Map filters, + final SearchOptionsBuilder builder) { + /* + * By default we add a caller filter of -1 to avoid having sub processes. + * If caller is forced to any then we don't need to add the filter. + */ + if (!filters.containsKey(CaseItem.FILTER_CALLER)) { + builder.filter(ArchivedProcessInstancesSearchDescriptor.CALLER_ID, -1); + } else if (!"any".equalsIgnoreCase(filters.get(CaseItem.FILTER_CALLER))) { + builder.filter(ArchivedProcessInstancesSearchDescriptor.CALLER_ID, + MapUtil.getValueAsLong(filters, CaseItem.FILTER_CALLER)); + } } // Overridden for testing @@ -136,8 +157,7 @@ protected SearchResult runSearch(final Map