1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.timecollection.service;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.joda.time.LocalDate;
25 import org.kuali.kpme.core.KPMENamespace;
26 import org.kuali.kpme.core.department.Department;
27 import org.kuali.kpme.core.permission.KPMEPermissionTemplate;
28 import org.kuali.kpme.core.role.KPMERoleMemberAttribute;
29 import org.kuali.kpme.core.service.HrServiceLocator;
30 import org.kuali.kpme.tklm.time.rules.timecollection.TimeCollectionRule;
31 import org.kuali.kpme.tklm.time.rules.timecollection.dao.TimeCollectionRuleDaoService;
32 import org.kuali.rice.kim.api.KimConstants;
33 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
35
36 public class TimeCollectionRuleServiceImpl implements TimeCollectionRuleService {
37 private TimeCollectionRuleDaoService timeCollectRuleDao;
38
39 @Override
40 public TimeCollectionRule getTimeCollectionRule(String dept, Long workArea, String payType, LocalDate asOfDate){
41 return timeCollectRuleDao.getTimeCollectionRule(dept, workArea, payType, asOfDate);
42 }
43
44 public TimeCollectionRuleDaoService getTimeCollectRuleDao() {
45 return timeCollectRuleDao;
46 }
47
48 public void setTimeCollectRuleDao(
49 TimeCollectionRuleDaoService timeCollectRuleDao) {
50 this.timeCollectRuleDao = timeCollectRuleDao;
51 }
52
53 @Override
54 public TimeCollectionRule getTimeCollectionRule(String tkTimeCollectionRuleId) {
55 return timeCollectRuleDao.getTimeCollectionRule(tkTimeCollectionRuleId);
56 }
57
58 @Override
59 public List<TimeCollectionRule> getTimeCollectionRules(String userPrincipalId, String dept, String workArea, String payType, String active, String showHistory) {
60 List<TimeCollectionRule> results = new ArrayList<TimeCollectionRule>();
61
62 Long workAreaToSearch = StringUtils.isEmpty(workArea) ? null : Long.parseLong(workArea);
63
64 List<TimeCollectionRule> timeCollectionRuleObjs = timeCollectRuleDao.getTimeCollectionRules(dept, workAreaToSearch , payType, active, showHistory);
65
66
67 for (TimeCollectionRule timeCollectionRuleObj : timeCollectionRuleObjs) {
68 String department = timeCollectionRuleObj.getDept();
69 Department departmentObj = HrServiceLocator.getDepartmentService().getDepartmentWithoutRoles(department, timeCollectionRuleObj.getEffectiveLocalDate());
70 String location = departmentObj != null ? departmentObj.getLocation() : null;
71 Map<String, String> permissionDetails = new HashMap<String, String>();
72 permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, KRADServiceLocatorWeb.getDocumentDictionaryService().getMaintenanceDocumentTypeName(TimeCollectionRule.class));
73 Map<String, String> roleQualification = new HashMap<String, String>();
74 roleQualification.put(KimConstants.AttributeConstants.PRINCIPAL_ID, userPrincipalId);
75 roleQualification.put(KPMERoleMemberAttribute.DEPARTMENT.getRoleMemberAttributeName(), department);
76 roleQualification.put(KPMERoleMemberAttribute.LOCATION.getRoleMemberAttributeName(), location);
77
78 if (!KimApiServiceLocator.getPermissionService().isPermissionDefinedByTemplate(KPMENamespace.KPME_WKFLW.getNamespaceCode(),
79 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), permissionDetails)
80 || KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(userPrincipalId, KPMENamespace.KPME_WKFLW.getNamespaceCode(),
81 KPMEPermissionTemplate.VIEW_KPME_RECORD.getPermissionTemplateName(), permissionDetails, roleQualification)) {
82 results.add(timeCollectionRuleObj);
83 }
84 }
85
86 return results;
87 }
88 }