001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.purap.document.validation.impl;
017
018 import org.kuali.kfs.module.purap.PurapPropertyConstants;
019 import org.kuali.kfs.module.purap.businessobject.ReceivingAddress;
020 import org.kuali.kfs.sys.KFSPropertyConstants;
021 import org.kuali.kfs.sys.context.SpringContext;
022 import org.kuali.kfs.sys.service.PostalCodeValidationService;
023 import org.kuali.rice.kns.document.MaintenanceDocument;
024 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
025 import org.kuali.rice.kns.util.GlobalVariables;
026
027 public class ReceivingAddressRule extends MaintenanceDocumentRuleBase {
028
029 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
030 LOG.info("processCustomApproveDocumentBusinessRules called");
031 this.setupConvenienceObjects();
032 boolean success = this.validateAddress(document);
033 return success && super.processCustomApproveDocumentBusinessRules(document);
034 }
035
036 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
037 LOG.info("processCustomRouteDocumentBusinessRules called");
038 this.setupConvenienceObjects();
039 boolean success = this.validateAddress(document);
040 return success && super.processCustomRouteDocumentBusinessRules(document);
041 }
042
043 protected boolean validateAddress(MaintenanceDocument document) {
044 ReceivingAddress newReceivingAddress = (ReceivingAddress) document.getNewMaintainableObject().getBusinessObject();
045 GlobalVariables.getMessageMap().clearErrorPath();
046 GlobalVariables.getMessageMap().addToErrorPath(KFSPropertyConstants.DOCUMENT + "." + KFSPropertyConstants.NEW_MAINTAINABLE_OBJECT);
047 boolean valid = SpringContext.getBean(PostalCodeValidationService.class).validateAddress(newReceivingAddress.getReceivingCountryCode(), newReceivingAddress.getReceivingStateCode(), newReceivingAddress.getReceivingPostalCode(), PurapPropertyConstants.RECEIVING_ADDRESS_STATE, PurapPropertyConstants.RECEIVING_ADDRESS_POSTAL_CODE);
048 GlobalVariables.getMessageMap().clearErrorPath();
049 return valid;
050 }
051
052 }