From e8bf5611ad128f2acdf1b9dc3dfaae8f54d56daa Mon Sep 17 00:00:00 2001 From: mnhnam-axonivy Date: Wed, 25 Dec 2024 12:01:10 +0700 Subject: [PATCH] IVYPORTAL-17694 Remove usages of deprecated methods Query#fromJson and Query#asJson - Replaced methods --- .../internal/CaseHistoryLazyDataModel.java | 2 - .../searchcriteria/CaseSearchCriteria.java | 18 ++------ .../ivydata/service/impl/CaseService.java | 3 +- .../datamodel/CaseLazyDataModel.java | 41 +---------------- .../datamodel/TaskLazyDataModel.java | 44 ++----------------- .../internal/RelatedCaseLazyDataModel.java | 1 - .../internal/RelatedTaskLazyDataModel.java | 1 - .../CaseCategorySearchCriteria.java | 2 +- .../searchcriteria/CaseSearchCriteria.java | 39 ++++++++++------ .../TaskCategorySearchCriteria.java | 5 +-- .../searchcriteria/TaskSearchCriteria.java | 43 +++++++++++------- .../ivydata/service/impl/CaseService.java | 8 ++-- .../ivydata/service/impl/TaskService.java | 25 ++++++----- .../DashboardWidgetInformationService.java | 6 ++- .../TaskWidget/TaskWidgetProcess.p.json | 4 +- 15 files changed, 87 insertions(+), 155 deletions(-) diff --git a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/datamodel/internal/CaseHistoryLazyDataModel.java b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/datamodel/internal/CaseHistoryLazyDataModel.java index 6c8281d40af..7ec4ee983e9 100644 --- a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/datamodel/internal/CaseHistoryLazyDataModel.java +++ b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/datamodel/internal/CaseHistoryLazyDataModel.java @@ -116,8 +116,6 @@ private void buildQueryToSearchCriteria() { .isEqual(businessEntityId); criteria.setCustomCaseQuery(caseQuery); } - - criteria.setFinalCaseQuery(criteria.createQuery()); } public String getBusinessEntityId() { diff --git a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/searchcriteria/CaseSearchCriteria.java b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/searchcriteria/CaseSearchCriteria.java index 39b1ff8d9f8..dfa79895c92 100644 --- a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/searchcriteria/CaseSearchCriteria.java +++ b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/searchcriteria/CaseSearchCriteria.java @@ -14,6 +14,7 @@ import org.apache.commons.lang.StringUtils; import com.axonivy.portal.components.enums.CaseSortField; + import ch.ivyteam.ivy.workflow.CaseState; import ch.ivyteam.ivy.workflow.query.CaseQuery; import ch.ivyteam.ivy.workflow.query.CaseQuery.IFilterQuery; @@ -39,11 +40,9 @@ public class CaseSearchCriteria { private boolean isNewQueryCreated; private boolean isSorted = true; private CaseQuery customCaseQuery; - - private CaseQuery finalCaseQuery; + private boolean isGlobalSearchScope; - @SuppressWarnings("deprecation") public CaseQuery createQuery() { CaseQuery finalQuery; if (isBusinessCase) { @@ -56,7 +55,7 @@ public CaseQuery createQuery() { setNewQueryCreated(isNewQueryCreated() || customCaseQuery == null || hasCaseId()); if (!isNewQueryCreated()) { - finalQuery.where().andOverall(CaseQuery.fromJson(customCaseQuery.asJson())); // clone to keep the original custom query + finalQuery.where().andOverall(customCaseQuery); } if (hasIncludedStates()) { @@ -377,17 +376,6 @@ public boolean hasInvolvedUsername() { return StringUtils.isNotBlank(involvedUsername); } - public CaseQuery getFinalCaseQuery() { - if (finalCaseQuery == null) { - finalCaseQuery = createQuery(); - } - return finalCaseQuery; - } - - public void setFinalCaseQuery(CaseQuery finalCaseQuery) { - this.finalCaseQuery = finalCaseQuery; - } - public boolean isCaseOwnerEnabled() { return isCaseOwnerEnabled; } diff --git a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/service/impl/CaseService.java b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/service/impl/CaseService.java index 1bc6120e81b..1246bc0235e 100644 --- a/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/service/impl/CaseService.java +++ b/AxonIvyPortal/portal-components/src/com/axonivy/portal/components/ivydata/service/impl/CaseService.java @@ -42,8 +42,7 @@ public IvyCaseResultDTO countCasesByCriteria(CaseSearchCriteria criteria) { } private CaseQuery extendQuery(CaseSearchCriteria criteria) { - CaseQuery finalQuery = criteria.getFinalCaseQuery(); - CaseQuery clonedQuery = CaseQuery.fromJson(finalQuery.asJson()); // clone to keep the final query in CaseSearchCriteria + CaseQuery clonedQuery = criteria.createQuery(); if (!criteria.isAdminQuery()) { clonedQuery.where().and(queryForCurrentUser(criteria.isTechnicalCase(), criteria.isCaseOwnerEnabled())); diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/CaseLazyDataModel.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/CaseLazyDataModel.java index 83134a3b1e4..388a9a2873b 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/CaseLazyDataModel.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/CaseLazyDataModel.java @@ -47,7 +47,6 @@ import ch.ivyteam.ivy.workflow.CaseState; import ch.ivyteam.ivy.workflow.ICase; import ch.ivyteam.ivy.workflow.query.CaseQuery; -import ch.ivyteam.ivy.workflow.query.CaseQuery.IFilterQuery; public class CaseLazyDataModel extends LazyDataModel { public static final String DESCRIPTION = "DESCRIPTION"; @@ -338,46 +337,10 @@ protected void buildQueryToSearchCriteria() { criteria.setIncludedStates(filterContainer.getStateFilter().getSelectedFilteredStates()); } } - buildSort(); - CaseQuery caseQuery = buildCaseQuery(); - extendSort(caseQuery); - this.criteria.setFinalCaseQuery(caseQuery); - } + criteria.setLegacyFilters(selectedFilters); - /** - *

- * If your customized case list has new columns/fields, please extend the {@code caseQuery} parameter with the sort - * query for these fields. - *

- *

- * Example:

-   * if ("CustomerName".equalsIgnoreCase(criteria.getSortField())) {
-   *   if (criteria.isSortDescending()) {
-   *     caseQuery.orderBy().customField().stringField("CustomerName").descending();
-   *   } else {
-   *     caseQuery.orderBy().customField().stringField("CustomerName");
-   *   }
-   * }
-   * 
- *

- * - * @param caseQuery case query {@link CaseQuery} - */ - public void extendSort(@SuppressWarnings("unused") CaseQuery caseQuery) { - // Placeholder for customization - } - - private CaseQuery buildCaseQuery() { - CaseQuery caseQuery = criteria.createQuery(); - IFilterQuery filterQuery = caseQuery.where(); - selectedFilters.forEach(selectedFilter -> { - CaseQuery subQuery = selectedFilter.buildQuery(); - if (subQuery != null) { - filterQuery.and(subQuery); - } - }); + buildSort(); storeCaseFiltersIntoSession(); - return caseQuery; } private void storeCaseFiltersIntoSession() { diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/TaskLazyDataModel.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/TaskLazyDataModel.java index 6fd29c119fb..493def9bd9c 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/TaskLazyDataModel.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/TaskLazyDataModel.java @@ -48,7 +48,6 @@ import ch.ivyteam.ivy.workflow.ITask; import ch.ivyteam.ivy.workflow.TaskState; import ch.ivyteam.ivy.workflow.query.TaskQuery; -import ch.ivyteam.ivy.workflow.query.TaskQuery.IFilterQuery; public class TaskLazyDataModel extends LazyDataModel { public static final String DESCRIPTION = "DESCRIPTION"; @@ -323,29 +322,6 @@ private boolean isSortedDescendingByDefault() { return !SortFieldUtil.isAscendingSort(SortDirection.DESC.name()); } - /** - *

- * If your customized task list has new columns/fields, please extend the {@code taskQuery} - * parameter with the sort query for these fields. - *

- *

- * Example:

-   * if ("CustomerType".equalsIgnoreCase(criteria.getSortField())) {
-   *   if (criteria.isSortDescending()) {
-   *     taskQuery.orderBy().customField().stringField("CustomerType").descending();
-   *   } else {
-   *     taskQuery.orderBy().customField().stringField("CustomerType");
-   *   }
-   * }
-   * 
- *

- * - * @param taskQuery task query {@link TaskQuery} - */ - public void extendSort(@SuppressWarnings("unused") TaskQuery taskQuery) { - // Placeholder for customization - } - public void setSortField(String sortField, boolean sortDescending) { updateSortCriteria(sortField, sortDescending, true); } @@ -567,7 +543,7 @@ public boolean hasReadAllTasksPermisson() { } /** - * Builds and converts TaskQuery to JsonQuery and put it into TaskSearchCriteria. + * Builds TaskQuery and put it into TaskSearchCriteria. */ protected void buildQueryToSearchCriteria() { if (criteria.getCustomTaskQuery() == null) { @@ -586,9 +562,8 @@ protected void buildQueryToSearchCriteria() { } } - TaskQuery taskQuery = buildTaskQuery(); - extendSort(taskQuery); - criteria.setFinalTaskQuery(taskQuery); + criteria.setLegacyFilters(selectedFilters); + storeTaskFiltersIntoSession(); } protected void setValuesForStateFilter(TaskSearchCriteria criteria, TaskFilterContainer filterContainer) { @@ -600,19 +575,6 @@ protected void setValuesForStateFilter(TaskSearchCriteria criteria, TaskFilterCo } } - protected TaskQuery buildTaskQuery() { - TaskQuery taskQuery = criteria.createQuery(); - IFilterQuery filterQuery = taskQuery.where(); - selectedFilters.forEach(selectedFilter -> { - TaskQuery subQuery = selectedFilter.buildQuery(); - if (subQuery != null) { - filterQuery.and(subQuery); - } - }); - storeTaskFiltersIntoSession(); - return taskQuery; - } - private void storeTaskFiltersIntoSession() { if (shouldSaveAndLoadSessionFilters()) { UserUtils.setSessionSelectedDefaultTaskFilterSetAttribute(isSelectedDefaultFilter); diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedCaseLazyDataModel.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedCaseLazyDataModel.java index 6312a91a3f9..b779f8a6673 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedCaseLazyDataModel.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedCaseLazyDataModel.java @@ -113,7 +113,6 @@ private UIComponent findRelatedCaseComponent() { private void initializedDataModel() { data.clear(); - criteria.setFinalCaseQuery(null); } private int getCaseCount(CaseSearchCriteria criteria) { diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedTaskLazyDataModel.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedTaskLazyDataModel.java index 9e354ecfb9b..305c89cb66d 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedTaskLazyDataModel.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/datamodel/internal/RelatedTaskLazyDataModel.java @@ -133,7 +133,6 @@ protected int getTaskCount(TaskSearchCriteria criteria) { private void initializedDataModel() { data.clear(); - criteria.setFinalTaskQuery(null); } @Override diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseCategorySearchCriteria.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseCategorySearchCriteria.java index d5455e3ed5e..ab91e965d64 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseCategorySearchCriteria.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseCategorySearchCriteria.java @@ -20,7 +20,7 @@ public class CaseCategorySearchCriteria { public CaseQuery createQuery() { CaseQuery finalQuery = CaseUtils.createBusinessCaseQuery(); if (customCaseQuery != null) { - finalQuery = CaseQuery.fromJson(customCaseQuery.asJson()); // clone to keep the original custom query + finalQuery.where().andOverall(customCaseQuery); } if (hasIncludedStates()) { diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseSearchCriteria.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseSearchCriteria.java index c10254dedb4..4d11e8c8ba1 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseSearchCriteria.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/CaseSearchCriteria.java @@ -16,6 +16,7 @@ import com.axonivy.portal.enums.SearchScopeCaseField; +import ch.ivy.addon.portalkit.casefilter.CaseFilter; import ch.ivy.addon.portalkit.enums.CaseSortField; import ch.ivyteam.ivy.workflow.CaseState; import ch.ivyteam.ivy.workflow.caze.CaseBusinessState; @@ -44,12 +45,12 @@ public class CaseSearchCriteria { private boolean isNewQueryCreated; private boolean isSorted = true; private CaseQuery customCaseQuery; - - private CaseQuery finalCaseQuery; private boolean isGlobalSearch; private boolean isGlobalSearchScope; private List searchScopeCaseFields; + + private List legacyFilters; public CaseQuery createQuery() { CaseQuery finalQuery; @@ -63,7 +64,7 @@ public CaseQuery createQuery() { setNewQueryCreated(isNewQueryCreated() || customCaseQuery == null || hasCaseId()); if (!isNewQueryCreated()) { - finalQuery.where().andOverall(CaseQuery.fromJson(customCaseQuery.asJson())); // clone to keep the original custom query + finalQuery.where().andOverall(customCaseQuery); } if (hasIncludedStates()) { @@ -82,6 +83,8 @@ public CaseQuery createQuery() { finalQuery.where().and(queryForCategory(getCategory())); } + queryLegacyFilters(finalQuery); + if (isSorted) { CaseSortingQueryAppender appender = new CaseSortingQueryAppender(finalQuery); finalQuery = appender.appendSorting(this).toQuery(); @@ -98,6 +101,17 @@ private CaseQuery queryForStates(List states) { return stateFieldQuery; } + private void queryLegacyFilters(CaseQuery finalQuery) { + if (CollectionUtils.isNotEmpty(legacyFilters)) { + for (CaseFilter filter : legacyFilters) { + CaseQuery subQuery = filter.buildQuery(); + if (subQuery != null) { + finalQuery.where().and(subQuery); + } + } + } + } + private CaseQuery queryForKeyword(String keyword) { String containingKeyword = String.format("%%%s%%", keyword.trim()); CaseQuery filterByKeywordQuery = newCaseQuery(); @@ -375,17 +389,6 @@ public void setNewQueryCreated(boolean isNewQueryCreated) { this.isNewQueryCreated = isNewQueryCreated; } - public CaseQuery getFinalCaseQuery() { - if (finalCaseQuery == null) { - finalCaseQuery = createQuery(); - } - return finalCaseQuery; - } - - public void setFinalCaseQuery(CaseQuery finalCaseQuery) { - this.finalCaseQuery = finalCaseQuery; - } - public List getSearchScopeCaseFields() { return searchScopeCaseFields; } @@ -409,4 +412,12 @@ public void setGlobalSearchScope(boolean isGlobalSearchScope) { this.isGlobalSearchScope = isGlobalSearchScope; } + public List getLegacyFilters() { + return legacyFilters; + } + + public void setLegacyFilters(List legacyFilters) { + this.legacyFilters = legacyFilters; + } + } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskCategorySearchCriteria.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskCategorySearchCriteria.java index e4bc52f5782..614a4374aa0 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskCategorySearchCriteria.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskCategorySearchCriteria.java @@ -14,12 +14,11 @@ public class TaskCategorySearchCriteria { private List includedStates; private TaskQuery customTaskQuery; - - @SuppressWarnings("deprecation") + public TaskQuery createQuery() { TaskQuery query = TaskQuery.create(); if (customTaskQuery != null) { - query = TaskQuery.fromJson(customTaskQuery.asJson()); // clone to keep the original custom query + query.where().andOverall(customTaskQuery); } if (hasIncludedStates()) { diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskSearchCriteria.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskSearchCriteria.java index fba8c3cdc03..e02dbebe9a3 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskSearchCriteria.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/searchcriteria/TaskSearchCriteria.java @@ -24,6 +24,7 @@ import ch.ivy.addon.portalkit.enums.TaskAssigneeType; import ch.ivy.addon.portalkit.enums.TaskSortField; +import ch.ivy.addon.portalkit.taskfilter.TaskFilter; import ch.ivyteam.ivy.workflow.TaskState; import ch.ivyteam.ivy.workflow.query.TaskQuery; import ch.ivyteam.ivy.workflow.query.TaskQuery.IFilterQuery; @@ -56,12 +57,12 @@ public class TaskSearchCriteria { private TaskQuery customTaskQuery; private boolean isOnlyShowOpenTask; - private TaskQuery finalTaskQuery; - private List searchScopeTaskFields; private boolean isGlobalSearch; private boolean isGlobalSearchScope; + private List legacyFilters; + @SuppressWarnings("deprecation") public TaskQuery createQueryToFindLatestTasks(TaskQuery taskQuery, Date timeStamp) { if (isAdminQuery) { @@ -74,16 +75,16 @@ public TaskQuery createQueryToFindLatestTasks(TaskQuery taskQuery, Date timeStam return taskQuery; } - @SuppressWarnings("deprecation") public TaskQuery createQuery() { TaskQuery finalQuery = TaskQuery.create(); setNewQueryCreated(isNewQueryCreated() || customTaskQuery == null || hasTaskId() || hasCaseId()); if (!isNewQueryCreated()) { - finalQuery = TaskQuery.fromJson(customTaskQuery.asJson()); // clone to keep the original custom query + finalQuery.where().and(customTaskQuery); } addTaskStateQuery(finalQuery); + addLegacyTaskFilterQuery(finalQuery); if (hasTaskId()) { finalQuery.where().and(queryForTaskId(getTaskId())); @@ -126,6 +127,22 @@ private void addTaskStateQuery(TaskQuery finalQuery) { } } + /** + * Append legacy filters of the old Task list + * + * @param finalQuery + */ + private void addLegacyTaskFilterQuery(TaskQuery finalQuery) { + if (CollectionUtils.isNotEmpty(legacyFilters)) { + for (TaskFilter filter : legacyFilters) { + TaskQuery subQuery = filter.buildQuery(); + if (subQuery != null) { + finalQuery.where().and(subQuery); + } + } + } + } + private void addKeywordQuery(TaskQuery finalQuery) { if (hasKeyword()) { finalQuery.where().and(queryForKeyword(getKeyword())); @@ -462,17 +479,6 @@ public void setNewQueryCreated(boolean isNewQueryCreated) { this.isNewQueryCreated = isNewQueryCreated; } - public TaskQuery getFinalTaskQuery() { - if (finalTaskQuery == null) { - finalTaskQuery = createQuery(); - } - return finalTaskQuery; - } - - public void setFinalTaskQuery(TaskQuery finalTaskQuery) { - this.finalTaskQuery = finalTaskQuery; - } - public boolean isGlobalSearch() { return isGlobalSearch; } @@ -509,4 +515,11 @@ public void setOnlyShowOpenTask(boolean isOnlyShowOpenTask) { this.isOnlyShowOpenTask = isOnlyShowOpenTask; } + public List getLegacyFilters() { + return legacyFilters; + } + + public void setLegacyFilters(List legacyFilters) { + this.legacyFilters = legacyFilters; + } } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/CaseService.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/CaseService.java index 1b73953ff2a..95062bb5cf4 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/CaseService.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/CaseService.java @@ -268,17 +268,15 @@ protected CaseQuery queryExcludeHiddenCases() { } private CaseQuery extendQuery(CaseSearchCriteria criteria) { - CaseQuery finalQuery = criteria.getFinalCaseQuery(); - CaseQuery clonedQuery = CaseQuery.fromJson(finalQuery.asJson()); // clone to keep the final query in CaseSearchCriteria + CaseQuery clonedQuery = criteria.createQuery(); if (!criteria.isAdminQuery()) { clonedQuery.where().and(queryForCurrentUser(criteria.isTechnicalCase())); - } - + } + if (isHiddenTasksCasesExcluded()) { clonedQuery.where().and(queryExcludeHiddenCases()); } - return clonedQuery; } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/TaskService.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/TaskService.java index 118525d4ef8..80f7f7b3a2e 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/TaskService.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/ivydata/service/impl/TaskService.java @@ -69,7 +69,8 @@ public IvyTaskResultDTO findGlobalSearchTasksByCriteria(TaskSearchCriteria crite return Sudo.get(() -> { IvyTaskResultDTO result = new IvyTaskResultDTO(); TaskQuery finalQuery = extendQueryWithUserHasPermissionToSee(criteria); - IPagedResult iTask = Ivy.wf().getTaskQueryExecutor().getResultsPaged(finalQuery); + IPagedResult iTask = Ivy.wf().getTaskQueryExecutor() + .getResultsPaged(finalQuery); result.setTasks(iTask.window(startIndex, count)); result.setTotalTasks(iTask.count()); return result; @@ -244,19 +245,20 @@ private ExpiryStatistic createExpiryTimeStampToCountMap(Recordset recordSet) thr return expiryStatistic; } - @SuppressWarnings("deprecation") - private TaskQuery extendQueryWithUserHasPermissionToSee(TaskSearchCriteria criteria) { - TaskQuery clonedQuery = TaskQuery.fromJson(criteria.getFinalTaskQuery().asJson()); // clone to keep the final query in TaskSearchCriteria + private TaskQuery extendQueryWithUserHasPermissionToSee( + TaskSearchCriteria criteria) { + TaskQuery cloneQuery = criteria.createQuery(); + if (!criteria.isAdminQuery()) { - clonedQuery.where().and(queryInvolvedTasks()); + cloneQuery.where().and(queryInvolvedTasks()); } if (isHiddenTasksCasesExcluded()) { - clonedQuery.where().and(queryExcludeHiddenTasks()); + cloneQuery.where().and(queryExcludeHiddenTasks()); } if (!PermissionUtils.hasSystemTaskReadAllPermission()) { - clonedQuery.where().and(queryExcludeSystemTasks()); + cloneQuery.where().and(queryExcludeSystemTasks()); } - return clonedQuery; + return cloneQuery; } protected TaskQuery queryInvolvedTasks() { @@ -264,10 +266,9 @@ protected TaskQuery queryInvolvedTasks() { return currentUserIsInvolved; } - @SuppressWarnings("deprecation") private TaskQuery extendQueryWithInvolvedUser(TaskSearchCriteria criteria) { - TaskQuery finalQuery = criteria.getFinalTaskQuery(); - TaskQuery clonedQuery = TaskQuery.fromJson(finalQuery.asJson()); // clone to keep the final query in TaskSearchCriteria + TaskQuery clonedQuery = criteria.createQuery(); + if (!criteria.isAdminQuery()) { clonedQuery.where().and(queryInvolvedTasks()); } @@ -281,7 +282,7 @@ private TaskQuery extendQueryWithInvolvedUser(TaskSearchCriteria criteria) { } private TaskQuery extendQueryWithUserCanWorkOn(TaskSearchCriteria criteria) { - TaskQuery finalQuery = criteria.getFinalTaskQuery(); + TaskQuery finalQuery = criteria.createQuery(); if (!criteria.isAdminQuery()) { finalQuery.where().and().currentUserCanWorkOn(); } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/service/DashboardWidgetInformationService.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/service/DashboardWidgetInformationService.java index 5e854758fdb..c7ac3f1696d 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/service/DashboardWidgetInformationService.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/service/DashboardWidgetInformationService.java @@ -123,7 +123,8 @@ public List buildStatisticOfTaskByCatego private TaskSearchCriteria generateTaskSearchCriteriaWithoutOrderByClause(DashboardTaskLazyDataModel dataModel) { var taskSearchCriteria = new TaskSearchCriteria(); - taskSearchCriteria.setFinalTaskQuery(dataModel.getCriteria().buildQueryWithoutOrderByClause()); + taskSearchCriteria.setCustomTaskQuery( + dataModel.getCriteria().buildQueryWithoutOrderByClause()); taskSearchCriteria.setAdminQuery(PermissionUtils.checkReadAllCasesPermission()); return taskSearchCriteria; } @@ -194,7 +195,8 @@ public List buildStatisticOfCaseByCatego private CaseSearchCriteria generateCaseSearchCriteriaWithoutOrderByClause(DashboardCaseLazyDataModel dataModel) { var caseSearchCriteria = new CaseSearchCriteria(); - caseSearchCriteria.setFinalCaseQuery(dataModel.getCriteria().buildQueryWithoutOrderByClause()); + caseSearchCriteria.setCustomCaseQuery( + dataModel.getCriteria().buildQueryWithoutOrderByClause()); caseSearchCriteria.setAdminQuery(PermissionUtils.checkReadAllCasesPermission()); return caseSearchCriteria; } diff --git a/AxonIvyPortal/portal/src_hd/ch/ivy/addon/portalkit/component/TaskWidget/TaskWidgetProcess.p.json b/AxonIvyPortal/portal/src_hd/ch/ivy/addon/portalkit/component/TaskWidget/TaskWidgetProcess.p.json index 85be2b7f5eb..b1a154ed803 100644 --- a/AxonIvyPortal/portal/src_hd/ch/ivy/addon/portalkit/component/TaskWidget/TaskWidgetProcess.p.json +++ b/AxonIvyPortal/portal/src_hd/ch/ivy/addon/portalkit/component/TaskWidget/TaskWidgetProcess.p.json @@ -341,9 +341,9 @@ "import org.apache.commons.beanutils.BeanUtils;", "import ch.ivyteam.ivy.workflow.query.TaskQuery;", "", - "TaskQuery query = in.taskSearchCriteria.finalTaskQuery;", + "TaskQuery query = in.taskSearchCriteria.createQuery();", "in.newTaskSearchCriteria = BeanUtils.cloneBean(in.taskSearchCriteria) as TaskSearchCriteria;", - "in.newTaskSearchCriteria.setFinalTaskQuery(in.newTaskSearchCriteria.createQueryToFindLatestTasks(query, in.latestTaskDate));", + "in.newTaskSearchCriteria.setCustomTaskQuery(in.newTaskSearchCriteria.createQueryToFindLatestTasks(query, in.latestTaskDate));", "", "in.latestTaskDate = new java.util.Date();" ]