View Javadoc

1   /**
2    * Copyright 2004-2013 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.hr.time.calendar;
17  
18  import java.sql.Time;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.commons.lang.builder.HashCodeBuilder;
24  import org.joda.time.DateTimeConstants;
25  import org.kuali.hr.core.KPMEConstants;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  
28  public class Calendar extends PersistableBusinessObjectBase {
29      public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "Calendar";
30      /**
31       *
32       */
33  	private static final long serialVersionUID = 1L;
34  
35  	private String hrCalendarId;
36  	private String calendarName;
37  	private String calendarDescriptions;
38  
39  	private String flsaBeginDay;
40  	private Time flsaBeginTime;
41  	private String calendarTypes;
42  	private int flsaBeginDayConstant = -1;
43  
44  	private List<CalendarEntries> calendarEntries = new ArrayList<CalendarEntries>();
45  
46  	public Calendar() {
47  
48  	}
49  	
50  	public String getHrCalendarId() {
51  		return hrCalendarId;
52  	}
53  
54  
55  
56  	public void setHrCalendarId(String hrCalendarId) {
57  		this.hrCalendarId = hrCalendarId;
58  	}
59  
60  
61  
62  	public String getCalendarName() {
63  		return calendarName;
64  	}
65  
66  
67  
68  	public void setCalendarName(String calendarName) {
69  		this.calendarName = calendarName;
70  	}
71  
72  
73  
74  	public String getCalendarTypes() {
75  		return calendarTypes;
76  	}
77  
78  
79  
80  	public void setCalendarTypes(String calendarTypes) {
81  		this.calendarTypes = calendarTypes;
82  	}
83  
84  
85  
86  	public List<CalendarEntries> getCalendarEntries() {
87  		return calendarEntries;
88  	}
89  
90  
91  
92  	public void setCalendarEntries(List<CalendarEntries> calendarEntries) {
93  		this.calendarEntries = calendarEntries;
94  	}
95  
96  
97  
98  	public void setFlsaBeginDayConstant(int flsaBeginDayConstant) {
99  		this.flsaBeginDayConstant = flsaBeginDayConstant;
100 	}
101 
102 	public String getCalendarDescriptions() {
103 		return calendarDescriptions;
104 	}
105 
106 	public void setCalendarDescriptions(String calendarDescriptions) {
107 		this.calendarDescriptions = calendarDescriptions;
108 	}
109 
110 	public String getFlsaBeginDay() {
111 		return flsaBeginDay;
112 	}
113 
114 	public void setFlsaBeginDay(String flsaBeginDay) {
115 		this.flsaBeginDay = flsaBeginDay;
116 		this.setFlsaBeinDayConstant(flsaBeginDay);
117 	}
118 
119 	public Time getFlsaBeginTime() {
120 		return flsaBeginTime;
121 	}
122 
123 	public void setFlsaBeginTime(Time flsaBeginTime) {
124 		this.flsaBeginTime = flsaBeginTime;
125 	}
126 
127 	/**
128 	 * This method sets a constant matching those listed in
129 	 * org.joda.time.DateTimeConstants for day comparisons.
130 	 *
131 	 * Currently this is 'hard-coded' to be English specific, it would
132 	 * be trivial to change and support more than one language/day naming
133 	 * convention.
134 	 *
135 	 * @param day
136 	 */
137 	private void setFlsaBeinDayConstant(String day) {
138 		if (!StringUtils.isEmpty(day)) {
139 			day = day.toLowerCase().trim();
140 
141 			if (day.startsWith("m")) {
142 				this.flsaBeginDayConstant = DateTimeConstants.MONDAY;
143 			} else if (day.startsWith("tu")) {
144 				this.flsaBeginDayConstant = DateTimeConstants.TUESDAY;
145 			} else if (day.startsWith("w")) {
146 				this.flsaBeginDayConstant = DateTimeConstants.WEDNESDAY;
147 			} else if (day.startsWith("th")) {
148 				this.flsaBeginDayConstant = DateTimeConstants.THURSDAY;
149 			} else if (day.startsWith("f")) {
150 				this.flsaBeginDayConstant = DateTimeConstants.FRIDAY;
151 			} else if (day.startsWith("sa")) {
152 				this.flsaBeginDayConstant = DateTimeConstants.SATURDAY;
153 			} else if (day.startsWith("su")) {
154 				this.flsaBeginDayConstant = DateTimeConstants.SUNDAY;
155 			}
156 		}
157 	}
158 
159 	/**
160 	 * org.joda.time.DateTimeConstants.MONDAY
161 	 * ...
162 	 * org.joda.time.DateTimeConstants.SUNDAY
163 	 *
164 	 * @return an int representing the FLSA start day, sourced from
165 	 * org.joda.time.DateTimeConstants in the interval [1,7].
166 	 */
167 	public int getFlsaBeginDayConstant() {
168 		if (flsaBeginDayConstant < 0) {
169 			this.setFlsaBeinDayConstant(this.getFlsaBeginDay());
170 		}
171 		return flsaBeginDayConstant;
172 	}
173 
174     @Override
175     public int hashCode() {
176         return HashCodeBuilder.reflectionHashCode(this);
177     }
178 
179     @Override
180     public boolean equals(Object o) {
181         if (o instanceof Calendar) {
182             Calendar pc = (Calendar)o;
183             return this.getHrCalendarId().compareTo(pc.getHrCalendarId()) == 0;
184         } else {
185             return false;
186         }
187     }
188 }