View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.bo;
17  
18  import org.joda.time.DateTime;
19  import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
20  
21  import javax.persistence.Column;
22  import javax.persistence.Embeddable;
23  import javax.persistence.MappedSuperclass;
24  import javax.persistence.Transient;
25  import java.sql.Timestamp;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  @MappedSuperclass
31  public abstract class InactivatableFromToImpl extends PersistableBusinessObjectBase implements InactivatableFromTo {
32  
33  	private static final long serialVersionUID = 1L;
34  
35      /**
36       * EclipseLink static weaving does not weave MappedSuperclass unless an Entity or Embedded is
37       * weaved which uses it, hence this class.
38       */
39      @Embeddable
40      private static final class WeaveMe extends InactivatableFromToImpl {}
41  
42      @Column(name = "ACTV_FRM_DT")
43  	protected Timestamp activeFromDate;
44  	@Column(name = "ACTV_TO_DT")
45  	protected Timestamp activeToDate;
46  	@Transient
47  	protected Timestamp activeAsOfDate;
48  	@Transient
49  	protected boolean current;
50  
51  	/**
52  	 * Returns active if the {@link #getActiveAsOfDate()} (current time used if not set) is between
53  	 * the from and to dates. Null dates are considered to indicate an open range.
54  	 */
55  	public boolean isActive() {
56          return InactivatableFromToUtils.isActive(activeFromDate == null ? null : new DateTime(activeFromDate),
57                                                   activeToDate == null ? null : new DateTime(activeToDate),
58                                                   new DateTime(activeAsOfDate));
59  	}
60  	
61  	public void setActive(boolean active) {
62  		// do nothing
63  	}
64  
65  	public void setActiveFromDate(Timestamp from) {
66  		this.activeFromDate = from;
67  	}
68  
69  	public void setActiveToDate(Timestamp to) {
70  		this.activeToDate = to;
71  	}
72  
73  	public Timestamp getActiveFromDate() {
74  		return this.activeFromDate;
75  	}
76  
77  	public Timestamp getActiveToDate() {
78  		return this.activeToDate;
79  	}
80  
81  	public Timestamp getActiveAsOfDate() {
82  		return this.activeAsOfDate;
83  	}
84  
85  	public void setActiveAsOfDate(Timestamp activeAsOfDate) {
86  		this.activeAsOfDate = activeAsOfDate;
87  	}
88  
89  	public boolean isCurrent() {
90  		return this.current;
91  	}
92  
93  	public void setCurrent(boolean current) {
94  		this.current = current;
95  	}
96  }