Skip to content

Commit

Permalink
Merge pull request #1418 from axonivy-market/feature/IVYPORTAL-17694-…
Browse files Browse the repository at this point in the history
…remove-usages-of-deprecated-methods-query-fromJson-and-query-asJson-12

Feature/ivyportal 17694 remove usages of deprecated methods query from json and query as json 12
  • Loading branch information
mnhnam-axonivy authored Jan 10, 2025
2 parents 135969a + e4382cf commit 65f595d
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ private void buildQueryToSearchCriteria() {
.isEqual(businessEntityId);
criteria.setCustomCaseQuery(caseQuery);
}

criteria.setFinalCaseQuery(criteria.createQuery());
}

public String getBusinessEntityId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ICase> {
public static final String DESCRIPTION = "DESCRIPTION";
Expand Down Expand Up @@ -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);

/**
* <p>
* If your customized case list has new columns/fields, please extend the {@code caseQuery} parameter with the sort
* query for these fields.
* </p>
* <p>
* <b>Example: </b> <code><pre>
* if ("CustomerName".equalsIgnoreCase(criteria.getSortField())) {
* if (criteria.isSortDescending()) {
* caseQuery.orderBy().customField().stringField("CustomerName").descending();
* } else {
* caseQuery.orderBy().customField().stringField("CustomerName");
* }
* }
* </pre></code>
* </p>
*
* @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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITask> {
public static final String DESCRIPTION = "DESCRIPTION";
Expand Down Expand Up @@ -323,29 +322,6 @@ private boolean isSortedDescendingByDefault() {
return !SortFieldUtil.isAscendingSort(SortDirection.DESC.name());
}

/**
* <p>
* If your customized task list has new columns/fields, please extend the {@code taskQuery}
* parameter with the sort query for these fields.
* </p>
* <p>
* <b>Example: </b> <code><pre>
* if ("CustomerType".equalsIgnoreCase(criteria.getSortField())) {
* if (criteria.isSortDescending()) {
* taskQuery.orderBy().customField().stringField("CustomerType").descending();
* } else {
* taskQuery.orderBy().customField().stringField("CustomerType");
* }
* }
* </pre></code>
* </p>
*
* @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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private UIComponent findRelatedCaseComponent() {

private void initializedDataModel() {
data.clear();
criteria.setFinalCaseQuery(null);
}

private int getCaseCount(CaseSearchCriteria criteria) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ protected int getTaskCount(TaskSearchCriteria criteria) {

private void initializedDataModel() {
data.clear();
criteria.setFinalTaskQuery(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SearchScopeCaseField> searchScopeCaseFields;

private List<CaseFilter> legacyFilters;

public CaseQuery createQuery() {
CaseQuery finalQuery;
Expand All @@ -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()) {
Expand All @@ -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();
Expand All @@ -98,6 +101,17 @@ private CaseQuery queryForStates(List<CaseState> 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();
Expand Down Expand Up @@ -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<SearchScopeCaseField> getSearchScopeCaseFields() {
return searchScopeCaseFields;
}
Expand All @@ -409,4 +412,12 @@ public void setGlobalSearchScope(boolean isGlobalSearchScope) {
this.isGlobalSearchScope = isGlobalSearchScope;
}

public List<CaseFilter> getLegacyFilters() {
return legacyFilters;
}

public void setLegacyFilters(List<CaseFilter> legacyFilters) {
this.legacyFilters = legacyFilters;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ public class TaskCategorySearchCriteria {
private List<TaskState> 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()) {
Expand Down
Loading

0 comments on commit 65f595d

Please sign in to comment.