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