1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.assignment.service;
17
18 import java.util.Collection;
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.hr.job.Job;
24 import org.kuali.hr.time.HrBusinessObject;
25 import org.kuali.hr.time.assignment.Assignment;
26 import org.kuali.hr.time.assignment.AssignmentAccount;
27 import org.kuali.hr.time.paytype.PayType;
28 import org.kuali.hr.time.service.base.TkServiceLocator;
29 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
30 import org.kuali.kfs.coa.businessobject.Account;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33 import org.kuali.rice.kns.document.MaintenanceDocument;
34 import org.kuali.rice.kns.service.KNSServiceLocator;
35 import org.kuali.rice.krad.bo.PersistableBusinessObject;
36 import org.kuali.rice.krad.service.KRADServiceLocator;
37
38
39
40
41
42
43 public class AssignmentMaintainableServiceImpl extends HrBusinessObjectMaintainableImpl {
44
45
46
47
48 private static final long serialVersionUID = 1L;
49
50 @Override
51 public Map populateBusinessObject(Map<String, String> fieldValues,
52 MaintenanceDocument maintenanceDocument, String methodToCall) {
53 if (fieldValues.containsKey("principalId")
54 && StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
55 Person p = KimApiServiceLocator.getPersonService().getPerson(
56 fieldValues.get("principalId"));
57 if (p != null) {
58 fieldValues.put("name", p.getName());
59 } else {
60 fieldValues.put("name", "");
61 }
62 }
63
64
65
66
67
68
69
70 return super.populateBusinessObject(fieldValues, maintenanceDocument,
71 methodToCall);
72 }
73
74 @Override
75 public Map<String, String> populateNewCollectionLines(
76 Map<String, String> fieldValues,
77 MaintenanceDocument maintenanceDocument, String methodToCall) {
78 if (fieldValues.containsKey("assignmentAccounts.accountNbr")
79 && StringUtils.isNotEmpty(fieldValues
80 .get("assignmentAccounts.accountNbr"))) {
81 Map<String, String> fields = new HashMap<String, String>();
82 fields.put("accountNumber", fieldValues
83 .get("assignmentAccounts.accountNbr"));
84 Collection account = KRADServiceLocator.getBusinessObjectService()
85 .findMatching(Account.class, fields);
86 if (account.size() > 0) {
87 Account acc = (Account) account.iterator().next();
88 fieldValues.put("assignmentAccounts.finCoaCd", acc
89 .getChartOfAccountsCode());
90 }
91 }
92 if ( !fieldValues.containsKey("assignmentAccounts.earnCode")
93 || StringUtils.isEmpty(fieldValues.get("assignmentAccounts.earnCode"))) {
94 Assignment assignment = (Assignment) maintenanceDocument.getDocumentBusinessObject();
95 if(assignment != null
96 && assignment.getPrincipalId() != null
97 && assignment.getJobNumber() != null
98 && assignment.getEffectiveDate() != null) {
99 Job job = TkServiceLocator.getJobService().getJob(assignment.getPrincipalId(), assignment.getJobNumber(), assignment.getEffectiveDate(), false);
100 if(job != null) {
101 PayType payType = TkServiceLocator.getPayTypeService().getPayType(job.getHrPayType(), assignment.getEffectiveDate());
102 fieldValues.put("assignmentAccounts.earnCode", (payType != null) ? payType.getRegEarnCode() : "");
103 }
104 }
105 }
106
107 return super.populateNewCollectionLines(fieldValues,
108 maintenanceDocument, methodToCall);
109 }
110
111 @Override
112 public void processAfterEdit(MaintenanceDocument document,
113 Map<String, String[]> parameters) {
114 Assignment aOld = (Assignment) document.getOldMaintainableObject()
115 .getBusinessObject();
116 Assignment aNew = (Assignment) document.getNewMaintainableObject()
117 .getBusinessObject();
118 super.processAfterEdit(document, parameters);
119 }
120
121
122 @Override
123 protected void setNewCollectionLineDefaultValues(String arg0,
124 PersistableBusinessObject arg1) {
125 if(arg1 instanceof AssignmentAccount){
126 AssignmentAccount assignmentAccount = (AssignmentAccount)arg1;
127 Assignment assignment = (Assignment) this.getBusinessObject();
128 assignmentAccount.setActive(assignment.isActive());
129 }
130 super.setNewCollectionLineDefaultValues(arg0, arg1);
131 }
132
133 @Override
134 public HrBusinessObject getObjectById(String id) {
135 return TkServiceLocator.getAssignmentService().getAssignment(id);
136 }
137
138 @Override
139 public void customSaveLogic(HrBusinessObject hrObj) {
140 Assignment assignment = (Assignment)hrObj;
141 for (AssignmentAccount assignAcct : assignment.getAssignmentAccounts()) {
142 if(!isOldBusinessObjectInDocument()){
143 assignAcct.setTkAssignAcctId(null);
144 }
145 assignAcct.setTkAssignmentId(assignment.getTkAssignmentId());
146 }
147 }
148
149 }