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