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