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 27173044ff2..0a933a2344c 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 @@ -86,28 +86,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 +158,7 @@ protected SearchResult runSearch(final Map