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.module.purap.document.validation.impl;
17  
18  import org.kuali.ole.module.purap.PurapPropertyConstants;
19  import org.kuali.ole.module.purap.businessobject.BillingAddress;
20  import org.kuali.ole.sys.OLEPropertyConstants;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.sys.service.PostalCodeValidationService;
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 BillingAddressRule 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          BillingAddress newBillingAddress = (BillingAddress) 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(newBillingAddress.getBillingCountryCode(), newBillingAddress.getBillingStateCode(), newBillingAddress.getBillingPostalCode(), PurapPropertyConstants.BILLING_ADDRESS_STATE, PurapPropertyConstants.BILLING_ADDRESS_POSTAL_CODE);
48          GlobalVariables.getMessageMap().clearErrorPath();
49          return valid;
50      }
51  
52  }