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.roles;
017
018 import java.sql.Date;
019
020 import org.apache.commons.lang.builder.HashCodeBuilder;
021 import org.kuali.hr.core.KPMEConstants;
022 import org.kuali.hr.location.Location;
023 import org.kuali.hr.time.HrBusinessObject;
024 import org.kuali.hr.time.department.Department;
025 import org.kuali.hr.time.position.Position;
026 import org.kuali.hr.time.service.base.TkServiceLocator;
027 import org.kuali.hr.time.util.TKUtils;
028 import org.kuali.hr.time.workarea.WorkArea;
029 import org.kuali.kfs.coa.businessobject.Chart;
030 import org.kuali.rice.kim.api.identity.Person;
031 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
032
033 public class TkRole extends HrBusinessObject {
034
035 private static final long serialVersionUID = -2123815189941339343L;
036
037 public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "TkRole";
038
039 private String hrRolesId;
040 private String principalId;
041 private String roleName;
042 private String userPrincipalId;
043 private Long workArea;
044 private String department;
045 private String chart;
046 private Long hrDeptId;
047 private String positionNumber;
048 private Date expirationDate;
049
050 /**
051 * These objects are used by Lookups to provide links on the maintenance
052 * page. They are not necessarily going to be populated.
053 */
054 private transient Person person;
055 private transient Department departmentObj;
056 private transient WorkArea workAreaObj;
057 private transient Chart chartObj;
058 private transient Position positionObj;
059
060 private Location locationObj;
061
062 public Chart getChartObj() {
063 return chartObj;
064 }
065
066 public void setChartObj(Chart chartObj) {
067 this.chartObj = chartObj;
068 }
069
070 public Department getDepartmentObj() {
071 return departmentObj;
072 }
073
074 public void setDepartmentObj(Department departmentObj) {
075 this.departmentObj = departmentObj;
076 if (departmentObj != null) {
077 this.department = departmentObj.getDept();
078 this.workAreaObj= null;
079 this.workArea = null;
080 }
081 }
082
083 public WorkArea getWorkAreaObj() {
084 return workAreaObj;
085 }
086
087 public void setWorkAreaObj(WorkArea workAreaObj) {
088 this.workAreaObj = workAreaObj;
089 if (workAreaObj != null) {
090 this.workArea = workAreaObj.getWorkArea();
091 this.departmentObj = TkServiceLocator.getDepartmentService().getDepartment(workAreaObj.getDept(), TKUtils.getCurrentDate());
092 this.department = workAreaObj.getDept();
093 }
094 }
095
096 public String getHrRolesId() {
097 return hrRolesId;
098 }
099
100 public void setHrRolesId(String hrRolesId) {
101 this.hrRolesId = hrRolesId;
102 }
103
104 public String getPrincipalId() {
105 return principalId;
106 }
107
108 public void setPrincipalId(String principalId) {
109 this.principalId = principalId;
110 setPerson(KimApiServiceLocator.getPersonService().getPerson(this.principalId));
111 }
112
113 public String getRoleName() {
114 return roleName;
115 }
116
117 public void setRoleName(String roleName) {
118 this.roleName = roleName;
119 }
120
121 public String getUserPrincipalId() {
122 return userPrincipalId;
123 }
124
125 public void setUserPrincipalId(String userPrincipalId) {
126 this.userPrincipalId = userPrincipalId;
127 }
128
129 public Long getWorkArea() {
130 return workArea;
131 }
132
133 public void setWorkArea(Long workArea) {
134 this.workArea = workArea;
135 }
136
137 public String getDepartment() {
138 return department;
139 }
140
141 public void setDepartment(String department) {
142 this.department = department;
143 }
144
145 public Person getPerson() {
146 return person;
147 }
148
149 public void setPerson(Person person) {
150 this.person = person;
151 }
152
153 public Long getHrDeptId() {
154 return hrDeptId;
155 }
156
157 public void setHrDeptId(Long hrDeptId) {
158 this.hrDeptId = hrDeptId;
159 }
160
161 public String getChart() {
162 return chart;
163 }
164
165 public void setChart(String chart) {
166 this.chart = chart;
167 }
168
169 /**
170 * This method supports maintenance and lookup pages.
171 */
172 public String getUserName() {
173 if (person == null) {
174 person = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
175 }
176
177 return (person != null) ? person.getName() : "";
178 }
179
180 public void setPositionNumber(String positionNumber) {
181 this.positionNumber = positionNumber;
182 }
183
184 public String getPositionNumber() {
185 return positionNumber;
186 }
187
188 public Date getExpirationDate() {
189 return expirationDate;
190 }
191
192 public void setExpirationDate(Date expirationDate) {
193 this.expirationDate = expirationDate;
194 }
195
196 public void setPositionObj(Position positionObj) {
197 this.positionObj = positionObj;
198 }
199
200 public Position getPositionObj() {
201 return positionObj;
202 }
203
204 @Override
205 public String getUniqueKey() {
206 return principalId + "_" + positionNumber != null ? positionNumber.toString() : "" +"_"+
207 roleName + "_" + workArea != null ? workArea.toString() : "" + "_" +
208 department + "_" + chart;
209 }
210
211 @Override
212 public String getId() {
213 return getHrRolesId();
214 }
215
216 @Override
217 public void setId(String id) {
218 setHrRolesId(id);
219 }
220
221 public Location getLocationObj() {
222 return locationObj;
223 }
224
225 public void setLocationObj(Location locationObj) {
226 this.locationObj = locationObj;
227 }
228
229 @Override
230 public int hashCode() {
231 return HashCodeBuilder.reflectionHashCode(this);
232 }
233
234 @Override
235 public boolean equals(Object o) {
236 if (this == o) return true;
237 if (o == null || getClass() != o.getClass()) return false;
238
239 TkRole tkRole = (TkRole) o;
240
241 if (chart != null ? !chart.equals(tkRole.chart) : tkRole.chart != null) return false;
242 if (chartObj != null ? !chartObj.equals(tkRole.chartObj) : tkRole.chartObj != null) return false;
243 if (department != null ? !department.equals(tkRole.department) : tkRole.department != null) return false;
244 if (departmentObj != null ? !departmentObj.equals(tkRole.departmentObj) : tkRole.departmentObj != null)
245 return false;
246 if (expirationDate != null ? !expirationDate.equals(tkRole.expirationDate) : tkRole.expirationDate != null)
247 return false;
248 if (hrDeptId != null ? !hrDeptId.equals(tkRole.hrDeptId) : tkRole.hrDeptId != null) return false;
249 if (!hrRolesId.equals(tkRole.hrRolesId)) return false;
250 if (locationObj != null ? !locationObj.equals(tkRole.locationObj) : tkRole.locationObj != null) return false;
251 if (person != null ? !person.equals(tkRole.person) : tkRole.person != null) return false;
252 if (positionNumber != null ? !positionNumber.equals(tkRole.positionNumber) : tkRole.positionNumber != null)
253 return false;
254 if (positionObj != null ? !positionObj.equals(tkRole.positionObj) : tkRole.positionObj != null) return false;
255 if (principalId != null ? !principalId.equals(tkRole.principalId) : tkRole.principalId != null) return false;
256 if (roleName != null ? !roleName.equals(tkRole.roleName) : tkRole.roleName != null) return false;
257 if (userPrincipalId != null ? !userPrincipalId.equals(tkRole.userPrincipalId) : tkRole.userPrincipalId != null)
258 return false;
259 if (workArea != null ? !workArea.equals(tkRole.workArea) : tkRole.workArea != null) return false;
260 if (workAreaObj != null ? !workAreaObj.equals(tkRole.workAreaObj) : tkRole.workAreaObj != null) return false;
261
262 return true;
263 }
264 }