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.ar.document.validation.impl;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.kfs.module.ar.ArConstants;
020    import org.kuali.kfs.module.ar.businessobject.OrganizationOptions;
021    import org.kuali.kfs.sys.context.SpringContext;
022    import org.kuali.rice.kns.document.Document;
023    import org.kuali.rice.kns.document.MaintenanceDocument;
024    import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
025    import org.kuali.rice.kns.service.ParameterService;
026    
027    /**
028     * This class is used to ensure that default values are set accordingly if blank
029     */
030    public class OrganizationOptionsPreRules extends PromptBeforeValidationBase { 
031    
032        @Override
033        public boolean doPrompts(Document document) {
034    
035            MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
036            OrganizationOptions organizationOptions = (OrganizationOptions) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
037            String institutionName = SpringContext.getBean(ParameterService.class).getParameterValue(OrganizationOptions.class, ArConstants.INSTITUTION_NAME);
038    
039            // If university name is not provided, default to institution name
040            if (StringUtils.isBlank(organizationOptions.getUniversityName())) {
041                organizationOptions.setUniversityName(institutionName);
042            }
043    
044            // If check payable name is not provided, default to institution name
045            if (StringUtils.isBlank(organizationOptions.getOrganizationCheckPayableToName())) {
046                organizationOptions.setOrganizationCheckPayableToName(institutionName);
047            }
048    
049            return true;
050        }
051    }