001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.task.service;
017
018 import java.util.List;
019 import java.util.Map;
020
021 import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
022 import org.kuali.hr.time.service.base.TkServiceLocator;
023 import org.kuali.hr.time.util.TKUtils;
024 import org.kuali.rice.kns.document.authorization.BusinessObjectRestrictions;
025 import org.kuali.rice.kns.lookup.HtmlData;
026 import org.kuali.rice.kns.web.struts.form.LookupForm;
027 import org.kuali.rice.kns.web.ui.Field;
028 import org.kuali.rice.kns.web.ui.Row;
029 import org.kuali.rice.krad.bo.BusinessObject;
030
031 public class TaskLookupableHelper extends TkAuthorizedLookupableHelperBase {
032
033 private static final long serialVersionUID = 7525044777337159013L;
034
035 @Override
036 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
037 String task = fieldValues.get("task");
038 String description = fieldValues.get("description");
039 String workArea = fieldValues.get("workArea");
040 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
041 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
042
043 return TkServiceLocator.getTaskService().getTasks(task, description, workArea, TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt));
044 }
045
046 @SuppressWarnings("rawtypes")
047 @Override
048 public HtmlData getReturnUrl(BusinessObject businessObject,
049 LookupForm lookupForm, List returnKeys,
050 BusinessObjectRestrictions businessObjectRestrictions) {
051 if (lookupForm.getFieldConversions().containsKey("effectiveDate")) {
052 lookupForm.getFieldConversions().remove("effectiveDate");
053 }
054 if (returnKeys.contains("effectiveDate")) {
055 returnKeys.remove("effectiveDate");
056 }
057 if (lookupForm.getFieldConversions().containsKey("workArea")) {
058 lookupForm.getFieldConversions().remove("workArea");
059 }
060 if (returnKeys.contains("workArea")) {
061 returnKeys.remove("workArea");
062 }
063
064 return super.getReturnUrl(businessObject, lookupForm, returnKeys,
065 businessObjectRestrictions);
066 }
067
068 @Override
069 // remove the default value for Task for lookup
070 public List<Row> getRows() {
071 List<Row> rowList = super.getRows();
072 for (Row aRow : rowList) {
073 List<Field> fields = aRow.getFields();
074 for (Field aField : fields) {
075 if (aField.getFieldLabel() != null && aField.getFieldLabel().equals("Task")) {
076 if (aField.getPropertyValue() != null && aField.getPropertyValue().equals("0")) {
077 aField.setPropertyValue("");
078 }
079 }
080 }
081 }
082 return rowList;
083 }
084
085 @Override
086 public boolean shouldShowBusinessObject(BusinessObject bo) {
087 return true;
088 }
089 }