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.vnd.document.validation.impl;
017
018 import org.kuali.kfs.sys.KFSPropertyConstants;
019 import org.kuali.kfs.sys.context.SpringContext;
020 import org.kuali.kfs.sys.service.PostalCodeValidationService;
021 import org.kuali.kfs.vnd.VendorPropertyConstants;
022 import org.kuali.kfs.vnd.businessobject.CampusParameter;
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 CampusParameterRule 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 CampusParameter newCampusParameter = (CampusParameter) 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(newCampusParameter.getPurchasingDepartmentCountryCode(), newCampusParameter.getPurchasingDepartmentStateCode(), newCampusParameter.getPurchasingDepartmentZipCode(), VendorPropertyConstants.PURCHASING_DEPARTMENT_STATE, VendorPropertyConstants.PURCHASING_DEPARTMENT_POSTAL_CODE);
048 GlobalVariables.getMessageMap().clearErrorPath();
049 return valid;
050 }
051
052 }