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