View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.cg.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.ole.module.cg.businessobject.Proposal;
21  import org.kuali.ole.module.cg.businessobject.ProposalOrganization;
22  import org.kuali.ole.module.cg.businessobject.ProposalProjectDirector;
23  import org.kuali.ole.module.cg.businessobject.ProposalSubcontractor;
24  import org.kuali.ole.sys.OLEKeyConstants;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.rice.kns.document.MaintenanceDocument;
27  import org.kuali.rice.krad.bo.PersistableBusinessObject;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  /**
31   * Rules for the Proposal maintenance document.
32   */
33  public class ProposalRule extends CGMaintenanceDocumentRuleBase {
34      protected static Logger LOG = org.apache.log4j.Logger.getLogger(ProposalRule.class);
35  
36      protected Proposal newProposalCopy;
37  
38      @Override
39      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument documentCopy) {
40          LOG.debug("Entering ProposalRule.processCustomSaveDocumentBusinessRules");
41          processCustomRouteDocumentBusinessRules(documentCopy); // chain call but ignore success
42          LOG.info("Leaving ProposalRule.processCustomSaveDocumentBusinessRules");
43          return true; // save despite error messages
44      }
45  
46      @Override
47      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument documentCopy) {
48          LOG.debug("Entering ProposalRule.processCustomRouteDocumentBusinessRules");
49          boolean success = true;
50          success &= checkEndAfterBegin(newProposalCopy.getProposalBeginningDate(), newProposalCopy.getProposalEndingDate(), OLEPropertyConstants.PROPOSAL_ENDING_DATE);
51          success &= checkPrimary(newProposalCopy.getProposalOrganizations(), ProposalOrganization.class, OLEPropertyConstants.PROPOSAL_ORGANIZATIONS, Proposal.class);
52          success &= checkPrimary(newProposalCopy.getProposalProjectDirectors(), ProposalProjectDirector.class, OLEPropertyConstants.PROPOSAL_PROJECT_DIRECTORS, Proposal.class);
53          success &= checkProjectDirectorsAreDirectors(newProposalCopy.getProposalProjectDirectors(), ProposalProjectDirector.class, OLEPropertyConstants.PROPOSAL_PROJECT_DIRECTORS);
54          success &= checkProjectDirectorsExist(newProposalCopy.getProposalProjectDirectors(), ProposalProjectDirector.class, OLEPropertyConstants.PROPOSAL_PROJECT_DIRECTORS);
55          success &= checkProjectDirectorsStatuses(newProposalCopy.getProposalProjectDirectors(), ProposalProjectDirector.class, OLEPropertyConstants.PROPOSAL_PROJECT_DIRECTORS);
56          success &= checkFederalPassThrough(newProposalCopy.getProposalFederalPassThroughIndicator(), newProposalCopy.getAgency(), newProposalCopy.getFederalPassThroughAgencyNumber(), Proposal.class, OLEPropertyConstants.PROPOSAL_FEDERAL_PASS_THROUGH_INDICATOR);
57          success &= checkAgencyNotEqualToFederalPassThroughAgency(newProposalCopy.getAgency(), newProposalCopy.getFederalPassThroughAgency(), OLEPropertyConstants.AGENCY_NUMBER, OLEPropertyConstants.FEDERAL_PASS_THROUGH_AGENCY_NUMBER);
58          LOG.info("Leaving ProposalRule.processCustomRouteDocumentBusinessRules");
59          return success;
60      }
61  
62      /**
63       * @return
64       */
65      @Override
66      public boolean processCustomAddCollectionLineBusinessRules(MaintenanceDocument document, String collectionName, PersistableBusinessObject line) {
67          if (LOG.isDebugEnabled()) {
68              LOG.debug("Entering ProposalRule.processCustomAddNewCollectionLineBusinessRules( " + collectionName + " )");
69          }
70          boolean success = true;
71          success &= validateAddSubcontractor(line);
72          if (LOG.isDebugEnabled()) {
73              LOG.debug("Leaving ProposalRule.processCustomAddNewCollectionLineBusinessRules( " + collectionName + " )");
74          }
75          return success;
76      }
77  
78      /**
79       * This method takes a look at the new line being added and applies appropriate validation checks if the line is a new line for
80       * the {@link Subcontractor} collection. If the validation checks fail, an appropriate error message will be added to the global
81       * error map and the method will return a value of false.
82       * 
83       * @param addLine New business object values being added.
84       * @return True is the value being added passed all applicable validation rules.
85       */
86      protected boolean validateAddSubcontractor(PersistableBusinessObject addLine) {
87          boolean success = true;
88          if (addLine.getClass().isAssignableFrom(ProposalSubcontractor.class)) {
89              ProposalSubcontractor subc = (ProposalSubcontractor) addLine;
90              if (StringUtils.isBlank(subc.getSubcontractorNumber())) {
91                  String propertyName = OLEPropertyConstants.SUBCONTRACTOR_NUMBER;
92                  String errorKey = OLEKeyConstants.ERROR_PROPOSAL_SUBCONTRACTOR_NUMBER_REQUIRED_FOR_ADD;
93                  GlobalVariables.getMessageMap().putError(propertyName, errorKey);
94                  success = false;
95              }
96          }
97          return success;
98      }
99  
100     /**
101      * Performs convenience cast for Maintenance framework. Note that the {@link MaintenanceDocumentRule} events provide only a deep
102      * copy of the document (from KualiDocumentEventBase), so these BOs are a copy too. The framework does this to prevent these
103      * rules from changing any data.
104      * 
105      * @see org.kuali.rice.kns.rules.MaintenanceDocumentRule#setupConvenienceObjects()
106      */
107     @Override
108     public void setupConvenienceObjects() {
109         // oldProposalCopy = (Proposal) super.getOldBo();
110         newProposalCopy = (Proposal) super.getNewBo();
111     }
112     
113     
114 }