| 1 | |
package org.kuali.rice.kim.impl.identity.entity |
| 2 | |
|
| 3 | |
import javax.persistence.CascadeType |
| 4 | |
import javax.persistence.Column |
| 5 | |
import javax.persistence.FetchType |
| 6 | |
import javax.persistence.Id |
| 7 | |
import javax.persistence.JoinColumn |
| 8 | |
import javax.persistence.OneToMany |
| 9 | |
import javax.persistence.OneToOne |
| 10 | |
import javax.persistence.Table |
| 11 | |
import org.apache.commons.collections.CollectionUtils |
| 12 | |
import org.hibernate.annotations.Fetch |
| 13 | |
import org.hibernate.annotations.FetchMode |
| 14 | |
import org.hibernate.annotations.Type |
| 15 | |
import org.kuali.rice.kim.api.identity.EntityUtils |
| 16 | |
import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation |
| 17 | |
import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship |
| 18 | |
import org.kuali.rice.kim.api.identity.employment.EntityEmployment |
| 19 | |
import org.kuali.rice.kim.api.identity.entity.Entity |
| 20 | |
import org.kuali.rice.kim.api.identity.entity.EntityContract |
| 21 | |
import org.kuali.rice.kim.api.identity.entity.EntityDefault |
| 22 | |
import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier |
| 23 | |
import org.kuali.rice.kim.api.identity.name.EntityName |
| 24 | |
import org.kuali.rice.kim.api.identity.name.EntityNameContract |
| 25 | |
import org.kuali.rice.kim.api.identity.personal.EntityEthnicity |
| 26 | |
import org.kuali.rice.kim.api.identity.principal.Principal |
| 27 | |
import org.kuali.rice.kim.api.identity.residency.EntityResidency |
| 28 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeData |
| 29 | |
import org.kuali.rice.kim.api.identity.visa.EntityVisa |
| 30 | |
import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo |
| 31 | |
import org.kuali.rice.kim.impl.identity.citizenship.EntityCitizenshipBo |
| 32 | |
import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo |
| 33 | |
import org.kuali.rice.kim.impl.identity.external.EntityExternalIdentifierBo |
| 34 | |
import org.kuali.rice.kim.impl.identity.name.EntityNameBo |
| 35 | |
import org.kuali.rice.kim.impl.identity.personal.EntityBioDemographicsBo |
| 36 | |
import org.kuali.rice.kim.impl.identity.personal.EntityEthnicityBo |
| 37 | |
import org.kuali.rice.kim.impl.identity.principal.PrincipalBo |
| 38 | |
import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo |
| 39 | |
import org.kuali.rice.kim.impl.identity.residency.EntityResidencyBo |
| 40 | |
import org.kuali.rice.kim.impl.identity.type.EntityTypeDataBo |
| 41 | |
import org.kuali.rice.kim.impl.identity.visa.EntityVisaBo |
| 42 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
| 43 | |
|
| 44 | |
@javax.persistence.Entity |
| 45 | |
@Table(name = "KRIM_ENTITY_T") |
| 46 | |
class EntityBo extends PersistableBusinessObjectBase implements EntityContract { |
| 47 | |
@Id |
| 48 | |
@Column(name = "ENTITY_ID") |
| 49 | |
String id; |
| 50 | |
|
| 51 | |
@OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 52 | |
@Fetch(value = FetchMode.SELECT) |
| 53 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 54 | 1 | List<EntityNameBo> names = new ArrayList<EntityNameBo>() |
| 55 | |
|
| 56 | |
@OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 57 | |
@Fetch(value = FetchMode.SELECT) |
| 58 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 59 | 1 | List<PrincipalBo> principals = new ArrayList<PrincipalBo>() |
| 60 | |
|
| 61 | |
@OneToMany(fetch=FetchType.EAGER,cascade=[CascadeType.ALL]) |
| 62 | |
@Fetch(value = FetchMode.SELECT) |
| 63 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false) |
| 64 | 1 | List<EntityExternalIdentifierBo> externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>() |
| 65 | |
|
| 66 | |
@Fetch(value = FetchMode.SELECT) |
| 67 | |
@OneToMany(fetch=FetchType.EAGER,cascade=[CascadeType.ALL]) |
| 68 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false) |
| 69 | 1 | List<EntityAffiliationBo> affiliations = new ArrayList<EntityAffiliationBo>() |
| 70 | |
|
| 71 | |
@OneToMany(fetch=FetchType.EAGER, cascade=[CascadeType.ALL]) |
| 72 | |
@Fetch(value = FetchMode.SELECT) |
| 73 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false) |
| 74 | 1 | List<EntityEmploymentBo> employmentInformation = new ArrayList<EntityEmploymentBo>() |
| 75 | |
|
| 76 | |
@OneToMany(fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 77 | |
@Fetch(value = FetchMode.SELECT) |
| 78 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 79 | 1 | List<EntityTypeDataBo> entityTypes = new ArrayList<EntityTypeDataBo>() |
| 80 | |
|
| 81 | |
@OneToOne(targetEntity=EntityPrivacyPreferencesBo.class, fetch = FetchType.EAGER, cascade = [CascadeType.MERGE, CascadeType.REFRESH]) |
| 82 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 83 | |
EntityPrivacyPreferencesBo privacyPreferences |
| 84 | |
|
| 85 | |
@OneToOne(targetEntity=EntityBioDemographicsBo.class, fetch = FetchType.EAGER, cascade = []) |
| 86 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 87 | |
EntityBioDemographicsBo bioDemographics |
| 88 | |
|
| 89 | |
@OneToMany(targetEntity = EntityCitizenshipBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 90 | |
@Fetch(value = FetchMode.SELECT) |
| 91 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 92 | 1 | List<EntityCitizenshipBo> citizenships = new ArrayList<EntityCitizenshipBo>() |
| 93 | |
|
| 94 | |
@OneToMany(targetEntity = EntityEthnicityBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 95 | |
@Fetch(value = FetchMode.SELECT) |
| 96 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 97 | 1 | List<EntityEthnicityBo> ethnicities = new ArrayList<EntityEthnicityBo>() |
| 98 | |
|
| 99 | |
@OneToMany(targetEntity = EntityResidencyBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 100 | |
@Fetch(value = FetchMode.SELECT) |
| 101 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 102 | 1 | List<EntityResidencyBo> residencies = new ArrayList<EntityResidencyBo>() |
| 103 | |
|
| 104 | |
@OneToMany(targetEntity = EntityVisaBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
| 105 | |
@Fetch(value = FetchMode.SELECT) |
| 106 | |
@JoinColumn(name = "ENTITY_ID", insertable = false, updatable = false) |
| 107 | 1 | List<EntityVisaBo> visas = new ArrayList<EntityVisaBo>() |
| 108 | |
|
| 109 | |
@Type(type="yes_no") |
| 110 | |
@Column(name="ACTV_IND") |
| 111 | |
boolean active; |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
static Entity to(EntityBo bo) { |
| 119 | 1 | if (bo == null) { return null } |
| 120 | 1 | return Entity.Builder.create(bo).build() |
| 121 | |
} |
| 122 | |
|
| 123 | |
static EntityDefault toDefault(EntityBo bo) { |
| 124 | 0 | if (bo == null) { return null } |
| 125 | 0 | return EntityDefault.Builder.create(bo).build() |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
static EntityBo from(Entity immutable) { |
| 134 | 1 | if (immutable == null) {return null} |
| 135 | |
|
| 136 | 1 | EntityBo bo = new EntityBo() |
| 137 | 1 | bo.active = immutable.active |
| 138 | 1 | bo.id = immutable.id |
| 139 | |
|
| 140 | 1 | bo.names = new ArrayList<EntityNameBo>() |
| 141 | 1 | if (CollectionUtils.isNotEmpty(immutable.names)) { |
| 142 | 0 | for (EntityName name : immutable.names) { |
| 143 | 0 | bo.names.add(EntityNameBo.from(name)) |
| 144 | |
} |
| 145 | |
} |
| 146 | |
|
| 147 | 1 | bo.principals = new ArrayList<PrincipalBo>() |
| 148 | 1 | if (CollectionUtils.isNotEmpty(immutable.principals)) { |
| 149 | 0 | for (Principal principal : immutable.principals) { |
| 150 | 0 | bo.principals.add(PrincipalBo.from(principal)) |
| 151 | |
} |
| 152 | |
} |
| 153 | |
|
| 154 | 1 | bo.externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>(); |
| 155 | 1 | if (CollectionUtils.isNotEmpty(immutable.externalIdentifiers)) { |
| 156 | 0 | for (EntityExternalIdentifier externalId : immutable.externalIdentifiers) { |
| 157 | 0 | bo.externalIdentifiers.add(EntityExternalIdentifierBo.from(externalId)) |
| 158 | |
} |
| 159 | |
} |
| 160 | |
|
| 161 | 1 | bo.affiliations = new ArrayList<EntityAffiliationBo>() |
| 162 | 1 | if (CollectionUtils.isNotEmpty(immutable.affiliations)) { |
| 163 | 0 | for (EntityAffiliation affiliation : immutable.affiliations) { |
| 164 | 0 | bo.affiliations.add(EntityAffiliationBo.from(affiliation)) |
| 165 | |
} |
| 166 | |
} |
| 167 | |
|
| 168 | 1 | bo.employmentInformation = new ArrayList<EntityEmploymentBo>() |
| 169 | 1 | if (CollectionUtils.isNotEmpty(immutable.employmentInformation)) { |
| 170 | 0 | for (EntityEmployment employment : immutable.employmentInformation) { |
| 171 | 0 | bo.employmentInformation.add(EntityEmploymentBo.from(employment)) |
| 172 | |
} |
| 173 | |
} |
| 174 | |
|
| 175 | 1 | bo.entityTypes = new ArrayList<EntityTypeDataBo>() |
| 176 | 1 | if (CollectionUtils.isNotEmpty(immutable.entityTypes)) { |
| 177 | 0 | for (EntityTypeData entityType : immutable.entityTypes) { |
| 178 | 0 | bo.entityTypes.add(EntityTypeDataBo.from(entityType)) |
| 179 | |
} |
| 180 | |
} |
| 181 | |
|
| 182 | 1 | if (immutable.privacyPreferences != null) { |
| 183 | 0 | bo.privacyPreferences = EntityPrivacyPreferencesBo.from(immutable.privacyPreferences) |
| 184 | |
} |
| 185 | |
|
| 186 | 1 | if (immutable.bioDemographics != null) { |
| 187 | 0 | bo.bioDemographics = EntityBioDemographicsBo.from(immutable.bioDemographics) |
| 188 | |
} |
| 189 | |
|
| 190 | 1 | bo.citizenships = new ArrayList<EntityCitizenshipBo>() |
| 191 | 1 | if (CollectionUtils.isNotEmpty(immutable.citizenships)) { |
| 192 | 0 | for (EntityCitizenship citizenship : immutable.citizenships) { |
| 193 | 0 | bo.citizenships.add(EntityCitizenshipBo.from(citizenship)) |
| 194 | |
} |
| 195 | |
} |
| 196 | |
|
| 197 | 1 | bo.ethnicities = new ArrayList<EntityEthnicityBo>() |
| 198 | 1 | if (CollectionUtils.isNotEmpty(immutable.ethnicities)) { |
| 199 | 0 | for (EntityEthnicity ethnicity : immutable.ethnicities) { |
| 200 | 0 | bo.ethnicities.add(EntityEthnicityBo.from(ethnicity)) |
| 201 | |
} |
| 202 | |
} |
| 203 | |
|
| 204 | 1 | bo.residencies = new ArrayList<EntityResidencyBo>() |
| 205 | 1 | if (CollectionUtils.isNotEmpty(immutable.residencies)) { |
| 206 | 0 | for (EntityResidency residency : immutable.residencies) { |
| 207 | 0 | bo.residencies.add(EntityResidencyBo.from(residency)) |
| 208 | |
} |
| 209 | |
} |
| 210 | |
|
| 211 | 1 | bo.visas = new ArrayList<EntityVisaBo>() |
| 212 | 1 | if (CollectionUtils.isNotEmpty(immutable.visas)) { |
| 213 | 0 | for (EntityVisa visa : immutable.visas) { |
| 214 | 0 | bo.visas.add(EntityVisaBo.from(visa)) |
| 215 | |
} |
| 216 | |
} |
| 217 | |
|
| 218 | 1 | bo.versionNumber = immutable.versionNumber |
| 219 | 1 | bo.objectId = immutable.objectId |
| 220 | |
|
| 221 | 1 | return bo; |
| 222 | |
} |
| 223 | |
|
| 224 | |
|
| 225 | |
EntityTypeDataBo getEntityType(String entityTypeCode) { |
| 226 | 0 | if (CollectionUtils.isEmpty(this.entityTypes)) { |
| 227 | 0 | return null |
| 228 | |
} |
| 229 | 0 | for (EntityTypeDataBo entType : this.entityTypes) { |
| 230 | 0 | if (entType.getEntityTypeCode().equals(entityTypeCode)) { |
| 231 | 0 | return entType |
| 232 | |
} |
| 233 | |
} |
| 234 | 0 | return null |
| 235 | |
} |
| 236 | |
|
| 237 | |
EntityEmploymentBo getPrimaryEmployment() { |
| 238 | 0 | if (CollectionUtils.isEmpty(this.employmentInformation)) { |
| 239 | 0 | return null |
| 240 | |
} |
| 241 | 0 | for (EntityEmploymentBo employment : this.employmentInformation) { |
| 242 | 0 | if (employment.isPrimary() && employment.isActive()) { |
| 243 | 0 | return employment |
| 244 | |
} |
| 245 | |
} |
| 246 | 0 | return null |
| 247 | |
} |
| 248 | |
|
| 249 | |
EntityAffiliationBo getDefaultAffiliation() { |
| 250 | 0 | return EntityUtils.getDefaultItem(this.affiliations) |
| 251 | |
} |
| 252 | |
|
| 253 | |
EntityExternalIdentifierBo getEntityExternalIdentifier(String externalIdentifierTypeCode) { |
| 254 | 0 | if (CollectionUtils.isEmpty(this.externalIdentifiers)) { |
| 255 | 0 | return null |
| 256 | |
} |
| 257 | 0 | for (EntityExternalIdentifierBo externalId : this.externalIdentifiers) { |
| 258 | 0 | if (externalId.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) { |
| 259 | 0 | return externalId |
| 260 | |
} |
| 261 | |
} |
| 262 | 0 | return null |
| 263 | |
} |
| 264 | |
|
| 265 | |
EntityNameContract getDefaultName() { |
| 266 | 0 | return EntityUtils.getDefaultItem(this.names) |
| 267 | |
} |
| 268 | |
|
| 269 | |
@Override |
| 270 | |
public EntityPrivacyPreferencesBo getPrivacyPreferences() { |
| 271 | 1 | return this.privacyPreferences |
| 272 | |
} |
| 273 | |
|
| 274 | |
@Override |
| 275 | |
public EntityBioDemographicsBo getBioDemographics() { |
| 276 | 1 | return this.bioDemographics |
| 277 | |
} |
| 278 | |
} |