1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.criteria.CriteriaLookupService; |
21 | |
import org.kuali.rice.core.api.criteria.GenericQueryResults; |
22 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
23 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
24 | |
import org.kuali.rice.core.api.exception.RiceIllegalStateException; |
25 | |
import org.kuali.rice.kim.api.identity.Type; |
26 | |
import org.kuali.rice.kim.api.identity.address.EntityAddress; |
27 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation; |
28 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationType; |
29 | |
import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship; |
30 | |
import org.kuali.rice.kim.api.identity.email.EntityEmail; |
31 | |
import org.kuali.rice.kim.api.identity.employment.EntityEmployment; |
32 | |
import org.kuali.rice.kim.api.identity.entity.Entity; |
33 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault; |
34 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults; |
35 | |
import org.kuali.rice.kim.api.identity.entity.EntityQueryResults; |
36 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier; |
37 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierType; |
38 | |
import org.kuali.rice.kim.api.identity.name.EntityName; |
39 | |
import org.kuali.rice.kim.api.identity.name.EntityNameQueryResults; |
40 | |
import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics; |
41 | |
import org.kuali.rice.kim.api.identity.personal.EntityEthnicity; |
42 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhone; |
43 | |
import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName; |
44 | |
import org.kuali.rice.kim.api.identity.principal.Principal; |
45 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences; |
46 | |
import org.kuali.rice.kim.api.identity.residency.EntityResidency; |
47 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeData; |
48 | |
import org.kuali.rice.kim.api.identity.visa.EntityVisa; |
49 | |
import org.kuali.rice.kim.api.services.IdentityService; |
50 | |
import org.kuali.rice.kim.impl.identity.EntityTypeBo; |
51 | |
import org.kuali.rice.kim.impl.identity.address.EntityAddressBo; |
52 | |
import org.kuali.rice.kim.impl.identity.address.EntityAddressTypeBo; |
53 | |
import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo; |
54 | |
import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationTypeBo; |
55 | |
import org.kuali.rice.kim.impl.identity.citizenship.EntityCitizenshipBo; |
56 | |
import org.kuali.rice.kim.impl.identity.citizenship.EntityCitizenshipStatusBo; |
57 | |
import org.kuali.rice.kim.impl.identity.email.EntityEmailBo; |
58 | |
import org.kuali.rice.kim.impl.identity.email.EntityEmailTypeBo; |
59 | |
import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo; |
60 | |
import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentStatusBo; |
61 | |
import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentTypeBo; |
62 | |
import org.kuali.rice.kim.impl.identity.entity.EntityBo; |
63 | |
import org.kuali.rice.kim.impl.identity.external.EntityExternalIdentifierBo; |
64 | |
import org.kuali.rice.kim.impl.identity.external.EntityExternalIdentifierTypeBo; |
65 | |
import org.kuali.rice.kim.impl.identity.name.EntityNameBo; |
66 | |
import org.kuali.rice.kim.impl.identity.name.EntityNameTypeBo; |
67 | |
import org.kuali.rice.kim.impl.identity.personal.EntityBioDemographicsBo; |
68 | |
import org.kuali.rice.kim.impl.identity.personal.EntityEthnicityBo; |
69 | |
import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo; |
70 | |
import org.kuali.rice.kim.impl.identity.phone.EntityPhoneTypeBo; |
71 | |
import org.kuali.rice.kim.impl.identity.principal.PrincipalBo; |
72 | |
import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo; |
73 | |
import org.kuali.rice.kim.impl.identity.residency.EntityResidencyBo; |
74 | |
import org.kuali.rice.kim.impl.identity.type.EntityTypeDataBo; |
75 | |
import org.kuali.rice.kim.impl.identity.visa.EntityVisaBo; |
76 | |
import org.kuali.rice.kim.service.IdentityUpdateService; |
77 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
78 | |
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
79 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
80 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
81 | |
|
82 | |
import javax.jws.WebService; |
83 | |
import java.util.ArrayList; |
84 | |
import java.util.Collection; |
85 | |
import java.util.Collections; |
86 | |
import java.util.HashMap; |
87 | |
import java.util.List; |
88 | |
import java.util.Map; |
89 | |
|
90 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.*; |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
@WebService(endpointInterface = KIMWebServiceConstants.IdentityService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.IdentityService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.IdentityService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
100 | 0 | public class IdentityServiceImpl implements IdentityService, IdentityUpdateService { |
101 | |
|
102 | |
private CriteriaLookupService criteriaLookupService; |
103 | |
private BusinessObjectService businessObjectService; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
public Entity getEntity(String entityId) { |
109 | 0 | EntityBo entity = getEntityBo( entityId ); |
110 | 0 | if ( entity == null ) { |
111 | 0 | return null; |
112 | |
} |
113 | 0 | return EntityBo.to( entity ); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public Entity getEntityByPrincipalId(String principalId) { |
120 | 0 | EntityBo entity = getEntityBoByPrincipalId(principalId); |
121 | 0 | if ( entity == null ) { |
122 | 0 | return null; |
123 | |
} |
124 | 0 | return EntityBo.to(entity); |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
public Entity getEntityByPrincipalName(String principalName) { |
131 | 0 | EntityBo entity = getEntityBoByPrincipalName(principalName); |
132 | 0 | if ( entity == null ) { |
133 | 0 | return null; |
134 | |
} |
135 | 0 | return EntityBo.to(entity); |
136 | |
} |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
public EntityDefault getEntityDefault(String entityId) { |
142 | 0 | EntityBo entity = getEntityBo( entityId ); |
143 | 0 | if ( entity == null ) { |
144 | 0 | return null; |
145 | |
} |
146 | 0 | return EntityBo.toDefault( entity ); |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public EntityDefault getEntityDefaultByPrincipalId(String principalId) { |
153 | 0 | EntityBo entity = getEntityBoByPrincipalId(principalId); |
154 | 0 | if ( entity == null ) { |
155 | 0 | return null; |
156 | |
} |
157 | 0 | return EntityBo.toDefault(entity); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public EntityDefault getEntityDefaultByPrincipalName(String principalName) { |
164 | 0 | EntityBo entity = getEntityBoByPrincipalName(principalName); |
165 | 0 | if ( entity == null ) { |
166 | 0 | return null; |
167 | |
} |
168 | 0 | return EntityBo.toDefault(entity); |
169 | |
} |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
@SuppressWarnings("unchecked") |
175 | |
public Principal getPrincipalByPrincipalNameAndPassword(String principalName, String password) { |
176 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(3); |
177 | 0 | criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName); |
178 | 0 | criteria.put(KIMPropertyConstants.Principal.PASSWORD, password); |
179 | 0 | criteria.put(KIMPropertyConstants.Principal.ACTIVE, true); |
180 | 0 | Collection<PrincipalBo> principals = businessObjectService.findMatching(PrincipalBo.class, criteria); |
181 | |
|
182 | 0 | if (!principals.isEmpty()) { |
183 | 0 | return PrincipalBo.to(principals.iterator().next()); |
184 | |
} |
185 | 0 | return null; |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
public Principal addPrincipalToEntity(Principal principal) { |
190 | 0 | if (principal == null) { |
191 | 0 | throw new RiceIllegalArgumentException("principal is null"); |
192 | |
} |
193 | |
|
194 | 0 | if (StringUtils.isEmpty(principal.getEntityId()) || StringUtils.isBlank(principal.getEntityId()) |
195 | |
|| StringUtils.isEmpty(principal.getPrincipalName()) || StringUtils.isBlank(principal.getPrincipalName())) { |
196 | 0 | throw new RiceIllegalStateException("Principal's entityId and PrincipalName must be populated before creation"); |
197 | |
} else { |
198 | 0 | if (getPrincipalByPrincipalName(principal.getPrincipalName()) != null) { |
199 | 0 | throw new RiceIllegalStateException("the Principal to create already exists: " + principal); |
200 | |
} |
201 | |
} |
202 | 0 | PrincipalBo bo = PrincipalBo.from(principal); |
203 | 0 | return PrincipalBo.to(businessObjectService.save(bo)); |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public Principal updatePrincipal(Principal principal) { |
208 | 0 | if (principal == null) { |
209 | 0 | throw new RiceIllegalArgumentException("principal is null"); |
210 | |
} |
211 | |
|
212 | 0 | if (StringUtils.isEmpty(principal.getEntityId()) || StringUtils.isBlank(principal.getEntityId()) |
213 | |
|| StringUtils.isEmpty(principal.getPrincipalName()) || StringUtils.isBlank(principal.getPrincipalName())) { |
214 | 0 | throw new RiceIllegalStateException("Principal's entityId and PrincipalName must be populated before update"); |
215 | |
} else { |
216 | 0 | if (StringUtils.isEmpty(principal.getPrincipalId()) || |
217 | |
getPrincipalByPrincipalName(principal.getPrincipalName()) == null) { |
218 | 0 | throw new RiceIllegalStateException("the Principal to update does not exist: " + principal); |
219 | |
} |
220 | |
} |
221 | 0 | PrincipalBo bo = PrincipalBo.from(principal); |
222 | 0 | return PrincipalBo.to(businessObjectService.save(bo)); |
223 | |
} |
224 | |
|
225 | |
@Override |
226 | |
public Principal inactivatePrincipal(String principalId) { |
227 | 0 | Principal principal = getPrincipal(principalId); |
228 | 0 | if (principal == null) { |
229 | 0 | throw new RiceIllegalStateException("Principal with principalId: " + principalId + " does not exist"); |
230 | |
} |
231 | 0 | PrincipalBo bo = PrincipalBo.from(principal); |
232 | 0 | bo.setActive(false); |
233 | 0 | return PrincipalBo.to(businessObjectService.save(bo)); |
234 | |
} |
235 | |
|
236 | |
@Override |
237 | |
public Principal inactivatePrincipalByName(String principalName) { |
238 | 0 | Principal principal = getPrincipalByPrincipalName(principalName); |
239 | 0 | if (principal == null) { |
240 | 0 | throw new RiceIllegalStateException("Principal with principalName: " + principalName + " does not exist"); |
241 | |
} |
242 | 0 | PrincipalBo bo = PrincipalBo.from(principal); |
243 | 0 | bo.setActive(false); |
244 | 0 | return PrincipalBo.to(businessObjectService.save(bo)); |
245 | |
} |
246 | |
|
247 | |
@Override |
248 | |
public EntityTypeData addEntityTypeDataToEntity(EntityTypeData entityTypeData) { |
249 | 0 | if (entityTypeData == null) { |
250 | 0 | throw new RiceIllegalArgumentException("entityTypeData is null"); |
251 | |
} |
252 | |
|
253 | 0 | if (StringUtils.isEmpty(entityTypeData.getEntityId()) || StringUtils.isBlank(entityTypeData.getEntityId()) |
254 | |
|| StringUtils.isEmpty(entityTypeData.getEntityTypeCode()) || StringUtils.isBlank(entityTypeData.getEntityTypeCode())) { |
255 | 0 | throw new RiceIllegalStateException("EntityTypeData's entityId and entityTypeCode must be populated before creation"); |
256 | |
} else { |
257 | 0 | if (getEntityTypeDataBo(entityTypeData.getEntityId(), entityTypeData.getEntityTypeCode()) != null) { |
258 | 0 | throw new RiceIllegalStateException("the entityTypeData to create already exists: " + entityTypeData); |
259 | |
} |
260 | |
} |
261 | 0 | EntityTypeDataBo bo = EntityTypeDataBo.from(entityTypeData); |
262 | 0 | return EntityTypeDataBo.to(businessObjectService.save(bo)); |
263 | |
} |
264 | |
|
265 | |
private EntityTypeDataBo getEntityTypeDataBo(String entityId, String entityTypeCode) { |
266 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(3); |
267 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
268 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_TYPE_CODE, entityTypeCode); |
269 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
270 | 0 | return businessObjectService.findByPrimaryKey(EntityTypeDataBo.class, criteria); |
271 | |
} |
272 | |
|
273 | |
@Override |
274 | |
public EntityTypeData updateEntityTypeData(EntityTypeData entityTypeData) { |
275 | 0 | if (entityTypeData == null) { |
276 | 0 | throw new RiceIllegalArgumentException("entityTypeData is null"); |
277 | |
} |
278 | |
|
279 | 0 | if (StringUtils.isBlank(entityTypeData.getEntityId()) || StringUtils.isEmpty(entityTypeData.getEntityId()) |
280 | |
|| StringUtils.isBlank(entityTypeData.getEntityTypeCode()) || StringUtils.isEmpty(entityTypeData.getEntityTypeCode())) { |
281 | 0 | throw new RiceIllegalStateException("EntityTypeData's entityId and entityTypeCode must be populated before update"); |
282 | |
} else { |
283 | 0 | if (getEntityTypeDataBo(entityTypeData.getEntityId(), entityTypeData.getEntityTypeCode()) == null) { |
284 | 0 | throw new RiceIllegalStateException("the entityTypeData to update does not exist: " + entityTypeData); |
285 | |
} |
286 | |
} |
287 | 0 | EntityTypeDataBo bo = EntityTypeDataBo.from(entityTypeData); |
288 | 0 | return EntityTypeDataBo.to(businessObjectService.save(bo)); |
289 | |
} |
290 | |
|
291 | |
@Override |
292 | |
public EntityTypeData inactivateEntityTypeData(String entityId, String entityTypeCode) { |
293 | 0 | EntityTypeDataBo bo = getEntityTypeDataBo(entityId, entityTypeCode); |
294 | 0 | if (bo == null) { |
295 | 0 | throw new RiceIllegalStateException("EntityTypeData with entityId: " + entityId + " entityTypeCode: " + entityTypeCode + " does not exist"); |
296 | |
} |
297 | 0 | bo.setActive(false); |
298 | 0 | return EntityTypeDataBo.to(businessObjectService.save(bo)); |
299 | |
} |
300 | |
|
301 | |
private EntityAddressBo getEntityAddressBo(String entityId, String entityTypeCode, String addressTypeCode) { |
302 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
303 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
304 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_TYPE_CODE, entityTypeCode); |
305 | 0 | criteria.put("addressTypeCode", addressTypeCode); |
306 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
307 | 0 | return businessObjectService.findByPrimaryKey(EntityAddressBo.class, criteria); |
308 | |
} |
309 | |
|
310 | |
private EntityAddressBo getEntityAddressBo(String addressId) { |
311 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
312 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, addressId); |
313 | 0 | return businessObjectService.findByPrimaryKey(EntityAddressBo.class, criteria); |
314 | |
} |
315 | |
|
316 | |
@Override |
317 | |
public EntityAddress addAddressToEntity(EntityAddress address) { |
318 | 0 | if (address == null) { |
319 | 0 | throw new RiceIllegalArgumentException("address is null"); |
320 | |
} |
321 | |
|
322 | 0 | if (StringUtils.isEmpty(address.getEntityId()) || StringUtils.isBlank(address.getEntityId()) |
323 | |
|| StringUtils.isEmpty(address.getEntityTypeCode()) || StringUtils.isBlank(address.getEntityTypeCode())) { |
324 | 0 | throw new RiceIllegalStateException("Address's entityId and entityTypeCode must be populated before creation"); |
325 | |
} else { |
326 | 0 | if (address.getAddressType() == null) { |
327 | 0 | throw new RiceIllegalStateException("Address's type must be populated before creation"); |
328 | |
} |
329 | 0 | if (getEntityAddressBo(address.getEntityId(), address.getEntityTypeCode(), address.getAddressType().getCode()) != null) { |
330 | 0 | throw new RiceIllegalStateException("the address to create already exists: " + address); |
331 | |
} |
332 | |
} |
333 | 0 | EntityAddressBo bo = EntityAddressBo.from(address); |
334 | 0 | return EntityAddressBo.to(businessObjectService.save(bo)); |
335 | |
} |
336 | |
|
337 | |
@Override |
338 | |
public EntityAddress updateAddress(EntityAddress address) { |
339 | 0 | if (address == null) { |
340 | 0 | throw new RiceIllegalArgumentException("address is null"); |
341 | |
} |
342 | |
|
343 | 0 | if (StringUtils.isEmpty(address.getEntityId()) || StringUtils.isBlank(address.getEntityId()) |
344 | |
|| StringUtils.isEmpty(address.getEntityTypeCode()) || StringUtils.isBlank(address.getEntityTypeCode())) { |
345 | 0 | throw new RiceIllegalStateException("Address's entityId and entityTypeCode must be populated before creation"); |
346 | |
} else { |
347 | 0 | if (address.getAddressType() == null) { |
348 | 0 | throw new RiceIllegalStateException("Address's type must be populated before creation"); |
349 | |
} |
350 | 0 | if (StringUtils.isEmpty(address.getId()) |
351 | |
|| getEntityAddressBo(address.getEntityId(), address.getEntityTypeCode(), address.getAddressType().getCode()) == null) { |
352 | 0 | throw new RiceIllegalStateException("the address to update does not exists: " + address); |
353 | |
} |
354 | |
} |
355 | 0 | EntityAddressBo bo = EntityAddressBo.from(address); |
356 | 0 | return EntityAddressBo.to(businessObjectService.save(bo)); |
357 | |
} |
358 | |
|
359 | |
@Override |
360 | |
public EntityAddress inactivateAddress(String addressId) { |
361 | 0 | EntityAddressBo bo = getEntityAddressBo(addressId); |
362 | 0 | if (bo == null) { |
363 | 0 | throw new RiceIllegalStateException("Address with addressId: " + addressId + " does not exist"); |
364 | |
} |
365 | 0 | bo.setActive(false); |
366 | 0 | return EntityAddressBo.to(businessObjectService.save(bo)); |
367 | |
} |
368 | |
|
369 | |
private EntityEmailBo getEntityEmailBo(String entityId, String entityTypeCode, String emailTypeCode) { |
370 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
371 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
372 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_TYPE_CODE, entityTypeCode); |
373 | 0 | criteria.put("emailTypeCode", emailTypeCode); |
374 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
375 | 0 | return businessObjectService.findByPrimaryKey(EntityEmailBo.class, criteria); |
376 | |
} |
377 | |
|
378 | |
private EntityEmailBo getEntityEmailBo(String emailId) { |
379 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
380 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, emailId); |
381 | 0 | return businessObjectService.findByPrimaryKey(EntityEmailBo.class, criteria); |
382 | |
} |
383 | |
@Override |
384 | |
public EntityEmail addEmailToEntity(EntityEmail email) { |
385 | 0 | if (email == null) { |
386 | 0 | throw new RiceIllegalArgumentException("email is null"); |
387 | |
} |
388 | |
|
389 | 0 | if (StringUtils.isEmpty(email.getEntityId()) || StringUtils.isBlank(email.getEntityId()) |
390 | |
|| StringUtils.isEmpty(email.getEntityTypeCode()) || StringUtils.isBlank(email.getEntityTypeCode())) { |
391 | 0 | throw new RiceIllegalStateException("Email's entityId and entityTypeCode must be populated before creation"); |
392 | |
} else { |
393 | 0 | if (email.getEmailType() == null) { |
394 | 0 | throw new RiceIllegalStateException("Email's type must be populated before creation"); |
395 | |
} |
396 | 0 | if (getEntityEmailBo(email.getEntityId(), email.getEntityTypeCode(), email.getEmailType().getCode()) != null) { |
397 | 0 | throw new RiceIllegalStateException("the email to create already exists: " + email); |
398 | |
} |
399 | |
} |
400 | 0 | EntityEmailBo bo = EntityEmailBo.from(email); |
401 | 0 | return EntityEmailBo.to(businessObjectService.save(bo)); |
402 | |
} |
403 | |
|
404 | |
@Override |
405 | |
public EntityEmail updateEmail(EntityEmail email) { |
406 | 0 | if (email == null) { |
407 | 0 | throw new RiceIllegalArgumentException("email is null"); |
408 | |
} |
409 | |
|
410 | 0 | if (StringUtils.isEmpty(email.getEntityId()) || StringUtils.isBlank(email.getEntityId()) |
411 | |
|| StringUtils.isEmpty(email.getEntityTypeCode()) || StringUtils.isBlank(email.getEntityTypeCode())) { |
412 | 0 | throw new RiceIllegalStateException("Email's entityId and entityTypeCode must be populated before creation"); |
413 | |
} else { |
414 | 0 | if (email.getEmailType() == null) { |
415 | 0 | throw new RiceIllegalStateException("Email's type must be populated before creation"); |
416 | |
} |
417 | 0 | if (StringUtils.isEmpty(email.getId()) |
418 | |
|| getEntityEmailBo(email.getEntityId(), email.getEntityTypeCode(), email.getEmailType().getCode()) == null) { |
419 | 0 | throw new RiceIllegalStateException("the email to update does not exists: " + email); |
420 | |
} |
421 | |
} |
422 | 0 | EntityEmailBo bo = EntityEmailBo.from(email); |
423 | 0 | return EntityEmailBo.to(businessObjectService.save(bo)); |
424 | |
} |
425 | |
|
426 | |
@Override |
427 | |
public EntityEmail inactivateEmail(String emailId) { |
428 | 0 | EntityEmailBo bo = getEntityEmailBo(emailId); |
429 | 0 | if (bo == null) { |
430 | 0 | throw new RiceIllegalStateException("Email with emailId: " + emailId + " does not exist"); |
431 | |
} |
432 | 0 | bo.setActive(false); |
433 | 0 | return EntityEmailBo.to(businessObjectService.save(bo)); |
434 | |
} |
435 | |
|
436 | |
private EntityPhoneBo getEntityPhoneBo(String entityId, String entityTypeCode, String phoneTypeCode) { |
437 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
438 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
439 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_TYPE_CODE, entityTypeCode); |
440 | 0 | criteria.put("phoneTypeCode", phoneTypeCode); |
441 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
442 | 0 | return businessObjectService.findByPrimaryKey(EntityPhoneBo.class, criteria); |
443 | |
} |
444 | |
|
445 | |
private EntityPhoneBo getEntityPhoneBo(String phoneId) { |
446 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
447 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, phoneId); |
448 | 0 | return businessObjectService.findByPrimaryKey(EntityPhoneBo.class, criteria); |
449 | |
} |
450 | |
|
451 | |
@Override |
452 | |
public EntityPhone addPhoneToEntity(EntityPhone phone) { |
453 | 0 | if (phone == null) { |
454 | 0 | throw new RiceIllegalArgumentException("phone is null"); |
455 | |
} |
456 | |
|
457 | 0 | if (StringUtils.isEmpty(phone.getEntityId()) || StringUtils.isBlank(phone.getEntityId()) |
458 | |
|| StringUtils.isEmpty(phone.getEntityTypeCode()) || StringUtils.isBlank(phone.getEntityTypeCode())) { |
459 | 0 | throw new RiceIllegalStateException("Phone's entityId and entityTypeCode must be populated before creation"); |
460 | |
} else { |
461 | 0 | if (phone.getPhoneType() == null) { |
462 | 0 | throw new RiceIllegalStateException("Phone's type must be populated before creation"); |
463 | |
} |
464 | 0 | if (getEntityPhoneBo(phone.getEntityId(), phone.getEntityTypeCode(), phone.getPhoneType().getCode()) != null) { |
465 | 0 | throw new RiceIllegalStateException("the phone to create already exists: " + phone); |
466 | |
} |
467 | |
} |
468 | 0 | EntityPhoneBo bo = EntityPhoneBo.from(phone); |
469 | 0 | return EntityPhoneBo.to(businessObjectService.save(bo)); |
470 | |
} |
471 | |
|
472 | |
@Override |
473 | |
public EntityPhone updatePhone(EntityPhone phone) { |
474 | 0 | if (phone == null) { |
475 | 0 | throw new RiceIllegalArgumentException("phone is null"); |
476 | |
} |
477 | |
|
478 | 0 | if (StringUtils.isEmpty(phone.getEntityId()) || StringUtils.isBlank(phone.getEntityId()) |
479 | |
|| StringUtils.isEmpty(phone.getEntityTypeCode()) || StringUtils.isBlank(phone.getEntityTypeCode())) { |
480 | 0 | throw new RiceIllegalStateException("Phone's entityId and entityTypeCode must be populated before creation"); |
481 | |
} else { |
482 | 0 | if (phone.getPhoneType() == null) { |
483 | 0 | throw new RiceIllegalStateException("Phone's type must be populated before creation"); |
484 | |
} |
485 | 0 | if (StringUtils.isEmpty(phone.getId()) |
486 | |
|| getEntityPhoneBo(phone.getEntityId(), phone.getEntityTypeCode(), phone.getPhoneType().getCode()) == null) { |
487 | 0 | throw new RiceIllegalStateException("the phone to update does not exists: " + phone); |
488 | |
} |
489 | |
} |
490 | 0 | EntityPhoneBo bo = EntityPhoneBo.from(phone); |
491 | 0 | return EntityPhoneBo.to(businessObjectService.save(bo)); |
492 | |
} |
493 | |
|
494 | |
@Override |
495 | |
public EntityPhone inactivatePhone(String phoneId) { |
496 | 0 | EntityPhoneBo bo = getEntityPhoneBo(phoneId); |
497 | 0 | if (bo == null) { |
498 | 0 | throw new RiceIllegalStateException("Phone with phoneId: " + phoneId + " does not exist"); |
499 | |
} |
500 | 0 | bo.setActive(false); |
501 | 0 | return EntityPhoneBo.to(businessObjectService.save(bo)); |
502 | |
} |
503 | |
|
504 | |
|
505 | |
private EntityExternalIdentifierBo getEntityExternalIdentifierBo(String entityId, String externalIdentifierTypeCode) { |
506 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
507 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
508 | 0 | criteria.put("externalIdentifierTypeCode", externalIdentifierTypeCode); |
509 | 0 | return businessObjectService.findByPrimaryKey(EntityExternalIdentifierBo.class, criteria); |
510 | |
} |
511 | |
|
512 | |
@Override |
513 | |
public EntityExternalIdentifier addExternalIdentifierToEntity(EntityExternalIdentifier externalId) { |
514 | 0 | if (externalId == null) { |
515 | 0 | throw new RiceIllegalArgumentException("externalId is null"); |
516 | |
} |
517 | |
|
518 | 0 | if (StringUtils.isEmpty(externalId.getEntityId()) || StringUtils.isBlank(externalId.getEntityId()) |
519 | |
|| StringUtils.isEmpty(externalId.getExternalIdentifierTypeCode()) || StringUtils.isBlank(externalId.getExternalIdentifierTypeCode())) { |
520 | 0 | throw new RiceIllegalStateException("EntityExternalIdentifier's entityId and entityTypeCode must be populated before creation"); |
521 | |
} else { |
522 | 0 | if (getEntityExternalIdentifierBo(externalId.getEntityId(), externalId.getExternalIdentifierTypeCode()) != null) { |
523 | 0 | throw new RiceIllegalStateException("the EntityExternalIdentifier to create already exists: " + externalId); |
524 | |
} |
525 | |
} |
526 | 0 | EntityExternalIdentifierBo bo = EntityExternalIdentifierBo.from(externalId); |
527 | 0 | return EntityExternalIdentifierBo.to(businessObjectService.save(bo)); |
528 | |
} |
529 | |
|
530 | |
@Override |
531 | |
public EntityExternalIdentifier updateExternalIdentifier(EntityExternalIdentifier externalId) { |
532 | 0 | if (externalId == null) { |
533 | 0 | throw new RiceIllegalArgumentException("externalId is null"); |
534 | |
} |
535 | |
|
536 | 0 | if (StringUtils.isEmpty(externalId.getEntityId()) || StringUtils.isBlank(externalId.getEntityId()) |
537 | |
|| StringUtils.isEmpty(externalId.getExternalIdentifierTypeCode()) || StringUtils.isBlank(externalId.getExternalIdentifierTypeCode())) { |
538 | 0 | throw new RiceIllegalStateException("EntityExternalIdentifier's entityId and externalIdentifierTypeCode must be populated before creation"); |
539 | |
} else { |
540 | 0 | if (StringUtils.isEmpty(externalId.getId()) |
541 | |
|| getEntityExternalIdentifierBo(externalId.getEntityId(), externalId.getExternalIdentifierTypeCode()) == null) { |
542 | 0 | throw new RiceIllegalStateException("the external identifier to update does not exist: " + externalId); |
543 | |
} |
544 | |
} |
545 | 0 | EntityExternalIdentifierBo bo = EntityExternalIdentifierBo.from(externalId); |
546 | 0 | return EntityExternalIdentifierBo.to(businessObjectService.save(bo)); |
547 | |
} |
548 | |
|
549 | |
|
550 | |
private EntityAffiliationBo getEntityAffiliationBo(String id) { |
551 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
552 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, id); |
553 | 0 | return businessObjectService.findByPrimaryKey(EntityAffiliationBo.class, criteria); |
554 | |
} |
555 | |
|
556 | |
@Override |
557 | |
public EntityAffiliation addAffiliationToEntity(EntityAffiliation affiliation) { |
558 | 0 | if (affiliation == null) { |
559 | 0 | throw new RiceIllegalArgumentException("affiliation is null"); |
560 | |
} |
561 | |
|
562 | 0 | if (StringUtils.isEmpty(affiliation.getEntityId()) || StringUtils.isBlank(affiliation.getEntityId())) { |
563 | 0 | throw new RiceIllegalStateException("Affiliation's entityId must be populated before creation"); |
564 | |
} else { |
565 | 0 | if (affiliation.getAffiliationType() == null) { |
566 | 0 | throw new RiceIllegalStateException("EntityAffiliation's type must be populated before creation"); |
567 | |
} |
568 | 0 | if (getEntityAffiliationBo(affiliation.getId()) != null) { |
569 | 0 | throw new RiceIllegalStateException("the EntityAffiliation to create already exists: " + affiliation); |
570 | |
} |
571 | |
} |
572 | 0 | EntityAffiliationBo bo = EntityAffiliationBo.from(affiliation); |
573 | 0 | return EntityAffiliationBo.to(businessObjectService.save(bo)); |
574 | |
} |
575 | |
|
576 | |
@Override |
577 | |
public EntityAffiliation updateAffiliation(EntityAffiliation affiliation) { |
578 | 0 | if (affiliation == null) { |
579 | 0 | throw new RiceIllegalArgumentException("affiliation is null"); |
580 | |
} |
581 | |
|
582 | 0 | if (StringUtils.isEmpty(affiliation.getEntityId()) || StringUtils.isBlank(affiliation.getEntityId())) { |
583 | 0 | throw new RiceIllegalStateException("Affiliation's entityId must be populated before creation"); |
584 | |
} else { |
585 | 0 | if (affiliation.getAffiliationType() == null) { |
586 | 0 | throw new RiceIllegalStateException("EntityAffiliation's type must be populated before creation"); |
587 | |
} |
588 | 0 | if (StringUtils.isEmpty(affiliation.getId()) |
589 | |
|| getEntityAffiliationBo(affiliation.getId()) == null) { |
590 | 0 | throw new RiceIllegalStateException("the EntityAffiliation to update already exists: " + affiliation); |
591 | |
} |
592 | |
} |
593 | 0 | EntityAffiliationBo bo = EntityAffiliationBo.from(affiliation); |
594 | 0 | return EntityAffiliationBo.to(businessObjectService.save(bo)); |
595 | |
} |
596 | |
|
597 | |
@Override |
598 | |
public EntityAffiliation inactivateAffiliation(String id) { |
599 | 0 | EntityAffiliationBo bo = getEntityAffiliationBo(id); |
600 | 0 | if (bo == null) { |
601 | 0 | throw new RiceIllegalStateException("EntityAffiliation with id: " + id + " does not exist"); |
602 | |
} |
603 | 0 | bo.setActive(false); |
604 | 0 | return EntityAffiliationBo.to(businessObjectService.save(bo)); |
605 | |
} |
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
@SuppressWarnings("unchecked") |
611 | |
public EntityQueryResults findEntities(QueryByCriteria queryByCriteria) { |
612 | 0 | if (queryByCriteria == null) { |
613 | 0 | throw new RiceIllegalArgumentException("queryByCriteria is null"); |
614 | |
} |
615 | |
|
616 | 0 | GenericQueryResults<EntityBo> results = criteriaLookupService.lookup(EntityBo.class, queryByCriteria); |
617 | |
|
618 | 0 | EntityQueryResults.Builder builder = EntityQueryResults.Builder.create(); |
619 | 0 | builder.setMoreResultsAvailable(results.isMoreResultsAvailable()); |
620 | 0 | builder.setTotalRowCount(results.getTotalRowCount()); |
621 | |
|
622 | 0 | final List<Entity.Builder> ims = new ArrayList<Entity.Builder>(); |
623 | 0 | for (EntityBo bo : results.getResults()) { |
624 | 0 | ims.add(Entity.Builder.create(bo)); |
625 | |
} |
626 | |
|
627 | 0 | builder.setResults(ims); |
628 | 0 | return builder.build(); |
629 | |
} |
630 | |
|
631 | |
|
632 | |
|
633 | |
@SuppressWarnings("unchecked") |
634 | |
public EntityDefaultQueryResults findEntityDefaults(QueryByCriteria queryByCriteria) { |
635 | 0 | if (queryByCriteria == null) { |
636 | 0 | throw new RiceIllegalArgumentException("queryByCriteria is null"); |
637 | |
} |
638 | |
|
639 | 0 | GenericQueryResults<EntityBo> results = criteriaLookupService.lookup(EntityBo.class, queryByCriteria); |
640 | |
|
641 | 0 | EntityDefaultQueryResults.Builder builder = EntityDefaultQueryResults.Builder.create(); |
642 | 0 | builder.setMoreResultsAvailable(results.isMoreResultsAvailable()); |
643 | 0 | builder.setTotalRowCount(results.getTotalRowCount()); |
644 | |
|
645 | 0 | final List<EntityDefault.Builder> ims = new ArrayList<EntityDefault.Builder>(); |
646 | 0 | for (EntityBo bo : results.getResults()) { |
647 | 0 | ims.add(EntityDefault.Builder.create(bo)); |
648 | |
} |
649 | |
|
650 | 0 | builder.setResults(ims); |
651 | 0 | return builder.build(); |
652 | |
} |
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
@SuppressWarnings("unchecked") |
658 | |
public EntityNameQueryResults findNames(QueryByCriteria queryByCriteria) { |
659 | 0 | if (queryByCriteria == null) { |
660 | 0 | throw new RiceIllegalArgumentException("queryByCriteria is null"); |
661 | |
} |
662 | |
|
663 | 0 | GenericQueryResults<EntityNameBo> results = criteriaLookupService.lookup(EntityNameBo.class, queryByCriteria); |
664 | |
|
665 | 0 | EntityNameQueryResults.Builder builder = EntityNameQueryResults.Builder.create(); |
666 | 0 | builder.setMoreResultsAvailable(results.isMoreResultsAvailable()); |
667 | 0 | builder.setTotalRowCount(results.getTotalRowCount()); |
668 | |
|
669 | 0 | final List<EntityName.Builder> ims = new ArrayList<EntityName.Builder>(); |
670 | 0 | for (EntityNameBo bo : results.getResults()) { |
671 | 0 | ims.add(EntityName.Builder.create(bo)); |
672 | |
} |
673 | |
|
674 | 0 | builder.setResults(ims); |
675 | 0 | return builder.build(); |
676 | |
} |
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
public EntityPrivacyPreferences getEntityPrivacyPreferences(String entityId) { |
682 | 0 | if (StringUtils.isEmpty(entityId)) { |
683 | 0 | return null; |
684 | |
} |
685 | 0 | Map<String,String> criteria = new HashMap<String,String>(1); |
686 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
687 | 0 | return EntityPrivacyPreferencesBo.to(businessObjectService.findByPrimaryKey(EntityPrivacyPreferencesBo.class, criteria)); |
688 | |
} |
689 | |
|
690 | |
|
691 | |
|
692 | |
|
693 | |
public Principal getPrincipal(String principalId) { |
694 | 0 | PrincipalBo principal = getPrincipalBo(principalId); |
695 | 0 | if ( principal == null ) { |
696 | 0 | return null; |
697 | |
} |
698 | 0 | return PrincipalBo.to(principal); |
699 | |
} |
700 | |
|
701 | |
private PrincipalBo getPrincipalBo(String principalId) { |
702 | 0 | Map<String,String> criteria = new HashMap<String,String>(1); |
703 | 0 | criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_ID, principalId); |
704 | 0 | return businessObjectService.findByPrimaryKey(PrincipalBo.class, criteria); |
705 | |
} |
706 | |
|
707 | |
private EntityBo getEntityBo(String entityId) { |
708 | 0 | EntityBo entityImpl = businessObjectService.findByPrimaryKey(EntityBo.class, Collections.singletonMap("id", entityId)); |
709 | 0 | if(entityImpl!=null) { |
710 | 0 | entityImpl.refresh(); |
711 | |
|
712 | |
|
713 | |
|
714 | |
|
715 | 0 | for (EntityTypeDataBo type : entityImpl.getEntityTypes()) { |
716 | 0 | type.refresh(); |
717 | 0 | for (EntityAddressBo addressBo : type.getAddresses()) { |
718 | 0 | addressBo.refreshReferenceObject("addressType"); |
719 | |
} |
720 | 0 | for (EntityEmailBo emailBo : type.getEmailAddresses()) { |
721 | 0 | emailBo.refreshReferenceObject("emailType"); |
722 | |
} |
723 | 0 | for (EntityPhoneBo phoneBo : type.getPhoneNumbers()) { |
724 | 0 | phoneBo.refreshReferenceObject("phoneType"); |
725 | |
} |
726 | |
} |
727 | 0 | for (EntityNameBo name : entityImpl.getNames()) { |
728 | 0 | name.refreshReferenceObject("nameType"); |
729 | |
} |
730 | |
} |
731 | 0 | return entityImpl; |
732 | |
} |
733 | |
|
734 | |
|
735 | |
|
736 | |
|
737 | |
@SuppressWarnings("unchecked") |
738 | |
protected List<EntityBo> lookupEntitys(Map<String, String> searchCriteria) { |
739 | 0 | return new ArrayList(KRADServiceLocatorWeb.getLookupService().findCollectionBySearchUnbounded( EntityBo.class, searchCriteria )); |
740 | |
} |
741 | |
|
742 | |
|
743 | |
|
744 | |
|
745 | |
public List<String> lookupEntityIds(Map<String,String> searchCriteria) { |
746 | 0 | List<EntityBo> entities = lookupEntitys( searchCriteria ); |
747 | 0 | List<String> entityIds = new ArrayList<String>( entities.size() ); |
748 | 0 | for ( EntityBo entity : entities ) { |
749 | 0 | entityIds.add( entity.getId() ); |
750 | |
} |
751 | 0 | return entityIds; |
752 | |
} |
753 | |
|
754 | |
|
755 | |
|
756 | |
|
757 | |
@SuppressWarnings("unchecked") |
758 | |
public Principal getPrincipalByPrincipalName(String principalName) { |
759 | 0 | if ( StringUtils.isBlank(principalName) ) { |
760 | 0 | return null; |
761 | |
} |
762 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(1); |
763 | 0 | criteria.put(KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName.toLowerCase()); |
764 | 0 | Collection<PrincipalBo> principals = businessObjectService.findMatching(PrincipalBo.class, criteria); |
765 | 0 | if (!principals.isEmpty() && principals.size() == 1) { |
766 | 0 | return PrincipalBo.to(principals.iterator().next()); |
767 | |
} |
768 | 0 | return null; |
769 | |
} |
770 | |
|
771 | |
|
772 | |
|
773 | |
|
774 | |
protected EntityBo getEntityBoByPrincipalName(String principalName) { |
775 | 0 | if ( StringUtils.isBlank( principalName ) ) { |
776 | 0 | return null; |
777 | |
} |
778 | 0 | return getEntityByKeyValue("principals." + KIMPropertyConstants.Principal.PRINCIPAL_NAME, principalName.toLowerCase()); |
779 | |
} |
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
protected EntityBo getEntityBoByPrincipalId(String principalId) { |
785 | 0 | if ( StringUtils.isBlank( principalId ) ) { |
786 | 0 | return null; |
787 | |
} |
788 | 0 | return getEntityByKeyValue("principals." + KIMPropertyConstants.Principal.PRINCIPAL_ID, principalId); |
789 | |
} |
790 | |
|
791 | |
|
792 | |
|
793 | |
|
794 | |
public String getEntityIdByPrincipalId(String principalId) { |
795 | 0 | if ( StringUtils.isBlank( principalId ) ) { |
796 | 0 | return null; |
797 | |
} |
798 | 0 | PrincipalBo principal = getPrincipalBo(principalId); |
799 | 0 | return principal != null ? principal.getEntityId() : null; |
800 | |
} |
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
public String getEntityIdByPrincipalName(String principalName) { |
806 | 0 | if ( StringUtils.isBlank( principalName ) ) { |
807 | 0 | return null; |
808 | |
} |
809 | 0 | Principal principal = getPrincipalByPrincipalName(principalName); |
810 | 0 | return principal != null ? principal.getEntityId() : null; |
811 | |
} |
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
public String getPrincipalIdByPrincipalName(String principalName) { |
817 | 0 | if ( StringUtils.isBlank( principalName ) ) { |
818 | 0 | return null; |
819 | |
} |
820 | 0 | Principal principal = getPrincipalByPrincipalName( principalName ); |
821 | 0 | return principal != null ? principal.getPrincipalId() : null; |
822 | |
} |
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
public Map<String, EntityNamePrincipalName> getDefaultNamesForEntityIds(List<String> entityIds) { |
828 | 0 | Map<String, EntityNamePrincipalName> result = new HashMap<String, EntityNamePrincipalName>(entityIds.size()); |
829 | |
|
830 | 0 | if (CollectionUtils.isEmpty(entityIds)) { |
831 | 0 | return result; |
832 | |
} |
833 | 0 | final QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
834 | 0 | builder.setPredicates(and(in("id", entityIds.toArray()), |
835 | |
equal("active", "Y"), |
836 | |
and( |
837 | |
equal("names.active", "Y"), |
838 | |
equal("names.defaultValue", "Y")))); |
839 | 0 | EntityDefaultQueryResults qr = findEntityDefaults(builder.build()); |
840 | 0 | for(EntityDefault entityDefault : qr.getResults()) { |
841 | |
|
842 | 0 | for (Principal principal : entityDefault.getPrincipals()) { |
843 | 0 | result.put(entityDefault.getEntityId(), EntityNamePrincipalName.Builder |
844 | |
.create(principal.getPrincipalName(), EntityName.Builder.create(entityDefault.getName())) |
845 | |
.build()); |
846 | 0 | break; |
847 | |
} |
848 | |
} |
849 | 0 | return result; |
850 | |
} |
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
|
857 | |
public Map<String, EntityNamePrincipalName> getDefaultNamesForPrincipalIds(List<String> principalIds) { |
858 | 0 | Map<String, EntityNamePrincipalName> result = new HashMap<String, EntityNamePrincipalName>(); |
859 | |
|
860 | 0 | QueryByCriteria.Builder qb = QueryByCriteria.Builder.create(); |
861 | 0 | qb.setPredicates(and(in("principals.principalId", principalIds.toArray()), |
862 | |
equal("active", "Y"), |
863 | |
equal("names.defaultValue", "Y"))); |
864 | |
|
865 | 0 | List<EntityDefault> entityDefaults = findEntityDefaults(qb.build()).getResults(); |
866 | 0 | for(EntityDefault entityDefault : entityDefaults) { |
867 | |
|
868 | 0 | for (Principal principal : entityDefault.getPrincipals()) { |
869 | 0 | result.put(principal.getPrincipalId(), EntityNamePrincipalName.Builder |
870 | |
.create(principal.getPrincipalName(), EntityName.Builder.create(entityDefault.getName())) |
871 | |
.build()); |
872 | |
} |
873 | |
} |
874 | |
|
875 | 0 | return result; |
876 | |
} |
877 | |
|
878 | |
|
879 | |
|
880 | |
|
881 | |
@SuppressWarnings("unchecked") |
882 | |
protected EntityBo getEntityByKeyValue(String key, String value) { |
883 | 0 | Map<String,String> criteria = new HashMap<String,String>(1); |
884 | 0 | criteria.put(key, value); |
885 | 0 | Collection<EntityBo> entities = businessObjectService.findMatching(EntityBo.class, criteria); |
886 | 0 | if (entities.size() >= 1) { |
887 | 0 | return entities.iterator().next(); |
888 | |
} |
889 | 0 | return null; |
890 | |
} |
891 | |
|
892 | |
public Type getAddressType( String code ) { |
893 | 0 | EntityAddressTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityAddressTypeBo.class, code); |
894 | 0 | if ( impl == null ) { |
895 | 0 | return null; |
896 | |
} |
897 | 0 | return EntityAddressTypeBo.to(impl); |
898 | |
} |
899 | |
|
900 | |
|
901 | |
|
902 | |
public EntityAffiliationType getAffiliationType( String code ) { |
903 | 0 | EntityAffiliationTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityAffiliationTypeBo.class, code); |
904 | 0 | if ( impl == null ) { |
905 | 0 | return null; |
906 | |
} |
907 | 0 | return EntityAffiliationTypeBo.to(impl); |
908 | |
} |
909 | |
|
910 | |
|
911 | |
public Type getCitizenshipStatus( String code ) { |
912 | 0 | EntityCitizenshipStatusBo impl = businessObjectService.findBySinglePrimaryKey(EntityCitizenshipStatusBo.class, code); |
913 | 0 | if ( impl == null ) { |
914 | 0 | return null; |
915 | |
} |
916 | 0 | return EntityCitizenshipStatusBo.to(impl); |
917 | |
} |
918 | |
|
919 | |
public Type getEmailType( String code ) { |
920 | 0 | EntityEmailTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityEmailTypeBo.class, code); |
921 | 0 | if ( impl == null ) { |
922 | 0 | return null; |
923 | |
} |
924 | 0 | return EntityEmailTypeBo.to(impl); |
925 | |
} |
926 | |
|
927 | |
public Type getEmploymentStatus( String code ) { |
928 | 0 | EntityEmploymentStatusBo impl = businessObjectService.findBySinglePrimaryKey(EntityEmploymentStatusBo.class, code); |
929 | 0 | if ( impl == null ) { |
930 | 0 | return null; |
931 | |
} |
932 | 0 | return EntityEmploymentStatusBo.to(impl); |
933 | |
} |
934 | |
|
935 | |
public Type getEmploymentType( String code ) { |
936 | 0 | EntityEmploymentTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityEmploymentTypeBo.class, code); |
937 | 0 | if ( impl == null ) { |
938 | 0 | return null; |
939 | |
} |
940 | 0 | return EntityEmploymentTypeBo.to(impl); |
941 | |
} |
942 | |
|
943 | |
public Type getNameType(String code) { |
944 | 0 | EntityNameTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityNameTypeBo.class, code); |
945 | 0 | if ( impl == null ) { |
946 | 0 | return null; |
947 | |
} |
948 | 0 | return EntityNameTypeBo.to(impl); |
949 | |
} |
950 | |
|
951 | |
public Type getEntityType( String code ) { |
952 | 0 | EntityTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityTypeBo.class, code); |
953 | 0 | if ( impl == null ) { |
954 | 0 | return null; |
955 | |
} |
956 | 0 | return EntityTypeBo.to(impl); |
957 | |
} |
958 | |
|
959 | |
public EntityExternalIdentifierType getExternalIdentifierType( String code ) { |
960 | 0 | EntityExternalIdentifierTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityExternalIdentifierTypeBo.class, code); |
961 | 0 | if ( impl == null ) { |
962 | 0 | return null; |
963 | |
} |
964 | 0 | return EntityExternalIdentifierTypeBo.to(impl); |
965 | |
} |
966 | |
|
967 | |
|
968 | |
|
969 | |
public Type getPhoneType( String code ) { |
970 | 0 | EntityPhoneTypeBo impl = businessObjectService.findBySinglePrimaryKey(EntityPhoneTypeBo.class, code); |
971 | 0 | if ( impl == null ) { |
972 | 0 | return null; |
973 | |
} |
974 | 0 | return EntityPhoneTypeBo.to(impl); |
975 | |
} |
976 | |
|
977 | |
@Override |
978 | |
public Entity createEntity(Entity entity) { |
979 | 0 | if (entity == null) { |
980 | 0 | throw new RiceIllegalArgumentException("entity is null"); |
981 | |
} |
982 | |
|
983 | 0 | if (StringUtils.isNotBlank(entity.getId()) && getEntity(entity.getId()) != null) { |
984 | 0 | throw new RiceIllegalStateException("the Entity to create already exists: " + entity); |
985 | |
} |
986 | |
|
987 | 0 | EntityBo bo = EntityBo.from(entity); |
988 | 0 | return EntityBo.to(businessObjectService.save(bo)); |
989 | |
} |
990 | |
|
991 | |
@Override |
992 | |
public Entity updateEntity(Entity entity) { |
993 | 0 | if (entity == null) { |
994 | 0 | throw new RiceIllegalArgumentException("entity is null"); |
995 | |
} |
996 | |
|
997 | 0 | if (StringUtils.isBlank(entity.getId()) || getEntity(entity.getId()) == null) { |
998 | 0 | throw new RiceIllegalStateException("the Entity does not exist: " + entity); |
999 | |
} |
1000 | |
|
1001 | 0 | EntityBo bo = EntityBo.from(entity); |
1002 | 0 | return EntityBo.to(businessObjectService.save(bo)); |
1003 | |
} |
1004 | |
|
1005 | |
@Override |
1006 | |
public Entity inactivateEntity(String entityId) { |
1007 | 0 | if (StringUtils.isEmpty(entityId)) { |
1008 | 0 | throw new RiceIllegalArgumentException("entityId is empty"); |
1009 | |
} |
1010 | |
|
1011 | 0 | Entity entity = getEntity(entityId); |
1012 | 0 | if (entity == null) { |
1013 | 0 | throw new RiceIllegalStateException("an Entity does not exist for entityId: " + entityId); |
1014 | |
} |
1015 | |
|
1016 | 0 | EntityBo bo = EntityBo.from(entity); |
1017 | 0 | bo.setActive(false); |
1018 | 0 | return EntityBo.to(businessObjectService.save(bo)); |
1019 | |
} |
1020 | |
|
1021 | |
@Override |
1022 | |
public EntityPrivacyPreferences addPrivacyPreferencesToEntity(EntityPrivacyPreferences privacyPreferences) { |
1023 | 0 | if (privacyPreferences == null) { |
1024 | 0 | throw new RiceIllegalArgumentException("privacyPreferences is null"); |
1025 | |
} |
1026 | |
|
1027 | 0 | if (StringUtils.isEmpty(privacyPreferences.getEntityId()) || StringUtils.isBlank(privacyPreferences.getEntityId())) { |
1028 | 0 | throw new RiceIllegalStateException("PrivacyPreferences' entityId must be populated before creation"); |
1029 | |
} else { |
1030 | 0 | if (getEntityPrivacyPreferences(privacyPreferences.getEntityId()) != null) { |
1031 | 0 | throw new RiceIllegalStateException("the PrivacyPreferences to create already exists: " + privacyPreferences); |
1032 | |
} |
1033 | |
} |
1034 | 0 | EntityPrivacyPreferencesBo bo = EntityPrivacyPreferencesBo.from(privacyPreferences); |
1035 | 0 | return EntityPrivacyPreferencesBo.to(businessObjectService.save(bo)); |
1036 | |
} |
1037 | |
|
1038 | |
@Override |
1039 | |
public EntityPrivacyPreferences updatePrivacyPreferences(EntityPrivacyPreferences privacyPreferences) { |
1040 | 0 | if (privacyPreferences == null) { |
1041 | 0 | throw new RiceIllegalArgumentException("privacyPreferences is null"); |
1042 | |
} |
1043 | |
|
1044 | 0 | if (StringUtils.isEmpty(privacyPreferences.getEntityId()) || StringUtils.isBlank(privacyPreferences.getEntityId())) { |
1045 | 0 | throw new RiceIllegalStateException("PrivacyPreferences' entityId must be populated before update"); |
1046 | |
} else { |
1047 | 0 | if (getEntityPrivacyPreferences(privacyPreferences.getEntityId()) == null) { |
1048 | 0 | throw new RiceIllegalStateException("the PrivacyPreferences to update does not exist: " + privacyPreferences); |
1049 | |
} |
1050 | |
} |
1051 | 0 | EntityPrivacyPreferencesBo bo = EntityPrivacyPreferencesBo.from(privacyPreferences); |
1052 | 0 | return EntityPrivacyPreferencesBo.to(businessObjectService.save(bo)); |
1053 | |
} |
1054 | |
|
1055 | |
private EntityCitizenshipBo getEntityCitizenshipBo(String entityId, String citizenshipStatusCode) { |
1056 | 0 | if (StringUtils.isEmpty(entityId) || StringUtils.isEmpty(citizenshipStatusCode)) { |
1057 | 0 | return null; |
1058 | |
} |
1059 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(4); |
1060 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
1061 | 0 | criteria.put("statusCode", citizenshipStatusCode); |
1062 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
1063 | 0 | return businessObjectService.findByPrimaryKey(EntityCitizenshipBo.class, criteria); |
1064 | |
} |
1065 | |
|
1066 | |
private EntityCitizenshipBo getEntityCitizenshipBo(String id) { |
1067 | 0 | if (StringUtils.isEmpty(id)) { |
1068 | 0 | return null; |
1069 | |
} |
1070 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1071 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, id); |
1072 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, true); |
1073 | 0 | return businessObjectService.findByPrimaryKey(EntityCitizenshipBo.class, criteria); |
1074 | |
} |
1075 | |
|
1076 | |
@Override |
1077 | |
public EntityCitizenship addCitizenshipToEntity(EntityCitizenship citizenship) { |
1078 | 0 | if (citizenship == null) { |
1079 | 0 | throw new RiceIllegalArgumentException("citizenship is null"); |
1080 | |
} |
1081 | |
|
1082 | 0 | if (StringUtils.isEmpty(citizenship.getEntityId()) || StringUtils.isBlank(citizenship.getEntityId())) { |
1083 | 0 | throw new RiceIllegalStateException("Citizenship's entityId must be populated before creation"); |
1084 | |
} else { |
1085 | 0 | if (citizenship.getStatus() == null) { |
1086 | 0 | throw new RiceIllegalStateException("Citizenship's status must be populated before creation"); |
1087 | |
} |
1088 | 0 | if (getEntityCitizenshipBo(citizenship.getEntityId(), citizenship.getStatus().getCode()) != null) { |
1089 | 0 | throw new RiceIllegalStateException("the EntityCitizenship to create already exists: " + citizenship); |
1090 | |
} |
1091 | |
} |
1092 | 0 | EntityCitizenshipBo bo = EntityCitizenshipBo.from(citizenship); |
1093 | 0 | return EntityCitizenshipBo.to(businessObjectService.save(bo)); |
1094 | |
} |
1095 | |
|
1096 | |
@Override |
1097 | |
public EntityCitizenship updateCitizenship(EntityCitizenship citizenship) { |
1098 | 0 | if (citizenship == null) { |
1099 | 0 | throw new RiceIllegalArgumentException("citizenship is null"); |
1100 | |
} |
1101 | |
|
1102 | 0 | if (StringUtils.isEmpty(citizenship.getEntityId()) || StringUtils.isBlank(citizenship.getEntityId())) { |
1103 | 0 | throw new RiceIllegalStateException("Email's entityId must be populated before creation"); |
1104 | |
} else { |
1105 | 0 | if (citizenship.getStatus() == null) { |
1106 | 0 | throw new RiceIllegalStateException("Citizenship's status must be populated before creation"); |
1107 | |
} |
1108 | 0 | if (getEntityCitizenshipBo(citizenship.getEntityId(), citizenship.getStatus().getCode()) == null) { |
1109 | 0 | throw new RiceIllegalStateException("the EntityCitizenship to update does not exist: " + citizenship); |
1110 | |
} |
1111 | |
} |
1112 | 0 | EntityCitizenshipBo bo = EntityCitizenshipBo.from(citizenship); |
1113 | 0 | return EntityCitizenshipBo.to(businessObjectService.save(bo)); |
1114 | |
} |
1115 | |
|
1116 | |
@Override |
1117 | |
public EntityCitizenship inactivateCitizenship(String id) { |
1118 | 0 | if (StringUtils.isEmpty(id)) { |
1119 | 0 | throw new RiceIllegalArgumentException("id is empty"); |
1120 | |
} |
1121 | |
|
1122 | 0 | EntityCitizenshipBo bo = getEntityCitizenshipBo(id); |
1123 | 0 | if (bo == null) { |
1124 | 0 | throw new RiceIllegalStateException("the EntityCitizenship with id: " + id + " does not exist"); |
1125 | |
} |
1126 | 0 | bo.setActive(false); |
1127 | 0 | return EntityCitizenshipBo.to(businessObjectService.save(bo)); |
1128 | |
} |
1129 | |
|
1130 | |
private EntityEthnicityBo getEntityEthnicityBo(String ethnicityId) { |
1131 | 0 | if (StringUtils.isEmpty(ethnicityId)) { |
1132 | 0 | return null; |
1133 | |
} |
1134 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1135 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, ethnicityId); |
1136 | 0 | return businessObjectService.findByPrimaryKey(EntityEthnicityBo.class, criteria); |
1137 | |
} |
1138 | |
@Override |
1139 | |
public EntityEthnicity addEthnicityToEntity(EntityEthnicity ethnicity) { |
1140 | 0 | if (ethnicity == null) { |
1141 | 0 | throw new RiceIllegalArgumentException("ethnicity is null"); |
1142 | |
} |
1143 | |
|
1144 | 0 | if (StringUtils.isEmpty(ethnicity.getEntityId()) || StringUtils.isBlank(ethnicity.getEntityId())) { |
1145 | 0 | throw new RiceIllegalStateException("Ethnicity's entityId must be populated before creation"); |
1146 | |
} else { |
1147 | 0 | if (StringUtils.isNotEmpty(ethnicity.getId()) && getEntityEthnicityBo(ethnicity.getId()) != null) { |
1148 | 0 | throw new RiceIllegalStateException("the EntityEthnicity to create already exists: " + ethnicity); |
1149 | |
} |
1150 | |
} |
1151 | 0 | EntityEthnicityBo bo = EntityEthnicityBo.from(ethnicity); |
1152 | 0 | return EntityEthnicityBo.to(businessObjectService.save(bo)); |
1153 | |
} |
1154 | |
|
1155 | |
@Override |
1156 | |
public EntityEthnicity updateEthnicity(EntityEthnicity ethnicity) { |
1157 | 0 | if (ethnicity == null) { |
1158 | 0 | throw new RiceIllegalArgumentException("ethnicity is null"); |
1159 | |
} |
1160 | |
|
1161 | 0 | if (StringUtils.isEmpty(ethnicity.getEntityId()) || StringUtils.isBlank(ethnicity.getEntityId())) { |
1162 | 0 | throw new RiceIllegalStateException("Ethnicity's entityId must be populated before creation"); |
1163 | |
} else { |
1164 | 0 | if (StringUtils.isEmpty(ethnicity.getId()) || getEntityEthnicityBo(ethnicity.getId()) == null) { |
1165 | 0 | throw new RiceIllegalStateException("the EntityEthnicity to update does not exist: " + ethnicity); |
1166 | |
} |
1167 | |
} |
1168 | 0 | EntityEthnicityBo bo = EntityEthnicityBo.from(ethnicity); |
1169 | 0 | return EntityEthnicityBo.to(businessObjectService.save(bo)); |
1170 | |
} |
1171 | |
|
1172 | |
private EntityResidencyBo getEntityResidencyBo(String residencyId) { |
1173 | 0 | if (StringUtils.isEmpty(residencyId)) { |
1174 | 0 | return null; |
1175 | |
} |
1176 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1177 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, residencyId); |
1178 | 0 | return businessObjectService.findByPrimaryKey(EntityResidencyBo.class, criteria); |
1179 | |
} |
1180 | |
@Override |
1181 | |
public EntityResidency addResidencyToEntity(EntityResidency residency) { |
1182 | 0 | if (residency == null) { |
1183 | 0 | throw new RiceIllegalArgumentException("residency is null"); |
1184 | |
} |
1185 | |
|
1186 | 0 | if (StringUtils.isEmpty(residency.getEntityId()) || StringUtils.isBlank(residency.getEntityId())) { |
1187 | 0 | throw new RiceIllegalStateException("Residency's entityId must be populated before creation"); |
1188 | |
} else { |
1189 | 0 | if (StringUtils.isNotEmpty(residency.getId()) && getEntityResidencyBo(residency.getId()) != null) { |
1190 | 0 | throw new RiceIllegalStateException("the EntityResidency to create already exists: " + residency); |
1191 | |
} |
1192 | |
} |
1193 | 0 | EntityResidencyBo bo = EntityResidencyBo.from(residency); |
1194 | 0 | return EntityResidencyBo.to(businessObjectService.save(bo)); |
1195 | |
} |
1196 | |
|
1197 | |
@Override |
1198 | |
public EntityResidency updateResidency(EntityResidency residency) { |
1199 | 0 | if (residency == null) { |
1200 | 0 | throw new RiceIllegalArgumentException("residency is null"); |
1201 | |
} |
1202 | |
|
1203 | 0 | if (StringUtils.isEmpty(residency.getEntityId()) || StringUtils.isBlank(residency.getEntityId())) { |
1204 | 0 | throw new RiceIllegalStateException("Residency's entityId must be populated before creation"); |
1205 | |
} else { |
1206 | 0 | if (StringUtils.isEmpty(residency.getId()) || getEntityResidencyBo(residency.getId()) == null) { |
1207 | 0 | throw new RiceIllegalStateException("the EntityResidency to update does not exist: " + residency); |
1208 | |
} |
1209 | |
} |
1210 | 0 | EntityResidencyBo bo = EntityResidencyBo.from(residency); |
1211 | 0 | return EntityResidencyBo.to(businessObjectService.save(bo)); |
1212 | |
} |
1213 | |
|
1214 | |
private EntityVisaBo getEntityVisaBo(String visaId) { |
1215 | 0 | if (StringUtils.isEmpty(visaId)) { |
1216 | 0 | return null; |
1217 | |
} |
1218 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1219 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, visaId); |
1220 | 0 | return businessObjectService.findByPrimaryKey(EntityVisaBo.class, criteria); |
1221 | |
} |
1222 | |
@Override |
1223 | |
public EntityVisa addVisaToEntity(EntityVisa visa) { |
1224 | 0 | if (visa == null) { |
1225 | 0 | throw new RiceIllegalArgumentException("visa is null"); |
1226 | |
} |
1227 | |
|
1228 | 0 | if (StringUtils.isEmpty(visa.getEntityId()) || StringUtils.isBlank(visa.getEntityId())) { |
1229 | 0 | throw new RiceIllegalStateException("Visa's entityId must be populated before creation"); |
1230 | |
} else { |
1231 | 0 | if (StringUtils.isNotEmpty(visa.getId()) && getEntityVisaBo(visa.getId()) != null) { |
1232 | 0 | throw new RiceIllegalStateException("the EntityVisa to create already exists: " + visa); |
1233 | |
} |
1234 | |
} |
1235 | 0 | EntityVisaBo bo = EntityVisaBo.from(visa); |
1236 | 0 | return EntityVisaBo.to(businessObjectService.save(bo)); |
1237 | |
} |
1238 | |
|
1239 | |
@Override |
1240 | |
public EntityVisa updateVisa(EntityVisa visa) { |
1241 | 0 | if (visa == null) { |
1242 | 0 | throw new RiceIllegalArgumentException("visa is null"); |
1243 | |
} |
1244 | |
|
1245 | 0 | if (StringUtils.isEmpty(visa.getEntityId()) || StringUtils.isBlank(visa.getEntityId())) { |
1246 | 0 | throw new RiceIllegalStateException("Visa's entityId must be populated before creation"); |
1247 | |
} else { |
1248 | 0 | if (StringUtils.isEmpty(visa.getId()) || getEntityVisaBo(visa.getId()) == null) { |
1249 | 0 | throw new RiceIllegalStateException("the EntityVisa to update does not exist: " + visa); |
1250 | |
} |
1251 | |
} |
1252 | 0 | EntityVisaBo bo = EntityVisaBo.from(visa); |
1253 | 0 | return EntityVisaBo.to(businessObjectService.save(bo)); |
1254 | |
} |
1255 | |
|
1256 | |
private EntityNameBo getEntityNameBo(String entityId, String nameTypeCode) { |
1257 | 0 | if (StringUtils.isEmpty(entityId) || StringUtils.isEmpty(nameTypeCode)) { |
1258 | 0 | return null; |
1259 | |
} |
1260 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1261 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
1262 | 0 | criteria.put("nameTypeCode", nameTypeCode); |
1263 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, "Y"); |
1264 | 0 | return businessObjectService.findByPrimaryKey(EntityNameBo.class, criteria); |
1265 | |
} |
1266 | |
|
1267 | |
private EntityNameBo getEntityNameBo(String id) { |
1268 | 0 | if (StringUtils.isEmpty(id)) { |
1269 | 0 | return null; |
1270 | |
} |
1271 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1272 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, id); |
1273 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, "Y"); |
1274 | 0 | return businessObjectService.findByPrimaryKey(EntityNameBo.class, criteria); |
1275 | |
} |
1276 | |
|
1277 | |
@Override |
1278 | |
public EntityName addNameToEntity(EntityName name) { |
1279 | 0 | if (name == null) { |
1280 | 0 | throw new RiceIllegalArgumentException("name is null"); |
1281 | |
} |
1282 | |
|
1283 | 0 | if (StringUtils.isEmpty(name.getEntityId()) || StringUtils.isBlank(name.getEntityId())) { |
1284 | 0 | throw new RiceIllegalStateException("Name's entityId must be populated before creation"); |
1285 | |
} else { |
1286 | 0 | if (name.getNameType() == null) { |
1287 | 0 | throw new RiceIllegalStateException("EntityName's type must be populated before creation"); |
1288 | |
} |
1289 | 0 | if (getEntityNameBo(name.getEntityId(), name.getNameType().getCode()) != null) { |
1290 | 0 | throw new RiceIllegalStateException("the EntityName to create already exists: " + name); |
1291 | |
} |
1292 | |
} |
1293 | 0 | EntityNameBo bo = EntityNameBo.from(name); |
1294 | 0 | return EntityNameBo.to(businessObjectService.save(bo)); |
1295 | |
} |
1296 | |
|
1297 | |
@Override |
1298 | |
public EntityName updateName(EntityName name) { |
1299 | 0 | if (name == null) { |
1300 | 0 | throw new RiceIllegalArgumentException("name is null"); |
1301 | |
} |
1302 | |
|
1303 | 0 | if (StringUtils.isEmpty(name.getEntityId()) || StringUtils.isBlank(name.getEntityId())) { |
1304 | 0 | throw new RiceIllegalStateException("Name's entityId must be populated before update"); |
1305 | |
} else { |
1306 | 0 | if (name.getNameType() == null) { |
1307 | 0 | throw new RiceIllegalStateException("EntityName's type must be populated before update"); |
1308 | |
} |
1309 | 0 | if (StringUtils.isEmpty(name.getId()) || getEntityNameBo(name.getId()) == null) { |
1310 | 0 | throw new RiceIllegalStateException("the EntityName to update does not exist: " + name); |
1311 | |
} |
1312 | |
} |
1313 | 0 | EntityNameBo bo = EntityNameBo.from(name); |
1314 | 0 | return EntityNameBo.to(businessObjectService.save(bo)); |
1315 | |
} |
1316 | |
|
1317 | |
@Override |
1318 | |
public EntityName inactivateName(String id) { |
1319 | 0 | if (StringUtils.isEmpty(id)) { |
1320 | 0 | throw new RiceIllegalArgumentException("id is empty"); |
1321 | |
} |
1322 | |
|
1323 | 0 | EntityNameBo bo = getEntityNameBo(id); |
1324 | 0 | if (bo == null) { |
1325 | 0 | throw new RiceIllegalStateException("the EntityName to inactivate does not exist"); |
1326 | |
} |
1327 | |
|
1328 | 0 | bo.setActive(false); |
1329 | 0 | return EntityNameBo.to(businessObjectService.save(bo)); |
1330 | |
} |
1331 | |
|
1332 | |
private EntityEmploymentBo getEntityEmploymentBo(String entityId, String employmentTypeCode, |
1333 | |
String employmentStatusCode, String employmentAffiliationId) { |
1334 | 0 | if (StringUtils.isEmpty(entityId) || StringUtils.isEmpty(employmentTypeCode) |
1335 | |
|| StringUtils.isEmpty(employmentStatusCode) || StringUtils.isEmpty(employmentAffiliationId)) { |
1336 | 0 | return null; |
1337 | |
} |
1338 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1339 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
1340 | 0 | criteria.put("employeeTypeCode", employmentTypeCode); |
1341 | 0 | criteria.put("employeeStatusCode", employmentStatusCode); |
1342 | 0 | criteria.put("entityAffiliationId", employmentAffiliationId); |
1343 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, "Y"); |
1344 | 0 | return businessObjectService.findByPrimaryKey(EntityEmploymentBo.class, criteria); |
1345 | |
} |
1346 | |
|
1347 | |
private EntityEmploymentBo getEntityEmploymentBo(String id) { |
1348 | 0 | if (StringUtils.isEmpty(id)) { |
1349 | 0 | return null; |
1350 | |
} |
1351 | 0 | Map<String,Object> criteria = new HashMap<String,Object>(); |
1352 | 0 | criteria.put(KIMPropertyConstants.Entity.ID, id); |
1353 | 0 | criteria.put(KIMPropertyConstants.Entity.ACTIVE, "Y"); |
1354 | 0 | return businessObjectService.findByPrimaryKey(EntityEmploymentBo.class, criteria); |
1355 | |
} |
1356 | |
@Override |
1357 | |
public EntityEmployment addEmploymentToEntity(EntityEmployment employment) { |
1358 | 0 | if (employment == null) { |
1359 | 0 | throw new RiceIllegalArgumentException("employment is null"); |
1360 | |
} |
1361 | |
|
1362 | 0 | if (StringUtils.isEmpty(employment.getEntityId()) || StringUtils.isBlank(employment.getEntityId())) { |
1363 | 0 | throw new RiceIllegalStateException("EntityEmployment's entityId must be populated before creation"); |
1364 | |
} else { |
1365 | 0 | if (employment.getEmployeeType() == null |
1366 | |
|| employment.getEmployeeStatus() == null |
1367 | |
|| employment.getEntityAffiliation() == null) { |
1368 | 0 | throw new RiceIllegalStateException("EntityEmployment's status, type, and entity affiliation must be populated before creation"); |
1369 | |
} |
1370 | 0 | if (getEntityEmploymentBo(employment.getEntityId(), employment.getEmployeeType().getCode(), employment.getEmployeeStatus().getCode(), employment.getEntityAffiliation().getId()) != null) { |
1371 | 0 | throw new RiceIllegalStateException("the EntityEmployment to create already exists: " + employment); |
1372 | |
} |
1373 | |
} |
1374 | 0 | EntityEmploymentBo bo = EntityEmploymentBo.from(employment); |
1375 | 0 | return EntityEmploymentBo.to(businessObjectService.save(bo)); |
1376 | |
} |
1377 | |
|
1378 | |
@Override |
1379 | |
public EntityEmployment updateEmployment(EntityEmployment employment) { |
1380 | 0 | if (employment == null) { |
1381 | 0 | throw new RiceIllegalArgumentException("employment is null"); |
1382 | |
} |
1383 | |
|
1384 | 0 | if (StringUtils.isEmpty(employment.getEntityId()) || StringUtils.isBlank(employment.getEntityId())) { |
1385 | 0 | throw new RiceIllegalStateException("EntityEmployment's entityId must be populated before update"); |
1386 | |
} else { |
1387 | 0 | if (employment.getEmployeeType() == null |
1388 | |
|| employment.getEmployeeStatus() == null |
1389 | |
|| employment.getEntityAffiliation() == null) { |
1390 | 0 | throw new RiceIllegalStateException("EntityEmployment's status, type, and entity affiliation must be populated before update"); |
1391 | |
} |
1392 | 0 | if (getEntityEmploymentBo(employment.getEntityId(), employment.getEmployeeType().getCode(), employment.getEmployeeStatus().getCode(), employment.getEntityAffiliation().getId()) == null) { |
1393 | 0 | throw new RiceIllegalStateException("the EntityEmployment to udpate does not exist: " + employment); |
1394 | |
} |
1395 | |
} |
1396 | 0 | EntityEmploymentBo bo = EntityEmploymentBo.from(employment); |
1397 | 0 | return EntityEmploymentBo.to(businessObjectService.save(bo)); |
1398 | |
} |
1399 | |
|
1400 | |
@Override |
1401 | |
public EntityEmployment inactivateEmployment(String id) { |
1402 | 0 | EntityEmploymentBo bo = getEntityEmploymentBo(id); |
1403 | 0 | if (bo == null) { |
1404 | 0 | throw new RiceIllegalStateException("the EntityEmployment to inactivate does not exist"); |
1405 | |
} |
1406 | 0 | bo.setActive(false); |
1407 | 0 | return EntityEmploymentBo.to(businessObjectService.save(bo)); |
1408 | |
} |
1409 | |
|
1410 | |
|
1411 | |
|
1412 | |
|
1413 | |
private EntityBioDemographicsBo getEntityBioDemographicsBo(String entityId) { |
1414 | 0 | if (StringUtils.isEmpty(entityId)) { |
1415 | 0 | return null; |
1416 | |
} |
1417 | 0 | Map<String,String> criteria = new HashMap<String,String>(1); |
1418 | 0 | criteria.put(KIMPropertyConstants.Entity.ENTITY_ID, entityId); |
1419 | 0 | return businessObjectService.findByPrimaryKey(EntityBioDemographicsBo.class, criteria); |
1420 | |
} |
1421 | |
@Override |
1422 | |
public EntityBioDemographics addBioDemographicsToEntity(EntityBioDemographics bioDemographics) { |
1423 | 0 | if (bioDemographics == null) { |
1424 | 0 | throw new RiceIllegalArgumentException("bioDemographics is null"); |
1425 | |
} |
1426 | |
|
1427 | 0 | if (StringUtils.isEmpty(bioDemographics.getEntityId()) || StringUtils.isBlank(bioDemographics.getEntityId())) { |
1428 | 0 | throw new RiceIllegalStateException("BioDemographics' entityId must be populated before creation"); |
1429 | |
} else { |
1430 | 0 | if (getEntityBioDemographicsBo(bioDemographics.getEntityId()) != null) { |
1431 | 0 | throw new RiceIllegalStateException("the EntityBioDemographics to create already exists: " + bioDemographics); |
1432 | |
} |
1433 | |
} |
1434 | 0 | EntityBioDemographicsBo bo = EntityBioDemographicsBo.from(bioDemographics); |
1435 | 0 | return EntityBioDemographicsBo.to(businessObjectService.save(bo)); |
1436 | |
} |
1437 | |
|
1438 | |
@Override |
1439 | |
public EntityBioDemographics updateBioDemographics(EntityBioDemographics bioDemographics) { |
1440 | 0 | if (bioDemographics == null) { |
1441 | 0 | throw new RiceIllegalArgumentException("bioDemographics is null"); |
1442 | |
} |
1443 | |
|
1444 | 0 | if (getEntityBioDemographicsBo(bioDemographics.getEntityId()) == null) { |
1445 | 0 | throw new RiceIllegalStateException("the EntityBioDemographics to update does not exist: " + bioDemographics); |
1446 | |
} |
1447 | 0 | EntityBioDemographicsBo bo = EntityBioDemographicsBo.from(bioDemographics); |
1448 | 0 | return EntityBioDemographicsBo.to(businessObjectService.save(bo)); |
1449 | |
} |
1450 | |
|
1451 | |
|
1452 | |
public void setCriteriaLookupService(final CriteriaLookupService criteriaLookupService) { |
1453 | 0 | this.criteriaLookupService = criteriaLookupService; |
1454 | 0 | } |
1455 | |
|
1456 | |
public void setBusinessObjectService(final BusinessObjectService businessObjectService) { |
1457 | 0 | this.businessObjectService = businessObjectService; |
1458 | 0 | } |
1459 | |
} |