1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.assignment.web;
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.kpme.core.assignment.Assignment;
24 import org.kuali.kpme.core.assignment.account.AssignmentAccount;
25 import org.kuali.kpme.core.bo.HrBusinessObject;
26 import org.kuali.kpme.core.bo.HrBusinessObjectMaintainableImpl;
27 import org.kuali.kpme.core.job.Job;
28 import org.kuali.kpme.core.kfs.coa.businessobject.Account;
29 import org.kuali.kpme.core.paytype.PayType;
30 import org.kuali.kpme.core.service.HrServiceLocator;
31 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33 import org.kuali.rice.kns.document.MaintenanceDocument;
34 import org.kuali.rice.krad.bo.PersistableBusinessObject;
35 import org.kuali.rice.krad.service.KRADServiceLocator;
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 = HrServiceLocator.getJobService().getJob(assignment.getPrincipalId(), assignment.getJobNumber(), assignment.getEffectiveLocalDate(), false);
98 if(job != null) {
99 PayType payType = HrServiceLocator.getPayTypeService().getPayType(job.getHrPayType(), assignment.getEffectiveLocalDate());
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 HrServiceLocator.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 }