001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.purap.rules;
017:
018: import java.util.HashMap;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.document.Document;
024: import org.kuali.core.rule.event.ApproveDocumentEvent;
025: import org.kuali.core.rules.TransactionalDocumentRuleBase;
026: import org.kuali.core.service.BusinessObjectService;
027: import org.kuali.core.util.GlobalVariables;
028: import org.kuali.core.util.ObjectUtils;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.module.purap.PurapConstants;
031: import org.kuali.module.purap.PurapKeyConstants;
032: import org.kuali.module.purap.PurapPropertyConstants;
033: import org.kuali.module.purap.bo.AssignContractManagerDetail;
034: import org.kuali.module.purap.document.AssignContractManagerDocument;
035: import org.kuali.module.vendor.bo.ContractManager;
036:
037: /**
038: * Business rule(s) applicable to Contract Manager Assignment document.
039: */
040: public class AssignContractManagerDocumentRule extends
041: TransactionalDocumentRuleBase {
042: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
043: .getLogger(AssignContractManagerDocumentRule.class);
044:
045: /**
046: * @see org.kuali.core.rules.TransactionalDocumentRuleBase#processCustomRouteDocumentBusinessRules(Document)
047: */
048: @Override
049: protected boolean processCustomRouteDocumentBusinessRules(
050: Document document) {
051: boolean isValid = true;
052: AssignContractManagerDocument acmDocument = (AssignContractManagerDocument) document;
053: return isValid &= processValidation(acmDocument);
054: }
055:
056: /**
057: * @see org.kuali.core.rules.DocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.rule.event.ApproveDocumentEvent)
058: */
059: @Override
060: protected boolean processCustomApproveDocumentBusinessRules(
061: ApproveDocumentEvent approveEvent) {
062: boolean isValid = true;
063: AssignContractManagerDocument acmDocument = (AssignContractManagerDocument) approveEvent
064: .getDocument();
065: // isValid &= processValidation(acmDocument);
066: return isValid;
067: }
068:
069: /**
070: * Perform validation for Contract Manager Assignment document such as validating contract manager codes.
071: *
072: * @param document Contract Manager Assignment document
073: * @return Boolean indicating if validation succeeded
074: */
075: private boolean processValidation(
076: AssignContractManagerDocument document) {
077: return validateContractManagerCodes(document
078: .getAssignContractManagerDetails());
079: }
080:
081: /**
082: * Review the list of AssignContractManagerDetails where the user has entered ContractManagerCodes and validates that each code
083: * is valid.
084: *
085: * @param assignContractManagerDetails A list containing the code to be validated.
086: * @return Boolean indicating if validation succeeded
087: */
088: public boolean validateContractManagerCodes(
089: List assignContractManagerDetails) {
090: LOG.debug("validateContractManagerCodes(): entered method.");
091: boolean isValid = true;
092: for (Iterator iter = assignContractManagerDetails.iterator(); iter
093: .hasNext();) {
094: AssignContractManagerDetail detail = (AssignContractManagerDetail) iter
095: .next();
096:
097: // Look for the contractManagerCode in the table. If not there the code is invalid.
098: if (ObjectUtils.isNotNull(detail.getContractManagerCode())) {
099: Map fieldValues = new HashMap();
100: fieldValues.put(
101: PurapPropertyConstants.CONTRACT_MANAGER_CODE,
102: detail.getContractManagerCode());
103: if (SpringContext.getBean(BusinessObjectService.class)
104: .countMatching(ContractManager.class,
105: fieldValues) != 1) {
106: GlobalVariables
107: .getErrorMap()
108: .putError(
109: PurapConstants.ASSIGN_CONTRACT_MANAGER_TAB_ERRORS,
110: PurapKeyConstants.INVALID_CONTRACT_MANAGER_CODE,
111: detail.getContractManagerCode()
112: .toString());
113: isValid = false;
114: }
115: }
116: }
117: LOG.debug("validateContractManagerCodes(): leaving method.");
118: return isValid;
119: }
120: }
|