001    /**
002     * Copyright 2005-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.rice.krad.bo;
017    
018    import org.joda.time.DateTime;
019    import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
020    
021    import javax.persistence.Column;
022    import javax.persistence.MappedSuperclass;
023    import javax.persistence.Transient;
024    import java.sql.Timestamp;
025    
026    /**
027     * @author Kuali Rice Team (rice.collab@kuali.org)
028     */
029    @MappedSuperclass
030    public abstract class InactivatableFromToImpl extends PersistableBusinessObjectBase implements InactivatableFromTo {
031    
032            private static final long serialVersionUID = 1L;
033    
034            @Column(name = "ACTV_FRM_DT")
035            protected Timestamp activeFromDate;
036            @Column(name = "ACTV_TO_DT")
037            protected Timestamp activeToDate;
038            @Transient
039            protected Timestamp activeAsOfDate;
040            @Transient
041            protected boolean current;
042    
043            /**
044             * Returns active if the {@link #getActiveAsOfDate()} (current time used if not set) is between
045             * the from and to dates. Null dates are considered to indicate an open range.
046             */
047            public boolean isActive() {
048            return InactivatableFromToUtils.isActive(new DateTime(activeFromDate), new DateTime(activeToDate), new DateTime(activeAsOfDate));
049            }
050            
051            public void setActive(boolean active) {
052                    // do nothing
053            }
054    
055            public void setActiveFromDate(Timestamp from) {
056                    this.activeFromDate = from;
057            }
058    
059            public void setActiveToDate(Timestamp to) {
060                    this.activeToDate = to;
061            }
062    
063            public Timestamp getActiveFromDate() {
064                    return this.activeFromDate;
065            }
066    
067            public Timestamp getActiveToDate() {
068                    return this.activeToDate;
069            }
070    
071            public Timestamp getActiveAsOfDate() {
072                    return this.activeAsOfDate;
073            }
074    
075            public void setActiveAsOfDate(Timestamp activeAsOfDate) {
076                    this.activeAsOfDate = activeAsOfDate;
077            }
078    
079            public boolean isCurrent() {
080                    return this.current;
081            }
082    
083            public void setCurrent(boolean current) {
084                    this.current = current;
085            }
086    }