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.cg.document.validation.impl;
017    
018    import java.util.Collections;
019    import java.util.HashMap;
020    import java.util.Map;
021    
022    import org.apache.commons.lang.StringUtils;
023    import org.kuali.kfs.module.cg.businessobject.Award;
024    import org.kuali.kfs.sys.KFSPropertyConstants;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.rice.kns.service.BusinessObjectService;
027    import org.kuali.rice.kns.util.ObjectUtils;
028    
029    /**
030     * Rules for the Award maintenance document.
031     */
032    public class AwardRuleUtil {
033        /**
034         * Determines if a proposal has already been awarded
035         * 
036         * @param award the award to check the proposal for
037         * @return true if the award's proposal has already been awarded
038         */
039        public static boolean isProposalAwarded(Award award) {
040            if (ObjectUtils.isNull(award)) {
041                return false;
042            }
043    
044            Award result = (Award) SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(Award.class, award.getProposalNumber());
045    
046            // Make sure it exists and is not the same object
047            return ObjectUtils.isNotNull(result) && !StringUtils.equals(award.getObjectId(), result.getObjectId());
048        }
049    
050    
051        /**
052         * Per KULCG-315 - Proposals should not be designated as inactive. This functionality is not yet implemented and this rule
053         * should not be applied at this time. I'm leaving this code here in case the functionality gets added down the road.
054         */
055        // /**
056        // * determines if a proposal is inactive
057        // *
058        // * @param award the award to check the proposal for
059        // * @return true if the award's proposal has already been set to inactive
060        // */
061        // public static boolean isProposalInactive(Award award) {
062        // if (ObjectUtils.isNull(award)) {
063        // return false;
064        // }
065        //
066        // Long proposalNumber = award.getProposalNumber();
067        // Map<String, Object> awardPrimaryKeys = new HashMap<String, Object>();
068        // awardPrimaryKeys.put(KFSPropertyConstants.PROPOSAL_NUMBER, proposalNumber);
069        // Award result = (Award) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Award.class, awardPrimaryKeys);
070        //
071        // boolean inactive = ObjectUtils.isNotNull(result) && !result.isActive();
072        //
073        // return inactive;
074        // }
075    }