001 /**
002 * Copyright 2004-2013 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.hr.time.calendar;
017
018 import java.sql.Time;
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.apache.commons.lang.builder.HashCodeBuilder;
024 import org.joda.time.DateTimeConstants;
025 import org.kuali.hr.core.KPMEConstants;
026 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
027
028 public class Calendar extends PersistableBusinessObjectBase {
029 public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "Calendar";
030 /**
031 *
032 */
033 private static final long serialVersionUID = 1L;
034
035 private String hrCalendarId;
036 private String calendarName;
037 private String calendarDescriptions;
038
039 private String flsaBeginDay;
040 private Time flsaBeginTime;
041 private String calendarTypes;
042 private int flsaBeginDayConstant = -1;
043
044 private List<CalendarEntries> calendarEntries = new ArrayList<CalendarEntries>();
045
046 public Calendar() {
047
048 }
049
050 public String getHrCalendarId() {
051 return hrCalendarId;
052 }
053
054
055
056 public void setHrCalendarId(String hrCalendarId) {
057 this.hrCalendarId = hrCalendarId;
058 }
059
060
061
062 public String getCalendarName() {
063 return calendarName;
064 }
065
066
067
068 public void setCalendarName(String calendarName) {
069 this.calendarName = calendarName;
070 }
071
072
073
074 public String getCalendarTypes() {
075 return calendarTypes;
076 }
077
078
079
080 public void setCalendarTypes(String calendarTypes) {
081 this.calendarTypes = calendarTypes;
082 }
083
084
085
086 public List<CalendarEntries> getCalendarEntries() {
087 return calendarEntries;
088 }
089
090
091
092 public void setCalendarEntries(List<CalendarEntries> calendarEntries) {
093 this.calendarEntries = calendarEntries;
094 }
095
096
097
098 public void setFlsaBeginDayConstant(int flsaBeginDayConstant) {
099 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 }