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 super(
054 portletRequest, new WorkflowTaskDisplayTerms(portletRequest),
055 new WorkflowTaskSearchTerms(portletRequest), DEFAULT_CUR_PARAM,
056 DEFAULT_DELTA, iteratorURL, headerNames, null);
057
058 WorkflowTaskDisplayTerms displayTerms =
059 (WorkflowTaskDisplayTerms)getDisplayTerms();
060
061 iteratorURL.setParameter(
062 WorkflowTaskDisplayTerms.NAME, displayTerms.getName());
063 iteratorURL.setParameter(
064 WorkflowTaskDisplayTerms.TYPE, displayTerms.getType());
065
066 String orderByCol = ParamUtil.getString(
067 portletRequest, "orderByCol");
068 String orderByType = ParamUtil.getString(
069 portletRequest, "orderByType");
070
071 OrderByComparator orderByComparator = getOrderByComparator(
072 orderByCol, orderByType);
073
074 setOrderableHeaders(orderableHeaders);
075 setOrderByCol(orderByCol);
076 setOrderByType(orderByType);
077 setOrderByComparator(orderByComparator);
078 }
079
080 protected OrderByComparator getOrderByComparator(
081 String orderByCol, String orderByType) {
082
083 boolean orderByAsc = false;
084
085 if (orderByType.equals("asc")) {
086 orderByAsc = true;
087 }
088
089 OrderByComparator orderByComparator = null;
090
091 if (orderByCol.equals("due-date")) {
092 orderByComparator =
093 WorkflowComparatorFactoryUtil.getTaskDueDateComparator(
094 orderByAsc);
095 }
096 else if (orderByCol.equals("name")){
097 orderByComparator =
098 WorkflowComparatorFactoryUtil.getTaskNameComparator(orderByAsc);
099 }
100
101 return orderByComparator;
102 }
103
104 }