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 org.apache.commons.lang.StringUtils;
19 import org.kuali.kpme.core.assignment.AssignmentBo;
20 import org.kuali.kpme.core.assignment.AssignmentBo;
21 import org.kuali.kpme.core.assignment.account.AssignmentAccountBo;
22 import org.kuali.kpme.core.bo.HrBusinessObject;
23 import org.kuali.kpme.core.bo.HrDataObjectMaintainableImpl;
24 import org.kuali.kpme.core.service.HrServiceLocator;
25 import org.kuali.kpme.core.util.ValidationUtils;
26 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
27 import org.kuali.rice.krad.uif.container.CollectionGroup;
28 import org.kuali.rice.krad.uif.view.View;
29 import org.kuali.rice.krad.uif.view.ViewModel;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
32
33 import java.util.ArrayList;
34
35
36
37
38
39
40 public class AssignmentMaintainableServiceImpl extends HrDataObjectMaintainableImpl {
41
42
43
44
45 private static final long serialVersionUID = 1L;
46
47 @Override
48 public HrBusinessObject getObjectById(String id) {
49 return AssignmentBo.from(HrServiceLocator.getAssignmentService().getAssignment(id));
50 }
51
52 @Override
53 public void customSaveLogic(HrBusinessObject hrObj) {
54 AssignmentBo assignment = (AssignmentBo)hrObj;
55 for (AssignmentAccountBo assignAcct : assignment.getAssignmentAccounts()) {
56 if(!isOldDataObjectInDocument()){
57 assignAcct.setTkAssignAcctId(null);
58 }
59 assignAcct.setTkAssignmentId(assignment.getTkAssignmentId());
60
61 }
62 }
63
64
65 @Override
66 public void prepareForSave() {
67 AssignmentBo assignment = (AssignmentBo)this.getDataObject();
68 for (AssignmentAccountBo assignAcct : assignment.getAssignmentAccounts()) {
69 assignAcct.setUserPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
70 }
71 super.prepareForSave();
72 }
73
74 @Override
75 public void customInactiveSaveLogicNewEffective(HrBusinessObject oldHrObj) {
76 AssignmentBo bo = (AssignmentBo)oldHrObj;
77 bo.setAssignmentAccounts(new ArrayList<AssignmentAccountBo>());
78 }
79
80 @Override
81 protected boolean performAddLineValidation(ViewModel viewModel, Object newLine, String collectionId, String collectionPath) {
82 boolean isValid = super.performAddLineValidation(viewModel, newLine, collectionId, collectionPath);
83 if (viewModel instanceof MaintenanceDocumentForm) {
84 MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) viewModel;
85 MaintenanceDocument document = maintenanceForm.getDocument();
86 if (document.getNewMaintainableObject().getDataObject() instanceof AssignmentBo) {
87 AssignmentBo assignment = (AssignmentBo) document.getNewMaintainableObject().getDataObject();
88
89 if (newLine instanceof AssignmentAccountBo) {
90 AssignmentAccountBo assignmentAccount = (AssignmentAccountBo) newLine;
91 boolean results = this.validateAssignmentAccount(assignmentAccount, assignment);
92 if(!results) {
93 return false;
94 }
95 }
96 }
97 }
98 return isValid;
99 }
100
101 private boolean validateAssignmentAccount(AssignmentAccountBo assignmentAccount, AssignmentBo assignmentObj) {
102 boolean valid = false;
103
104 if(StringUtils.isNotEmpty(assignmentAccount.getEarnCode())) {
105 valid = ValidationUtils.validateEarnCode(assignmentAccount.getEarnCode(), assignmentObj.getEffectiveLocalDate());
106 if(!valid) {
107 GlobalVariables.getMessageMap().putError("newCollectionLines['document.newMaintainableObject.dataObject.assignmentAccounts'].earnCode","error.existence", "earn code '"+ assignmentAccount.getEarnCode() + "'");
108 return valid;
109 }
110 }
111 if(StringUtils.isNotEmpty(assignmentAccount.getAccountNbr())) {
112 valid = ValidationUtils.validateAccount(assignmentAccount.getFinCoaCd(),assignmentAccount.getAccountNbr());
113 if(!valid) {
114 GlobalVariables.getMessageMap().putError("newCollectionLines['document.newMaintainableObject.dataObject.assignmentAccounts'].accountNbr","error.existence", "Account Number '"+ assignmentAccount.getAccountNbr() + "'");
115 return valid;
116 }
117 }
118 if(StringUtils.isNotEmpty(assignmentAccount.getFinObjectCd())) {
119 valid = ValidationUtils.validateObjectCode(assignmentAccount.getFinObjectCd(),assignmentAccount.getFinCoaCd(),null);
120 if (!valid) {
121 GlobalVariables.getMessageMap().putError("newCollectionLines['document.newMaintainableObject.dataObject.assignmentAccounts'].finObjectCd","error.existence", "Object Code '"+ assignmentAccount.getFinObjectCd() + "'");
122 return valid;
123 }
124 }
125 if (StringUtils.isNotEmpty(assignmentAccount.getFinSubObjCd())) {
126 valid = ValidationUtils.validateSubObjectCode(String.valueOf(assignmentObj.getEffectiveLocalDate().getYear()),assignmentAccount.getFinCoaCd(),
127 assignmentAccount.getAccountNbr(), assignmentAccount.getFinObjectCd(), assignmentAccount.getFinSubObjCd());
128 if (!valid) {
129 GlobalVariables.getMessageMap().putError("newCollectionLines['document.newMaintainableObject.dataObject.assignmentAccounts'].finSubObjCd","error.existence", "SubObject Code '"+ assignmentAccount.getFinSubObjCd() + "'");
130 return valid;
131 }
132 }
133 if(assignmentAccount.getSubAcctNbr() != null && StringUtils.isNotEmpty(assignmentAccount.getSubAcctNbr())) {
134 valid = ValidationUtils.validateSubAccount(assignmentAccount.getSubAcctNbr(),assignmentAccount.getAccountNbr(), assignmentAccount.getFinCoaCd());
135 if (!valid) {
136 GlobalVariables.getMessageMap().putError("newCollectionLines['document.newMaintainableObject.dataObject.assignmentAccounts'].subAcctNbr", "error.existence", "Sub-Account Number '"+ assignmentAccount.getSubAcctNbr() + "'");
137 return valid;
138 }
139 }
140
141 return valid;
142 }
143
144 }