001
014
015 package com.liferay.portlet.workflowtasks.search;
016
017 import com.liferay.portal.kernel.dao.search.SearchContainer;
018 import com.liferay.portal.kernel.util.OrderByComparator;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.kernel.workflow.WorkflowTask;
021 import com.liferay.portal.kernel.workflow.comparator.WorkflowComparatorFactoryUtil;
022
023 import java.util.ArrayList;
024 import java.util.HashMap;
025 import java.util.List;
026 import java.util.Map;
027
028 import javax.portlet.PortletRequest;
029 import javax.portlet.PortletURL;
030
031
034 public class WorkflowTaskSearch extends SearchContainer<WorkflowTask> {
035
036 static List<String> headerNames = new ArrayList<String>();
037 static Map<String, String> orderableHeaders = new HashMap<String, String>();
038
039 static {
040 headerNames.add("task");
041 headerNames.add("asset-title");
042 headerNames.add("last-activity-date");
043 headerNames.add("due-date");
044 headerNames.add("state");
045
046 orderableHeaders.put("task", "task");
047 orderableHeaders.put("due-date", "due-date");
048 }
049
050 public WorkflowTaskSearch(
051 PortletRequest portletRequest, PortletURL iteratorURL) {
052
053 this(portletRequest, DEFAULT_CUR_PARAM, iteratorURL);
054 }
055
056 public WorkflowTaskSearch(
057 PortletRequest portletRequest, String curParam,
058 PortletURL iteratorURL) {
059
060 super(
061 portletRequest, new WorkflowTaskDisplayTerms(portletRequest),
062 new WorkflowTaskSearchTerms(portletRequest), curParam,
063 DEFAULT_DELTA, iteratorURL, headerNames, null);
064
065 WorkflowTaskDisplayTerms displayTerms =
066 (WorkflowTaskDisplayTerms)getDisplayTerms();
067
068 iteratorURL.setParameter(
069 WorkflowTaskDisplayTerms.NAME, displayTerms.getName());
070 iteratorURL.setParameter(
071 WorkflowTaskDisplayTerms.TYPE, displayTerms.getType());
072
073 String orderByCol = ParamUtil.getString(portletRequest, "orderByCol");
074 String orderByType = ParamUtil.getString(portletRequest, "orderByType");
075
076 OrderByComparator orderByComparator = getOrderByComparator(
077 orderByCol, orderByType);
078
079 setOrderableHeaders(orderableHeaders);
080 setOrderByCol(orderByCol);
081 setOrderByType(orderByType);
082 setOrderByComparator(orderByComparator);
083 }
084
085 protected OrderByComparator getOrderByComparator(
086 String orderByCol, String orderByType) {
087
088 boolean orderByAsc = false;
089
090 if (orderByType.equals("asc")) {
091 orderByAsc = true;
092 }
093
094 OrderByComparator orderByComparator = null;
095
096 if (orderByCol.equals("name")) {
097 orderByComparator =
098 WorkflowComparatorFactoryUtil.getTaskNameComparator(orderByAsc);
099 }
100 else {
101 orderByComparator =
102 WorkflowComparatorFactoryUtil.getTaskDueDateComparator(
103 orderByAsc);
104 }
105
106 return orderByComparator;
107 }
108
109 }