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.sql.Date;
019    
020    import org.kuali.kfs.module.cg.document.ProposalAwardCloseDocument;
021    import org.kuali.kfs.sys.KFSKeyConstants;
022    import org.kuali.kfs.sys.context.SpringContext;
023    import org.kuali.rice.kns.document.Document;
024    import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
025    import org.kuali.rice.kns.service.DateTimeService;
026    
027    /**
028     * 
029     */
030    public class ProposalCloseRule extends MaintenanceDocumentRuleBase {
031    
032        /**
033         * @see MaintenanceDocumentRuleBase#processSaveDocument(Document)
034         */
035        @Override
036        public boolean processSaveDocument(Document document) {
037            boolean isOk = super.processSaveDocument(document);
038            if (!isOk) {
039                return isOk;
040            }
041            ProposalAwardCloseDocument close = (ProposalAwardCloseDocument) document.getDocumentBusinessObject();
042            Date userDate = close.getUserInitiatedCloseDate();
043            Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight();
044            isOk = today.getTime() <= userDate.getTime();
045            if (!isOk) {
046                putFieldError("userInitiatedCloseDate", KFSKeyConstants.ContractsAndGrants.USER_INITIATED_DATE_TOO_EARLY, userDate.toString());
047            }
048            return isOk;
049        }
050    }