| 1 | |
package org.kuali.student.enrollment.class1.lui.model; |
| 2 | |
|
| 3 | |
import java.util.*; |
| 4 | |
|
| 5 | |
import javax.persistence.*; |
| 6 | |
|
| 7 | |
import org.kuali.student.common.entity.KSEntityConstants; |
| 8 | |
import org.kuali.student.enrollment.class1.lrc.model.ResultValuesGroupEntity; |
| 9 | |
import org.kuali.student.enrollment.lui.dto.LuiInfo; |
| 10 | |
import org.kuali.student.enrollment.lui.infc.Lui; |
| 11 | |
import org.kuali.student.enrollment.lui.infc.LuiIdentifier; |
| 12 | |
import org.kuali.student.r2.common.entity.BaseEntity; |
| 13 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 14 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 15 | |
import org.kuali.student.r2.common.util.RichTextHelper; |
| 16 | |
import org.kuali.student.r2.common.util.constants.LuiServiceConstants; |
| 17 | |
import org.kuali.student.r2.lum.clu.infc.LuCode; |
| 18 | |
|
| 19 | |
@Entity |
| 20 | |
@Table(name = "KSEN_LUI") |
| 21 | |
public class LuiEntity extends MetaEntity { |
| 22 | |
|
| 23 | |
@Column(name = "NAME") |
| 24 | |
private String name; |
| 25 | |
@Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 26 | |
private String formatted; |
| 27 | |
@Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH) |
| 28 | |
private String plain; |
| 29 | |
@Column(name = "LUI_TYPE") |
| 30 | |
private String luiType; |
| 31 | |
@Column(name = "LUI_STATE") |
| 32 | |
private String luiState; |
| 33 | |
@Column(name = "CLU_ID") |
| 34 | |
private String cluId; |
| 35 | |
@Column(name = "ATP_ID") |
| 36 | |
private String atpId; |
| 37 | |
@Column(name = "REF_URL") |
| 38 | |
private String referenceURL; |
| 39 | |
@Column(name = "MAX_SEATS") |
| 40 | |
private Integer maxSeats; |
| 41 | |
@Column(name = "MIN_SEATS") |
| 42 | |
private Integer minSeats; |
| 43 | |
@Column(name = "SCHEDULE_ID") |
| 44 | |
private String scheduleId; |
| 45 | |
@Temporal(TemporalType.TIMESTAMP) |
| 46 | |
@Column(name = "EFF_DT") |
| 47 | |
private Date effectiveDate; |
| 48 | |
@Temporal(TemporalType.TIMESTAMP) |
| 49 | |
@Column(name = "EXPIR_DT") |
| 50 | |
private Date expirationDate; |
| 51 | |
|
| 52 | |
@ManyToMany |
| 53 | |
@JoinTable(name="KSEN_LUI_RESULT_VAL_GRP", |
| 54 | |
joinColumns= |
| 55 | |
@JoinColumn(name="LUI_ID", referencedColumnName="ID"), |
| 56 | |
inverseJoinColumns= |
| 57 | |
@JoinColumn(name="RESULT_VAL_GRP_ID", referencedColumnName="ID") |
| 58 | |
) |
| 59 | |
private List<ResultValuesGroupEntity> resultValuesGroups; |
| 60 | |
|
| 61 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lui") |
| 62 | |
private List<LuiIdentifierEntity> identifiers; |
| 63 | |
|
| 64 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lui") |
| 65 | |
private List<LuiUnitsContentOwnerEntity> luiContentOwner; |
| 66 | |
|
| 67 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lui") |
| 68 | |
private List<LuiUnitsDeploymentEntity> luiUnitsDeployment; |
| 69 | |
|
| 70 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lui") |
| 71 | |
private List<LuCodeEntity> luiCodes; |
| 72 | |
|
| 73 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 74 | |
private List<LuiAttributeEntity> attributes; |
| 75 | |
|
| 76 | 0 | public LuiEntity() { |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
public LuiEntity(Lui lui) { |
| 80 | 0 | super(lui); |
| 81 | 0 | this.setId(lui.getId()); |
| 82 | 0 | this.setLuiType(lui.getTypeKey()); |
| 83 | 0 | this.setAtpId(lui.getAtpId()); |
| 84 | 0 | this.setCluId(lui.getCluId()); |
| 85 | |
|
| 86 | 0 | fromDto(lui); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
public List<Object> fromDto(Lui lui) { |
| 90 | |
|
| 91 | 0 | List<Object> orphansToDelete = new ArrayList<Object>(); |
| 92 | |
|
| 93 | 0 | this.setName(lui.getName()); |
| 94 | 0 | this.setMaxSeats(lui.getMaximumEnrollment()); |
| 95 | 0 | this.setMinSeats(lui.getMinimumEnrollment()); |
| 96 | 0 | this.setReferenceURL(lui.getReferenceURL()); |
| 97 | 0 | this.setLuiState(lui.getStateKey()); |
| 98 | 0 | this.setEffectiveDate(lui.getEffectiveDate()); |
| 99 | 0 | this.setExpirationDate(lui.getExpirationDate()); |
| 100 | 0 | if (lui.getDescr() == null) { |
| 101 | 0 | this.setDescrFormatted(null); |
| 102 | 0 | this.setDescrPlain(null); |
| 103 | |
} else { |
| 104 | 0 | this.setDescrFormatted(lui.getDescr().getFormatted()); |
| 105 | 0 | this.setDescrPlain(lui.getDescr().getPlain()); |
| 106 | |
} |
| 107 | |
|
| 108 | 0 | this.setLuiCodes(new ArrayList<LuCodeEntity>()); |
| 109 | 0 | for (LuCode luCode : lui.getLuiCodes()) { |
| 110 | 0 | this.getLuiCodes().add(new LuCodeEntity(luCode)); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | 0 | Map<String,LuiIdentifierEntity> existingIdents = new HashMap<String,LuiIdentifierEntity>(); |
| 117 | 0 | if(this.getIdentifiers() != null){ |
| 118 | 0 | for(LuiIdentifierEntity ident : this.getIdentifiers()){ |
| 119 | 0 | existingIdents.put(ident.getId(),ident); |
| 120 | |
} |
| 121 | |
} |
| 122 | |
|
| 123 | 0 | this.setIdentifiers(new ArrayList<LuiIdentifierEntity>()); |
| 124 | |
|
| 125 | |
|
| 126 | 0 | if (lui.getOfficialIdentifier() != null) { |
| 127 | |
LuiIdentifierEntity identEntity; |
| 128 | |
|
| 129 | 0 | if(existingIdents.containsKey(lui.getOfficialIdentifier().getId())){ |
| 130 | |
|
| 131 | 0 | identEntity = existingIdents.remove(lui.getOfficialIdentifier().getId()); |
| 132 | 0 | identEntity.fromDto(lui.getOfficialIdentifier()); |
| 133 | |
}else{ |
| 134 | |
|
| 135 | 0 | identEntity = new LuiIdentifierEntity(lui.getOfficialIdentifier()); |
| 136 | |
} |
| 137 | |
|
| 138 | 0 | identEntity.setLui(this); |
| 139 | 0 | this.getIdentifiers().add(identEntity); |
| 140 | |
} |
| 141 | |
|
| 142 | |
|
| 143 | 0 | for (LuiIdentifier identifier : lui.getAlternateIdentifiers()) { |
| 144 | |
LuiIdentifierEntity identEntity; |
| 145 | |
|
| 146 | 0 | if(existingIdents.containsKey(identifier.getId())){ |
| 147 | |
|
| 148 | 0 | identEntity = existingIdents.remove(identifier.getId()); |
| 149 | 0 | identEntity.fromDto(identifier); |
| 150 | |
}else{ |
| 151 | |
|
| 152 | 0 | identEntity = new LuiIdentifierEntity(identifier); |
| 153 | 0 | identEntity.setLui(this); |
| 154 | |
} |
| 155 | |
|
| 156 | 0 | this.getIdentifiers().add(identEntity); |
| 157 | 0 | } |
| 158 | |
|
| 159 | |
|
| 160 | 0 | orphansToDelete.addAll(existingIdents.values()); |
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | 0 | Map<String,LuiUnitsContentOwnerEntity> existinguUnitsContentOwnerEntities = new HashMap<String,LuiUnitsContentOwnerEntity>(); |
| 166 | 0 | if(this.getLuiContentOwner() != null){ |
| 167 | 0 | for(LuiUnitsContentOwnerEntity unitEntity : this.getLuiContentOwner()){ |
| 168 | 0 | existinguUnitsContentOwnerEntities.put(unitEntity.getOrgId(), unitEntity); |
| 169 | |
} |
| 170 | |
} |
| 171 | |
|
| 172 | |
|
| 173 | 0 | this.setLuiContentOwner(new ArrayList<LuiUnitsContentOwnerEntity>()); |
| 174 | |
|
| 175 | 0 | if(lui.getUnitsContentOwner()!=null){ |
| 176 | 0 | for(String unitContentOrgId : lui.getUnitsContentOwner() ){ |
| 177 | |
LuiUnitsContentOwnerEntity luiUnitContentOwner; |
| 178 | 0 | if(existinguUnitsContentOwnerEntities.containsKey(unitContentOrgId)){ |
| 179 | 0 | luiUnitContentOwner = existinguUnitsContentOwnerEntities.remove(unitContentOrgId); |
| 180 | |
}else{ |
| 181 | 0 | luiUnitContentOwner = new LuiUnitsContentOwnerEntity(this, unitContentOrgId); |
| 182 | |
} |
| 183 | 0 | this.getLuiContentOwner().add(luiUnitContentOwner); |
| 184 | 0 | } |
| 185 | |
} |
| 186 | |
|
| 187 | |
|
| 188 | 0 | orphansToDelete.addAll(existinguUnitsContentOwnerEntities.values()); |
| 189 | |
|
| 190 | |
|
| 191 | 0 | Map<String,LuiUnitsDeploymentEntity> existinguLuiUnitsDeploymentEntities = new HashMap<String,LuiUnitsDeploymentEntity>(); |
| 192 | 0 | if(this.getLuiUnitsDeployment() != null){ |
| 193 | 0 | for(LuiUnitsDeploymentEntity unitEntity : this.getLuiUnitsDeployment()){ |
| 194 | 0 | existinguLuiUnitsDeploymentEntities.put(unitEntity.getOrgId(),unitEntity); |
| 195 | |
} |
| 196 | |
} |
| 197 | |
|
| 198 | |
|
| 199 | 0 | this.setLuiUnitsDeployment(new ArrayList<LuiUnitsDeploymentEntity>()); |
| 200 | |
|
| 201 | 0 | if(lui.getUnitsDeployment() != null){ |
| 202 | 0 | for(String unitDeploymentOrgId : lui.getUnitsDeployment()){ |
| 203 | |
LuiUnitsDeploymentEntity luiUnitDeployment; |
| 204 | 0 | if(existinguLuiUnitsDeploymentEntities.containsKey(unitDeploymentOrgId)){ |
| 205 | 0 | luiUnitDeployment = existinguLuiUnitsDeploymentEntities.remove(unitDeploymentOrgId); |
| 206 | |
}else{ |
| 207 | 0 | luiUnitDeployment = new LuiUnitsDeploymentEntity(this, unitDeploymentOrgId); |
| 208 | |
} |
| 209 | 0 | this.getLuiUnitsDeployment().add(luiUnitDeployment); |
| 210 | 0 | } |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | 0 | orphansToDelete.addAll(existinguLuiUnitsDeploymentEntities.values()); |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | 0 | this.setAttributes(new ArrayList<LuiAttributeEntity>()); |
| 219 | 0 | for (Attribute att : lui.getAttributes()) { |
| 220 | 0 | this.getAttributes().add(new LuiAttributeEntity(att)); |
| 221 | |
} |
| 222 | |
|
| 223 | 0 | return orphansToDelete; |
| 224 | |
} |
| 225 | |
|
| 226 | |
public LuiInfo toDto() { |
| 227 | 0 | LuiInfo info = new LuiInfo(); |
| 228 | 0 | info.setId(getId()); |
| 229 | 0 | info.setName(name); |
| 230 | 0 | info.setAtpId(atpId); |
| 231 | 0 | info.setCluId(cluId); |
| 232 | 0 | info.setMaximumEnrollment(maxSeats); |
| 233 | 0 | info.setMinimumEnrollment(minSeats); |
| 234 | 0 | info.setEffectiveDate(effectiveDate); |
| 235 | 0 | info.setExpirationDate(expirationDate); |
| 236 | 0 | info.setReferenceURL(referenceURL); |
| 237 | 0 | info.setTypeKey(luiType); |
| 238 | 0 | info.setStateKey(luiState); |
| 239 | 0 | info.setMeta(super.toDTO()); |
| 240 | 0 | info.setDescr(new RichTextHelper().toRichTextInfo(plain, formatted)); |
| 241 | |
|
| 242 | |
|
| 243 | 0 | if (luiCodes != null) { |
| 244 | 0 | for (LuCodeEntity luCode : luiCodes) { |
| 245 | 0 | info.getLuiCodes().add(luCode.toDto()); |
| 246 | |
} |
| 247 | |
} |
| 248 | |
|
| 249 | |
|
| 250 | 0 | if (identifiers != null) { |
| 251 | 0 | for (LuiIdentifierEntity identifier : identifiers) { |
| 252 | 0 | if (LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY.equals(identifier.getType())) { |
| 253 | 0 | info.setOfficialIdentifier(identifier.toDto()); |
| 254 | |
} else { |
| 255 | 0 | info.getAlternateIdentifiers().add(identifier.toDto()); |
| 256 | |
} |
| 257 | |
} |
| 258 | |
} |
| 259 | |
|
| 260 | |
|
| 261 | 0 | if (getAttributes() != null) { |
| 262 | 0 | for (LuiAttributeEntity att : getAttributes()) { |
| 263 | 0 | info.getAttributes().add(att.toDto()); |
| 264 | |
} |
| 265 | |
} |
| 266 | 0 | List<String> unitsDeploymentOrgIds = new ArrayList<String>(); |
| 267 | 0 | if( this.luiUnitsDeployment!= null) { |
| 268 | 0 | for(LuiUnitsDeploymentEntity unitsDep : this.luiUnitsDeployment){ |
| 269 | |
|
| 270 | 0 | unitsDeploymentOrgIds.add(unitsDep.getOrgId()); |
| 271 | |
} |
| 272 | |
} |
| 273 | 0 | info.setUnitsContentOwner(unitsDeploymentOrgIds); |
| 274 | |
|
| 275 | 0 | List<String> unitsContentOrgIds = new ArrayList<String>(); |
| 276 | |
|
| 277 | 0 | if(this.luiContentOwner!=null){ |
| 278 | 0 | for(LuiUnitsContentOwnerEntity unitsContent : this.luiContentOwner){ |
| 279 | |
|
| 280 | 0 | unitsContentOrgIds.add(unitsContent.getOrgId()); |
| 281 | |
} |
| 282 | |
} |
| 283 | |
|
| 284 | |
|
| 285 | 0 | info.setUnitsContentOwner(unitsContentOrgIds); |
| 286 | 0 | return info; |
| 287 | |
} |
| 288 | |
|
| 289 | |
public Integer getMaxSeats() { |
| 290 | 0 | return maxSeats; |
| 291 | |
} |
| 292 | |
|
| 293 | |
public void setMaxSeats(Integer maxSeats) { |
| 294 | 0 | this.maxSeats = maxSeats; |
| 295 | 0 | } |
| 296 | |
|
| 297 | |
public Integer getMinSeats() { |
| 298 | 0 | return minSeats; |
| 299 | |
} |
| 300 | |
|
| 301 | |
public void setMinSeats(Integer minSeats) { |
| 302 | 0 | this.minSeats = minSeats; |
| 303 | 0 | } |
| 304 | |
|
| 305 | |
public Date getEffectiveDate() { |
| 306 | 0 | return effectiveDate; |
| 307 | |
} |
| 308 | |
|
| 309 | |
public void setEffectiveDate(Date effectiveDate) { |
| 310 | 0 | this.effectiveDate = effectiveDate; |
| 311 | 0 | } |
| 312 | |
|
| 313 | |
public Date getExpirationDate() { |
| 314 | 0 | return expirationDate; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public void setExpirationDate(Date expirationDate) { |
| 318 | 0 | this.expirationDate = expirationDate; |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
public String getCluId() { |
| 322 | 0 | return cluId; |
| 323 | |
} |
| 324 | |
|
| 325 | |
public void setCluId(String cluId) { |
| 326 | 0 | this.cluId = cluId; |
| 327 | 0 | } |
| 328 | |
|
| 329 | |
public String getName() { |
| 330 | 0 | return name; |
| 331 | |
} |
| 332 | |
|
| 333 | |
public void setName(String name) { |
| 334 | 0 | this.name = name; |
| 335 | 0 | } |
| 336 | |
|
| 337 | |
public String getAtpId() { |
| 338 | 0 | return atpId; |
| 339 | |
} |
| 340 | |
|
| 341 | |
public void setAtpId(String atpId) { |
| 342 | 0 | this.atpId = atpId; |
| 343 | 0 | } |
| 344 | |
|
| 345 | |
public String getDescrFormatted() { |
| 346 | 0 | return formatted; |
| 347 | |
} |
| 348 | |
|
| 349 | |
public void setDescrFormatted(String formatted) { |
| 350 | 0 | this.formatted = formatted; |
| 351 | 0 | } |
| 352 | |
|
| 353 | |
public String getDescrPlain() { |
| 354 | 0 | return plain; |
| 355 | |
} |
| 356 | |
|
| 357 | |
public void setDescrPlain(String plain) { |
| 358 | 0 | this.plain = plain; |
| 359 | 0 | } |
| 360 | |
|
| 361 | |
public String getLuiType() { |
| 362 | 0 | return luiType; |
| 363 | |
} |
| 364 | |
|
| 365 | |
public void setLuiType(String luiType) { |
| 366 | 0 | this.luiType = luiType; |
| 367 | 0 | } |
| 368 | |
|
| 369 | |
public String getLuiState() { |
| 370 | 0 | return luiState; |
| 371 | |
} |
| 372 | |
|
| 373 | |
public void setLuiState(String luiState) { |
| 374 | 0 | this.luiState = luiState; |
| 375 | 0 | } |
| 376 | |
|
| 377 | |
public String getReferenceURL() { |
| 378 | 0 | return referenceURL; |
| 379 | |
} |
| 380 | |
|
| 381 | |
public void setReferenceURL(String referenceURL) { |
| 382 | 0 | this.referenceURL = referenceURL; |
| 383 | 0 | } |
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
public void setAttributes(List<LuiAttributeEntity> attributes) { |
| 409 | 0 | this.attributes = attributes; |
| 410 | 0 | } |
| 411 | |
|
| 412 | |
public List<LuiIdentifierEntity> getIdentifiers() { |
| 413 | 0 | return identifiers; |
| 414 | |
} |
| 415 | |
|
| 416 | |
public void setIdentifiers(List<LuiIdentifierEntity> identifiers) { |
| 417 | 0 | this.identifiers = identifiers; |
| 418 | 0 | } |
| 419 | |
|
| 420 | |
public List<LuiAttributeEntity> getAttributes() { |
| 421 | 0 | return attributes; |
| 422 | |
} |
| 423 | |
|
| 424 | |
public String getFormatted() { |
| 425 | 0 | return formatted; |
| 426 | |
} |
| 427 | |
|
| 428 | |
public void setFormatted(String formatted) { |
| 429 | 0 | this.formatted = formatted; |
| 430 | 0 | } |
| 431 | |
|
| 432 | |
public String getPlain() { |
| 433 | 0 | return plain; |
| 434 | |
} |
| 435 | |
|
| 436 | |
public void setPlain(String plain) { |
| 437 | 0 | this.plain = plain; |
| 438 | 0 | } |
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
public List<LuCodeEntity> getLuiCodes() { |
| 445 | 0 | return luiCodes; |
| 446 | |
} |
| 447 | |
|
| 448 | |
public void setLuiCodes(List<LuCodeEntity> luiCodes) { |
| 449 | 0 | this.luiCodes = luiCodes; |
| 450 | 0 | } |
| 451 | |
|
| 452 | |
public List<LuiUnitsContentOwnerEntity> getLuiContentOwner() { |
| 453 | 0 | return luiContentOwner; |
| 454 | |
} |
| 455 | |
|
| 456 | |
public void setLuiContentOwner(List<LuiUnitsContentOwnerEntity> luiContentOwner) { |
| 457 | 0 | this.luiContentOwner = luiContentOwner; |
| 458 | 0 | } |
| 459 | |
|
| 460 | |
public List<LuiUnitsDeploymentEntity> getLuiUnitsDeployment() { |
| 461 | 0 | return luiUnitsDeployment; |
| 462 | |
} |
| 463 | |
|
| 464 | |
public void setLuiUnitsDeployment(List<LuiUnitsDeploymentEntity> luiUnitsDeployment) { |
| 465 | 0 | this.luiUnitsDeployment = luiUnitsDeployment; |
| 466 | 0 | } |
| 467 | |
} |