1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.calendar;
17
18 import com.google.common.collect.ImmutableList;
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.commons.lang.builder.HashCodeBuilder;
21 import org.joda.time.DateTimeConstants;
22 import org.joda.time.LocalTime;
23 import org.kuali.kpme.core.api.calendar.Calendar;
24 import org.kuali.kpme.core.api.calendar.CalendarContract;
25 import org.kuali.kpme.core.util.HrConstants;
26 import org.kuali.rice.core.api.mo.ModelObjectUtils;
27 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
28
29 import java.sql.Time;
30
31 public class CalendarBo extends PersistableBusinessObjectBase implements CalendarContract {
32 public static final String CACHE_NAME = HrConstants.CacheNamespace.NAMESPACE_PREFIX + "Calendar";
33 public static final ModelObjectUtils.Transformer<CalendarBo, Calendar> toCalendar =
34 new ModelObjectUtils.Transformer<CalendarBo, Calendar>() {
35 public Calendar transform(CalendarBo input) {
36 return CalendarBo.to(input);
37 };
38 };
39 public static final ModelObjectUtils.Transformer<Calendar, CalendarBo> toCalendarBo =
40 new ModelObjectUtils.Transformer<Calendar, CalendarBo>() {
41 public CalendarBo transform(Calendar input) {
42 return CalendarBo.from(input);
43 };
44 };
45 public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
46 .add("calendarName")
47 .build();
48
49
50
51 private static final long serialVersionUID = 1L;
52
53 private String hrCalendarId;
54 private String calendarName;
55 private String calendarDescriptions;
56
57 private String flsaBeginDay;
58 private Time flsaBeginTime;
59 private String calendarTypes;
60 private int flsaBeginDayConstant = -1;
61
62 public String getHrCalendarId() {
63 return hrCalendarId;
64 }
65
66 public void setHrCalendarId(String hrCalendarId) {
67 this.hrCalendarId = hrCalendarId;
68 }
69
70 public String getCalendarName() {
71 return calendarName;
72 }
73
74 public void setCalendarName(String calendarName) {
75 this.calendarName = calendarName;
76 }
77
78 public String getCalendarTypes() {
79 return calendarTypes;
80 }
81
82 public void setCalendarTypes(String calendarTypes) {
83 this.calendarTypes = calendarTypes;
84 }
85
86 public void setFlsaBeginDayConstant(int flsaBeginDayConstant) {
87 this.flsaBeginDayConstant = flsaBeginDayConstant;
88 }
89
90 public String getCalendarDescriptions() {
91 return calendarDescriptions;
92 }
93
94 public void setCalendarDescriptions(String calendarDescriptions) {
95 this.calendarDescriptions = calendarDescriptions;
96 }
97
98 public String getFlsaBeginDay() {
99 return flsaBeginDay;
100 }
101
102 public void setFlsaBeginDay(String flsaBeginDay) {
103 this.flsaBeginDay = flsaBeginDay;
104 this.setFlsaBeinDayConstant(flsaBeginDay);
105 }
106
107 public Time getFlsaBeginTime() {
108 return flsaBeginTime;
109 }
110
111 public LocalTime getFlsaBeginLocalTime() {
112 return getFlsaBeginTime() == null ? null : LocalTime.fromDateFields(getFlsaBeginTime());
113 }
114
115 public void setFlsaBeginTime(Time flsaBeginTime) {
116 this.flsaBeginTime = flsaBeginTime;
117 }
118
119
120
121
122
123
124
125
126
127
128
129 private void setFlsaBeinDayConstant(String day) {
130 if (!StringUtils.isEmpty(day)) {
131 day = day.toLowerCase().trim();
132
133 if (day.startsWith("m")) {
134 this.flsaBeginDayConstant = DateTimeConstants.MONDAY;
135 } else if (day.startsWith("tu")) {
136 this.flsaBeginDayConstant = DateTimeConstants.TUESDAY;
137 } else if (day.startsWith("w")) {
138 this.flsaBeginDayConstant = DateTimeConstants.WEDNESDAY;
139 } else if (day.startsWith("th")) {
140 this.flsaBeginDayConstant = DateTimeConstants.THURSDAY;
141 } else if (day.startsWith("f")) {
142 this.flsaBeginDayConstant = DateTimeConstants.FRIDAY;
143 } else if (day.startsWith("sa")) {
144 this.flsaBeginDayConstant = DateTimeConstants.SATURDAY;
145 } else if (day.startsWith("su")) {
146 this.flsaBeginDayConstant = DateTimeConstants.SUNDAY;
147 }
148 }
149 }
150
151 public int getFlsaEndDayConstant() {
152 if (this.getFlsaBeginDayConstant() == DateTimeConstants.MONDAY) {
153 return DateTimeConstants.SUNDAY;
154 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.TUESDAY) {
155 return DateTimeConstants.MONDAY;
156 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.WEDNESDAY) {
157 return DateTimeConstants.TUESDAY;
158 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.THURSDAY) {
159 return DateTimeConstants.WEDNESDAY;
160 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.FRIDAY) {
161 return DateTimeConstants.THURSDAY;
162 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.SATURDAY) {
163 return DateTimeConstants.FRIDAY;
164 } else if (this.getFlsaBeginDayConstant() == DateTimeConstants.SUNDAY) {
165 return DateTimeConstants.SATURDAY;
166 }
167 return 0;
168 }
169
170
171
172
173
174
175
176
177
178 public int getFlsaBeginDayConstant() {
179 if (flsaBeginDayConstant < 0) {
180 this.setFlsaBeinDayConstant(this.getFlsaBeginDay());
181 }
182 return flsaBeginDayConstant;
183 }
184
185 @Override
186 public int hashCode() {
187 return HashCodeBuilder.reflectionHashCode(this);
188 }
189
190 @Override
191 public boolean equals(Object o) {
192 if (o instanceof CalendarBo) {
193 CalendarBo pc = (CalendarBo)o;
194 return this.getHrCalendarId().compareTo(pc.getHrCalendarId()) == 0;
195 } else {
196 return false;
197 }
198 }
199
200 public static CalendarBo from(Calendar im) {
201 if (im == null) {
202 return null;
203 }
204 CalendarBo cal = new CalendarBo();
205 cal.setHrCalendarId(im.getHrCalendarId());
206 cal.setCalendarName(im.getCalendarName());
207 cal.setCalendarDescriptions(im.getCalendarDescriptions());
208 cal.setFlsaBeginDay(im.getFlsaBeginDay());
209 cal.setFlsaBeginTime(im.getFlsaBeginLocalTime() == null ? null : new Time(im.getFlsaBeginLocalTime().toDateTimeToday().getMillis()));
210 cal.setCalendarTypes(im.getCalendarTypes());
211 cal.setFlsaBeginDayConstant(im.getFlsaBeginDayConstant());
212
213 cal.setVersionNumber(im.getVersionNumber());
214 cal.setObjectId(im.getObjectId());
215
216 return cal;
217 }
218
219 public static Calendar to(CalendarBo bo) {
220 if (bo == null) {
221 return null;
222 }
223
224 return Calendar.Builder.create(bo).build();
225 }
226 }