1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.businessobject.ContractManagerAssignmentDetail;
22 import org.kuali.ole.module.purap.document.ContractManagerAssignmentDocument;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.vnd.businessobject.ContractManager;
25 import org.kuali.rice.kns.rules.TransactionalDocumentRuleBase;
26 import org.kuali.rice.krad.document.Document;
27 import org.kuali.rice.krad.rules.rule.event.ApproveDocumentEvent;
28 import org.kuali.rice.krad.service.BusinessObjectService;
29 import org.kuali.rice.krad.util.GlobalVariables;
30 import org.kuali.rice.krad.util.KRADPropertyConstants;
31 import org.kuali.rice.krad.util.ObjectUtils;
32
33 import java.util.HashMap;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41 public class ContractManagerAssignmentDocumentRule extends TransactionalDocumentRuleBase {
42 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ContractManagerAssignmentDocumentRule.class);
43
44
45
46
47 @Override
48 protected boolean processCustomRouteDocumentBusinessRules(Document document) {
49 boolean isValid = true;
50 ContractManagerAssignmentDocument acmDocument = (ContractManagerAssignmentDocument) document;
51 return isValid &= processValidation(acmDocument);
52 }
53
54
55
56
57 @Override
58 protected boolean processCustomApproveDocumentBusinessRules(ApproveDocumentEvent approveEvent) {
59 boolean isValid = true;
60 ContractManagerAssignmentDocument acmDocument = (ContractManagerAssignmentDocument) approveEvent.getDocument();
61
62 return isValid;
63 }
64
65
66
67
68
69
70
71 protected boolean processValidation(ContractManagerAssignmentDocument document) {
72 return validateContractManagerCodes(document.getContractManagerAssignmentDetails());
73 }
74
75
76
77
78
79
80
81
82
83
84 public boolean validateContractManagerCodes(List contractManagerAssignmentDetails) {
85 LOG.debug("validateContractManagerCodes(): entered method.");
86 boolean isValid = true;
87 int count = 0;
88
89 for (Iterator iter = contractManagerAssignmentDetails.iterator(); iter.hasNext(); ) {
90 ContractManagerAssignmentDetail detail = (ContractManagerAssignmentDetail) iter.next();
91
92
93 if (ObjectUtils.isNotNull(detail.getContractManagerCode())) {
94 Map fieldValues = new HashMap();
95 fieldValues.put(PurapPropertyConstants.CONTRACT_MANAGER_CODE, detail.getContractManagerCode());
96 fieldValues.put(KRADPropertyConstants.ACTIVE, true);
97 if (SpringContext.getBean(BusinessObjectService.class).countMatching(ContractManager.class, fieldValues) != 1) {
98 GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_CONTRACT_MANAGER_TAB_ERRORS, PurapKeyConstants.INVALID_CONTRACT_MANAGER_CODE, detail.getContractManagerCode().toString());
99 isValid = false;
100 } else {
101 count++;
102 }
103 if (detail.getContractManagerCode().equals(PurapConstants.APO_CONTRACT_MANAGER)) {
104 GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_CONTRACT_MANAGER_TAB_ERRORS, PurapKeyConstants.ERROR_APO_CONTRACT_MANAGER_CODE_CHOSEN, detail.getContractManagerCode().toString());
105 isValid = false;
106 }
107 }
108 }
109
110
111 if (count < 1) {
112 GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_CONTRACT_MANAGER_TAB_ERRORS, PurapKeyConstants.NO_CONTRACT_MANAGER_ASSIGNED);
113 isValid = false;
114 }
115
116 LOG.debug("validateContractManagerCodes(): leaving method.");
117 return isValid;
118 }
119 }