1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.pm.positiondepartment;
17
18 import org.apache.commons.lang.builder.EqualsBuilder;
19 import org.kuali.kpme.core.api.departmentaffiliation.service.DepartmentAffiliationService;
20 import org.kuali.kpme.core.department.DepartmentBo;
21 import org.kuali.kpme.core.departmentaffiliation.DepartmentAffiliationBo;
22 import org.kuali.kpme.core.groupkey.HrGroupKeyBo;
23 import org.kuali.kpme.core.service.HrServiceLocator;
24 import org.kuali.kpme.pm.api.positiondepartment.PositionDepartment;
25 import org.kuali.kpme.pm.api.positiondepartment.PositionDepartmentContract;
26 import org.kuali.kpme.pm.position.PositionBo;
27 import org.kuali.kpme.pm.position.PositionKeyedDerived;
28 import org.kuali.rice.core.api.mo.ModelObjectUtils;
29 import org.springframework.util.StringUtils;
30
31 import com.google.common.collect.ImmutableList;
32
33 public class PositionDepartmentBo extends PositionKeyedDerived implements PositionDepartmentContract {
34
35 static class KeyFields {
36 private static final String DEPARTMENT = "department";
37 final static String GROUP_KEY_CODE = "groupKeyCode";
38 }
39
40
41
42 public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
43 .add(KeyFields.DEPARTMENT)
44 .add(KeyFields.GROUP_KEY_CODE)
45 .build();
46
47 private static final long serialVersionUID = 1L;
48
49 private String pmPositionDeptId;
50 private String department;
51 private String deptAffl;
52
53 private DepartmentBo departmentObj;
54 private DepartmentAffiliationBo deptAfflObj;
55
56
57
58
59 public String getDeptAffl() {
60 return deptAffl;
61 }
62
63
64
65
66 public void setDeptAffl(String deptAffl) {
67 this.deptAffl = deptAffl;
68 }
69
70
71
72
73 public DepartmentAffiliationBo getDeptAfflObj() {
74
75 if (deptAfflObj == null) {
76 if (!StringUtils.isEmpty(deptAffl)) {
77 DepartmentAffiliationService pdaService = HrServiceLocator.getDepartmentAffiliationService();
78 deptAfflObj = DepartmentAffiliationBo.from(pdaService.getDepartmentAffiliationByType(deptAffl));
79 }
80 }
81
82 return deptAfflObj;
83 }
84
85
86
87
88 public void setDeptAfflObj(
89 DepartmentAffiliationBo deptAfflObj) {
90 this.deptAfflObj = deptAfflObj;
91 }
92
93
94
95
96 public String getPmPositionDeptId() {
97 return pmPositionDeptId;
98 }
99
100
101
102
103 public void setPmPositionDeptId(String pmPositionDeptId) {
104 this.pmPositionDeptId = pmPositionDeptId;
105 }
106
107
108
109
110 public String getDepartment() {
111 return department;
112 }
113
114
115
116
117 public void setDepartment(String department) {
118 this.department = department;
119 }
120
121
122
123
124 public DepartmentBo getDepartmentObj() {
125 return departmentObj;
126 }
127
128
129
130
131 public void setDepartmentObj(DepartmentBo departmentObj) {
132 this.departmentObj = departmentObj;
133 }
134
135 @Override
136 public boolean equals(Object obj) {
137 if (obj == null)
138 return false;
139 if (obj == this)
140 return true;
141 if (obj.getClass() != getClass())
142 return false;
143
144 PositionDepartmentBo rhs = (PositionDepartmentBo)obj;
145 return new EqualsBuilder()
146 .append(pmPositionDeptId,rhs.getPmPositionDeptId())
147 .append(groupKeyCode,rhs.getGroupKeyCode())
148 .append(department, rhs.getDepartment())
149 .append(deptAffl, rhs.getDeptAffl())
150 .append(hrPositionId, rhs.getHrPositionId())
151 .isEquals();
152
153 }
154
155 @Override
156 public String getId() {
157 return this.getPmPositionDeptId();
158 }
159
160 @Override
161 public void setId(String id) {
162 this.setPmPositionDeptId(id);
163 }
164
165 public static PositionDepartmentBo from(PositionDepartment im) {
166 if (im == null) {
167 return null;
168 }
169 PositionDepartmentBo pd = new PositionDepartmentBo();
170 pd.setPmPositionDeptId(im.getPmPositionDeptId());
171 pd.setDeptAfflObj(DepartmentAffiliationBo.from(im.getDeptAfflObj()));
172 pd.setGroupKeyCode(im.getGroupKeyCode());
173 pd.setGroupKey(HrGroupKeyBo.from(im.getGroupKey()));
174 pd.setDepartment(im.getDepartment());
175 pd.setDeptAffl(im.getDeptAffl());
176 pd.setHrPositionId(im.getHrPositionId());
177
178 pd.setVersionNumber(im.getVersionNumber());
179 pd.setObjectId(im.getObjectId());
180 return pd;
181 }
182
183 public static PositionDepartment to(PositionDepartmentBo bo) {
184 if (bo == null) {
185 return null;
186 }
187 return PositionDepartment.Builder.create(bo).build();
188 }
189
190 public static final ModelObjectUtils.Transformer<PositionDepartmentBo, PositionDepartment> toImmutable = new ModelObjectUtils.Transformer<PositionDepartmentBo, PositionDepartment>() {
191 public PositionDepartment transform(PositionDepartmentBo input) {
192 return PositionDepartmentBo.to(input);
193 };
194 };
195
196 public static final ModelObjectUtils.Transformer<PositionDepartment, PositionDepartmentBo> toBo = new ModelObjectUtils.Transformer<PositionDepartment, PositionDepartmentBo>() {
197 public PositionDepartmentBo transform(PositionDepartment input) {
198 return PositionDepartmentBo.from(input);
199 };
200 };
201 }