View Javadoc
1   /*
2    * Copyright 2007-2009 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.vnd.document.validation.impl;
17  
18  import org.kuali.ole.sys.OLEPropertyConstants;
19  import org.kuali.ole.sys.context.SpringContext;
20  import org.kuali.ole.sys.service.PostalCodeValidationService;
21  import org.kuali.ole.vnd.VendorPropertyConstants;
22  import org.kuali.ole.vnd.businessobject.CampusParameter;
23  import org.kuali.rice.kns.document.MaintenanceDocument;
24  import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class CampusParameterRule extends MaintenanceDocumentRuleBase {
28  
29      protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
30          LOG.info("processCustomApproveDocumentBusinessRules called");
31          this.setupConvenienceObjects();
32          boolean success = this.validateAddress(document);
33          return success && super.processCustomApproveDocumentBusinessRules(document);
34      }
35  
36      protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
37          LOG.info("processCustomRouteDocumentBusinessRules called");
38          this.setupConvenienceObjects();
39          boolean success = this.validateAddress(document);
40          return success && super.processCustomRouteDocumentBusinessRules(document);
41      }
42  
43      protected boolean validateAddress(MaintenanceDocument document) {
44          CampusParameter newCampusParameter = (CampusParameter) document.getNewMaintainableObject().getBusinessObject();
45          GlobalVariables.getMessageMap().clearErrorPath();
46          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT + "." + OLEPropertyConstants.NEW_MAINTAINABLE_OBJECT);
47          boolean valid = SpringContext.getBean(PostalCodeValidationService.class).validateAddress(newCampusParameter.getPurchasingDepartmentCountryCode(), newCampusParameter.getPurchasingDepartmentStateCode(), newCampusParameter.getPurchasingDepartmentZipCode(), VendorPropertyConstants.PURCHASING_DEPARTMENT_STATE, VendorPropertyConstants.PURCHASING_DEPARTMENT_POSTAL_CODE);
48  		GlobalVariables.getMessageMap().clearErrorPath();
49          return valid;
50      }
51  
52  }