1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.location;
17
18 import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableMap;
20 import org.kuali.kpme.core.api.location.Location;
21 import org.kuali.kpme.core.api.location.LocationContract;
22 import org.kuali.kpme.core.bo.HrBusinessObject;
23 import org.kuali.kpme.core.role.location.LocationPrincipalRoleMemberBo;
24 import org.kuali.kpme.core.util.HrConstants;
25
26 import javax.persistence.Transient;
27 import java.sql.Timestamp;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 public class LocationBo extends HrBusinessObject implements LocationContract {
32
33 private static final String LOCATION = "location";
34
35 private static final long serialVersionUID = 9015089510044249197L;
36
37 public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
38 .add(LOCATION)
39 .build();
40 public static final String CACHE_NAME = HrConstants.CacheNamespace.NAMESPACE_PREFIX + "Location";
41
42 private String hrLocationId;
43 private String location;
44 private String timezone;
45 private String description;
46
47 @Override
48 public ImmutableMap<String, Object> getBusinessKeyValuesMap() {
49 return new ImmutableMap.Builder<String, Object>()
50 .put(LOCATION, this.getLocation())
51 .build();
52 }
53
54
55 @Transient
56 private List<LocationPrincipalRoleMemberBo> roleMembers = new ArrayList<LocationPrincipalRoleMemberBo>();
57
58 @Transient
59 private List<LocationPrincipalRoleMemberBo> inactiveRoleMembers = new ArrayList<LocationPrincipalRoleMemberBo>();
60
61 @Override
62 public String getUniqueKey() {
63 return location;
64 }
65
66 @Override
67 public String getId() {
68 return getHrLocationId();
69 }
70
71 @Override
72 public void setId(String id) {
73 setHrLocationId(id);
74 }
75
76 public String getHrLocationId() {
77 return hrLocationId;
78 }
79
80 public void setHrLocationId(String hrLocationId) {
81 this.hrLocationId = hrLocationId;
82 }
83
84 public String getLocation() {
85 return location;
86 }
87
88 public void setLocation(String location) {
89 this.location = location;
90 }
91
92 public String getTimezone() {
93 return timezone;
94 }
95
96 public void setTimezone(String timezone) {
97 this.timezone = timezone;
98 }
99
100 public String getDescription() {
101 return description;
102 }
103
104 public void setDescription(String description) {
105 this.description = description;
106 }
107
108 public List<LocationPrincipalRoleMemberBo> getRoleMembers() {
109 return roleMembers;
110 }
111
112 public void addRoleMember(LocationPrincipalRoleMemberBo roleMemberBo) {
113 roleMembers.add(roleMemberBo);
114 }
115
116 public void removeRoleMember(LocationPrincipalRoleMemberBo roleMemberBo) {
117 roleMembers.remove(roleMemberBo);
118 }
119
120 public void setRoleMembers(List<LocationPrincipalRoleMemberBo> roleMembers) {
121 this.roleMembers = roleMembers;
122 }
123
124 public List<LocationPrincipalRoleMemberBo> getInactiveRoleMembers() {
125 return inactiveRoleMembers;
126 }
127
128 public void addInactiveRoleMember(LocationPrincipalRoleMemberBo inactiveRoleMemberBo) {
129 inactiveRoleMembers.add(inactiveRoleMemberBo);
130 }
131
132 public void removeInactiveRoleMember(LocationPrincipalRoleMemberBo inactiveRoleMemberBo) {
133 inactiveRoleMembers.remove(inactiveRoleMemberBo);
134 }
135
136 public void setInactiveRoleMembers(List<LocationPrincipalRoleMemberBo> inactiveRoleMembers) {
137 this.inactiveRoleMembers = inactiveRoleMembers;
138 }
139
140 public static LocationBo from(Location im) {
141 if (im == null) {
142 return null;
143 }
144 LocationBo loc = new LocationBo();
145
146 loc.setLocation(im.getLocation());
147 loc.setHrLocationId(im.getHrLocationId());
148 loc.setTimezone(im.getTimezone());
149 loc.setDescription(im.getDescription());
150
151 loc.setEffectiveDate(im.getEffectiveLocalDate() == null ? null : im.getEffectiveLocalDate().toDate());
152 loc.setActive(im.isActive());
153 if (im.getCreateTime() != null) {
154 loc.setTimestamp(new Timestamp(im.getCreateTime().getMillis()));
155 }
156 loc.setUserPrincipalId(im.getUserPrincipalId());
157 loc.setVersionNumber(im.getVersionNumber());
158 loc.setObjectId(im.getObjectId());
159
160 return loc;
161 }
162
163 public static Location to(LocationBo bo) {
164 if (bo == null) {
165 return null;
166 }
167
168 return Location.Builder.create(bo).build();
169 }
170 }