001    /**
002     * Copyright 2004-2012 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    import java.sql.Timestamp;
020    
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        public static final String CACHE_NAME = KPMEConstants.APPLICATION_NAMESPACE_CODE + "/" + "TkRole";
035            /**
036             *
037             */
038            private static final long serialVersionUID = 1L;
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 tkWorkAreaId;
048            private String positionNumber;
049            private Date expirationDate;
050    
051        /**
052         * These objects are used by Lookups to provide links on the maintenance
053         * page. They are not necessarily going to be populated.
054         */
055            private Person person;
056        private Department departmentObj;
057        private WorkArea workAreaObj;
058        private Chart chartObj;
059        private Position positionObj;
060        
061        private Location locationObj;
062    
063        public Chart getChartObj() {
064            return chartObj;
065        }
066    
067        public void setChartObj(Chart chartObj) {
068            this.chartObj = chartObj;
069        }
070    
071        public Department getDepartmentObj() {
072            return departmentObj;
073        }
074    
075        public void setDepartmentObj(Department departmentObj) {
076            this.departmentObj = departmentObj;
077            if (departmentObj != null) {
078                this.department = departmentObj.getDept();
079                this.workAreaObj= null;
080                this.workArea = null;
081            }
082        }
083    
084        public WorkArea getWorkAreaObj() {
085            return workAreaObj;
086        }
087    
088        public void setWorkAreaObj(WorkArea workAreaObj) {
089            this.workAreaObj = workAreaObj;
090            if (workAreaObj != null) {
091                this.workArea = workAreaObj.getWorkArea();
092                this.departmentObj = TkServiceLocator.getDepartmentService().getDepartment(workAreaObj.getDept(), TKUtils.getCurrentDate());
093                this.department = workAreaObj.getDept();
094            }
095        }
096    
097        public String getHrRolesId() {
098                    return hrRolesId;
099            }
100            public void setHrRolesId(String hrRolesId) {
101                    this.hrRolesId = hrRolesId;
102            }
103            public String getPrincipalId() {
104                    return principalId;
105            }
106            public void setPrincipalId(String principalId) {
107                    this.principalId = principalId;
108            setPerson(KimApiServiceLocator.getPersonService().getPerson(this.principalId));
109            }
110            public String getRoleName() {
111                    return roleName;
112            }
113            public void setRoleName(String roleName) {
114                    this.roleName = roleName;
115            }
116            public String getUserPrincipalId() {
117                    return userPrincipalId;
118            }
119            public void setUserPrincipalId(String userPrincipalId) {
120                    this.userPrincipalId = userPrincipalId;
121            }
122            public Long getWorkArea() {
123                    return workArea;
124            }
125            public void setWorkArea(Long workArea) {
126                    this.workArea = workArea;
127            }
128            public String getDepartment() {
129                    return department;
130            }
131            public void setDepartment(String department) {
132                    this.department = department;
133            }
134            
135            public Date getEffectiveDate() {
136                    return effectiveDate;
137            }
138            public void setEffectiveDate(Date effectiveDate) {
139                    this.effectiveDate = effectiveDate;
140            }
141            public Timestamp getTimestamp() {
142                    return timestamp;
143            }
144            public void setTimestamp(Timestamp timestamp) {
145                    this.timestamp = timestamp;
146            }
147            public boolean isActive() {
148                    return active;
149            }
150            public void setActive(boolean active) {
151                    this.active = active;
152            }
153            public Person getPerson() {
154                    return person;
155            }
156            public void setPerson(Person person) {
157                    this.person = person;
158            }
159            public Long getHrDeptId() {
160                    return hrDeptId;
161            }
162            public void setHrDeptId(Long hrDeptId) {
163                    this.hrDeptId = hrDeptId;
164            }
165            public String getTkWorkAreaId() {
166                    return tkWorkAreaId;
167            }
168            public void setTkWorkAreaId(String tkWorkAreaId) {
169                    this.tkWorkAreaId = tkWorkAreaId;
170            }
171    
172        public String getChart() {
173            return chart;
174        }
175    
176        public void setChart(String chart) {
177            this.chart = chart;
178        }
179    
180        /**
181         * This method supports maintenance and lookup pages.
182         */
183        public String getUserName() {
184            if (person == null) {
185                person = KimApiServiceLocator.getPersonService().getPerson(this.principalId);
186            }
187    
188            return (person != null) ? person.getName() : "";
189        }
190    
191            public void setPositionNumber(String positionNumber) {
192                    this.positionNumber = positionNumber;
193            }
194    
195            public String getPositionNumber() {
196                    return positionNumber;
197            }
198    
199            public Date getExpirationDate() {
200                    return expirationDate;
201            }
202    
203            public void setExpirationDate(Date expirationDate) {
204                    this.expirationDate = expirationDate;
205            }
206    
207            public void setPositionObj(Position positionObj) {
208                    this.positionObj = positionObj;
209            }
210    
211            public Position getPositionObj() {
212                    return positionObj;
213            }
214    
215            @Override
216            public String getUniqueKey() {
217                    return principalId + "_" + positionNumber != null ? positionNumber.toString() : "" +"_"+
218                                    roleName + "_" + workArea != null ? workArea.toString() : "" + "_" +
219                                    department + "_" + chart;
220            }
221    
222            @Override
223            public String getId() {
224                    return getHrRolesId();
225            }
226    
227            @Override
228            public void setId(String id) {
229                    setHrRolesId(id);
230            }
231    
232            public Location getLocationObj() {
233                    return locationObj;
234            }
235    
236            public void setLocationObj(Location locationObj) {
237                    this.locationObj = locationObj;
238            }
239    }