001: /*
002: * Copyright 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.cg.rules;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.apache.log4j.Logger;
020: import org.kuali.core.bo.PersistableBusinessObject;
021: import org.kuali.core.document.MaintenanceDocument;
022: import org.kuali.core.util.GlobalVariables;
023: import org.kuali.kfs.KFSKeyConstants;
024: import org.kuali.kfs.KFSPropertyConstants;
025: import org.kuali.module.cg.bo.Proposal;
026: import org.kuali.module.cg.bo.ProposalOrganization;
027: import org.kuali.module.cg.bo.ProposalProjectDirector;
028: import org.kuali.module.cg.bo.ProposalSubcontractor;
029:
030: /**
031: * Rules for the Proposal maintenance document.
032: */
033: public class ProposalRule extends CGMaintenanceDocumentRuleBase {
034: protected static Logger LOG = org.apache.log4j.Logger
035: .getLogger(ProposalRule.class);
036:
037: private Proposal newProposalCopy;
038:
039: @Override
040: protected boolean processCustomSaveDocumentBusinessRules(
041: MaintenanceDocument documentCopy) {
042: LOG
043: .info("Entering ProposalRule.processCustomSaveDocumentBusinessRules");
044: processCustomRouteDocumentBusinessRules(documentCopy); // chain call but ignore success
045: LOG
046: .info("Leaving ProposalRule.processCustomSaveDocumentBusinessRules");
047: return true; // save despite error messages
048: }
049:
050: @Override
051: protected boolean processCustomRouteDocumentBusinessRules(
052: MaintenanceDocument documentCopy) {
053: LOG
054: .info("Entering ProposalRule.processCustomRouteDocumentBusinessRules");
055: boolean success = true;
056: success &= checkEndAfterBegin(newProposalCopy
057: .getProposalBeginningDate(), newProposalCopy
058: .getProposalEndingDate(),
059: KFSPropertyConstants.PROPOSAL_ENDING_DATE);
060: success &= checkPrimary(newProposalCopy
061: .getProposalOrganizations(),
062: ProposalOrganization.class,
063: KFSPropertyConstants.PROPOSAL_ORGANIZATIONS,
064: Proposal.class);
065: success &= checkPrimary(newProposalCopy
066: .getProposalProjectDirectors(),
067: ProposalProjectDirector.class,
068: KFSPropertyConstants.PROPOSAL_PROJECT_DIRECTORS,
069: Proposal.class);
070: success &= checkProjectDirectorsExist(newProposalCopy
071: .getProposalProjectDirectors(),
072: ProposalProjectDirector.class,
073: KFSPropertyConstants.PROPOSAL_PROJECT_DIRECTORS);
074: success &= checkProjectDirectorsStatuses(newProposalCopy
075: .getProposalProjectDirectors(),
076: ProposalProjectDirector.class,
077: KFSPropertyConstants.PROPOSAL_PROJECT_DIRECTORS);
078: success &= checkFederalPassThrough(
079: newProposalCopy
080: .getProposalFederalPassThroughIndicator(),
081: newProposalCopy.getAgency(),
082: newProposalCopy.getFederalPassThroughAgencyNumber(),
083: Proposal.class,
084: KFSPropertyConstants.PROPOSAL_FEDERAL_PASS_THROUGH_INDICATOR);
085: success &= checkAgencyNotEqualToFederalPassThroughAgency(
086: newProposalCopy.getAgency(), newProposalCopy
087: .getFederalPassThroughAgency(),
088: KFSPropertyConstants.AGENCY_NUMBER,
089: KFSPropertyConstants.FEDERAL_PASS_THROUGH_AGENCY_NUMBER);
090: LOG
091: .info("Leaving ProposalRule.processCustomRouteDocumentBusinessRules");
092: return success;
093: }
094:
095: /**
096: * @return
097: */
098: @Override
099: public boolean processCustomAddCollectionLineBusinessRules(
100: MaintenanceDocument document, String collectionName,
101: PersistableBusinessObject line) {
102: LOG
103: .debug("Entering ProposalRule.processCustomAddNewCollectionLineBusinessRules( "
104: + collectionName + " )");
105: boolean success = true;
106: success &= validateAddSubcontractor(line);
107: LOG
108: .debug("Leaving ProposalRule.processCustomAddNewCollectionLineBusinessRules( "
109: + collectionName + " )");
110: return success;
111: }
112:
113: /**
114: * This method takes a look at the new line being added and applies appropriate validation checks if the line is a new line for
115: * the {@link Subcontractor} collection. If the validation checks fail, an appropriate error message will be added to the global
116: * error map and the method will return a value of false.
117: *
118: * @param addLine New business object values being added.
119: * @return True is the value being added passed all applicable validation rules.
120: */
121: private boolean validateAddSubcontractor(
122: PersistableBusinessObject addLine) {
123: boolean success = true;
124: if (addLine.getClass().isAssignableFrom(
125: ProposalSubcontractor.class)) {
126: ProposalSubcontractor subc = (ProposalSubcontractor) addLine;
127: if (StringUtils.isBlank(subc.getSubcontractorNumber())) {
128: String propertyName = KFSPropertyConstants.SUBCONTRACTOR_NUMBER;
129: String errorKey = KFSKeyConstants.ERROR_PROPOSAL_SUBCONTRACTOR_NUMBER_REQUIRED_FOR_ADD;
130: GlobalVariables.getErrorMap().putError(propertyName,
131: errorKey);
132: success = false;
133: }
134: }
135: return success;
136: }
137:
138: /**
139: * Performs convenience cast for Maintenance framework. Note that the {@link MaintenanceDocumentRule} events provide only a deep
140: * copy of the document (from KualiDocumentEventBase), so these BOs are a copy too. The framework does this to prevent these
141: * rules from changing any data.
142: *
143: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRule#setupConvenienceObjects()
144: */
145: @Override
146: public void setupConvenienceObjects() {
147: // oldProposalCopy = (Proposal) super.getOldBo();
148: newProposalCopy = (Proposal) super.getNewBo();
149: }
150: }
|