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