View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.assignment.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
25  import org.kuali.hr.time.assignment.Assignment;
26  import org.kuali.hr.time.department.Department;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.util.TKContext;
29  import org.kuali.hr.time.util.TKUtils;
30  import org.kuali.rice.kns.lookup.HtmlData;
31  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32  import org.kuali.rice.krad.bo.BusinessObject;
33  import org.kuali.rice.krad.util.KRADConstants;
34  import org.kuali.rice.krad.util.UrlFactory;
35  
36  public class AssignmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37  
38  	private static final long serialVersionUID = 774015772672806415L;
39  
40  	@Override
41      public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
42      	List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
43  		
44  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);        
45          
46  		Assignment assignment = (Assignment) businessObject;
47          String tkAssignmentId = assignment.getTkAssignmentId();
48          Department dept = TkServiceLocator.getDepartmentService().getDepartment(assignment.getDept(), TKUtils.getCurrentDate());
49          String location = dept == null ? null : dept.getLocation();
50          String department = assignment.getDept();
51          
52          boolean systemAdmin = TKContext.getUser().isSystemAdmin();
53  		boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
54  		boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
55  		
56  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
57  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
58  				if (systemAdmin || locationAdmin || departmentAdmin) {
59  					customActionUrls.add(defaultCustomActionUrl);
60  				}
61  			} else {
62  				customActionUrls.add(defaultCustomActionUrl);
63  			}
64  		}
65  		
66  		Properties params = new Properties();
67  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
68  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
69  		params.put("tkAssignmentId", tkAssignmentId);
70  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
71  		viewUrl.setDisplayText("view");
72  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
73  		customActionUrls.add(viewUrl);
74  		
75  		return customActionUrls;
76      }
77  
78      @SuppressWarnings({"unchecked"})
79      @Override
80      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
81          String fromEffdt = fieldValues.get("rangeLowerBoundKeyPrefix_effectiveDate");
82          String toEffdt = StringUtils.isNotBlank(fieldValues.get("effectiveDate")) ? fieldValues.get("effectiveDate").replace("<=", "") : "";
83          String principalId = fieldValues.get("principalId");
84          String jobNumber = fieldValues.get("jobNumber");
85          String dept = fieldValues.get("dept");
86          String workArea = fieldValues.get("workArea");
87          String active = fieldValues.get("active");
88          String showHist = fieldValues.get("history");
89  
90          List<Assignment> assignments = TkServiceLocator.getAssignmentService().searchAssignments(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), principalId,
91                  jobNumber, dept, workArea, active, showHist);
92  
93  //		String deptName = "";
94  //		if(fieldValues.containsKey("dept") && !fieldValues.get("dept").isEmpty()) {
95  //			deptName = fieldValues.get("dept");
96  //			fieldValues.remove("dept");
97  //		}
98  //		List aList = super.getSearchResults(fieldValues);
99  //		if(deptName.isEmpty()) {
100 //			return aList;
101 //		}
102 //		List finalList = new ArrayList<Assignment>();
103 //		for(int i = 0; i< aList.size(); i++) {
104 //			Assignment anAssign = (Assignment) aList.get(i);
105 //			if(anAssign.getPrincipalId() != null && anAssign.getEffectiveDate() != null) {
106 //				List<Job> jobList = TkServiceLocator.getJobService().getJobs(anAssign.getPrincipalId(), anAssign.getEffectiveDate());
107 //				for(Job aJob : jobList) {
108 //					if(!aJob.getJobNumber().equals(anAssign.getJobNumber())){
109 //						continue;
110 //					}
111 //					if( aJob.getDept().equals(deptName)) {
112 //						finalList.add(anAssign);
113 //						break;
114 //					}
115 //				}
116 //			}
117 //		}
118         return assignments;
119     }
120 
121 
122 }