| 1 | |
package org.kuali.student.enrollment.class1.lpr.model; |
| 2 | |
|
| 3 | |
import java.math.BigDecimal; |
| 4 | |
import java.util.ArrayList; |
| 5 | |
import java.util.Date; |
| 6 | |
import java.util.LinkedHashMap; |
| 7 | |
import java.util.List; |
| 8 | |
import java.util.Map; |
| 9 | |
|
| 10 | |
import javax.persistence.CascadeType; |
| 11 | |
import javax.persistence.Column; |
| 12 | |
import javax.persistence.Entity; |
| 13 | |
import javax.persistence.OneToMany; |
| 14 | |
import javax.persistence.Table; |
| 15 | |
import javax.persistence.Temporal; |
| 16 | |
import javax.persistence.TemporalType; |
| 17 | |
|
| 18 | |
import org.kuali.student.enrollment.lpr.dto.LprInfo; |
| 19 | |
import org.kuali.student.enrollment.lpr.infc.Lpr; |
| 20 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 21 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 22 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper; |
| 23 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.EntityMergeOptions; |
| 24 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.EntityMergeResult; |
| 25 | |
import org.kuali.student.r2.common.helper.EntityMergeHelper.StringMergeOptions; |
| 26 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
@Entity |
| 32 | |
@Table(name = "KSEN_LPR") |
| 33 | |
public class LprEntity extends MetaEntity { |
| 34 | |
|
| 35 | |
@Column(name = "PERS_ID") |
| 36 | |
private String personId; |
| 37 | |
|
| 38 | |
@Column(name = "LUI_ID") |
| 39 | |
private String luiId; |
| 40 | |
|
| 41 | |
@Column(name = "COMMIT_PERCT") |
| 42 | |
private BigDecimal commitmentPercent; |
| 43 | |
|
| 44 | |
@Temporal(TemporalType.TIMESTAMP) |
| 45 | |
@Column(name = "EFF_DT") |
| 46 | |
private Date effectiveDate; |
| 47 | |
|
| 48 | |
@Temporal(TemporalType.TIMESTAMP) |
| 49 | |
@Column(name = "EXPIR_DT") |
| 50 | |
private Date expirationDate; |
| 51 | |
|
| 52 | |
@Column(name = "LPR_TYPE") |
| 53 | |
private String personRelationTypeId; |
| 54 | |
|
| 55 | |
@Column(name = "LPR_STATE") |
| 56 | |
private String personRelationStateId; |
| 57 | |
|
| 58 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
| 59 | |
private List<LprAttributeEntity> attributes; |
| 60 | |
|
| 61 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lpr") |
| 62 | |
private List<LprResultValueGroupEntity> resultValueGroups; |
| 63 | |
|
| 64 | 0 | public LprEntity() { |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
public LprEntity(Lpr dto) { |
| 68 | 0 | super(dto); |
| 69 | |
|
| 70 | 0 | this.setId(dto.getId()); |
| 71 | 0 | this.setLuiId(dto.getLuiId()); |
| 72 | 0 | this.setPersonId(dto.getPersonId()); |
| 73 | 0 | this.setPersonRelationTypeId(dto.getTypeKey()); |
| 74 | 0 | fromDto(dto); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
public List<Object> fromDto(Lpr dto) { |
| 79 | |
|
| 80 | 0 | List<Object> orphanData = new ArrayList<Object>(); |
| 81 | |
|
| 82 | 0 | this.setCommitmentPercent(new BigDecimal(dto.getCommitmentPercent())); |
| 83 | 0 | this.setExpirationDate(dto.getExpirationDate()); |
| 84 | 0 | this.setEffectiveDate(dto.getEffectiveDate()); |
| 85 | 0 | this.setPersonRelationStateId(dto.getStateKey()); |
| 86 | |
|
| 87 | 0 | EntityMergeHelper<LprAttributeEntity, Attribute> attributeMergeHelper = new EntityMergeHelper<LprAttributeEntity, Attribute>(); |
| 88 | |
|
| 89 | 0 | EntityMergeResult<LprAttributeEntity> attributeMergeResult = attributeMergeHelper |
| 90 | |
.merge(this.attributes, |
| 91 | |
(List<Attribute>) dto.getAttributes(), |
| 92 | 0 | new EntityMergeOptions<LprAttributeEntity, Attribute>() { |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public String getEntityId(LprAttributeEntity entity) { |
| 96 | 0 | return entity.getId(); |
| 97 | |
} |
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public String getInfoId(Attribute info) { |
| 101 | 0 | return info.getId(); |
| 102 | |
} |
| 103 | |
|
| 104 | |
@Override |
| 105 | |
public List<Object> merge( |
| 106 | |
LprAttributeEntity entity, Attribute info) { |
| 107 | |
|
| 108 | 0 | entity.fromDto(info); |
| 109 | |
|
| 110 | 0 | entity.setOwner(LprEntity.this); |
| 111 | |
|
| 112 | 0 | return new ArrayList<Object>(); |
| 113 | |
} |
| 114 | |
|
| 115 | |
@Override |
| 116 | |
public LprAttributeEntity create(Attribute info) { |
| 117 | 0 | LprAttributeEntity entity = new LprAttributeEntity(info); |
| 118 | |
|
| 119 | 0 | entity.setOwner(LprEntity.this); |
| 120 | |
|
| 121 | 0 | return entity; |
| 122 | |
} |
| 123 | |
|
| 124 | |
}); |
| 125 | |
|
| 126 | 0 | this.attributes = attributeMergeResult.getMergedList(); |
| 127 | |
|
| 128 | 0 | orphanData.addAll(attributeMergeResult.getOrphanList()); |
| 129 | |
|
| 130 | 0 | EntityMergeHelper<LprResultValueGroupEntity, String> resultValueGroupMergeHelper = new EntityMergeHelper<LprResultValueGroupEntity, String>(); |
| 131 | |
|
| 132 | 0 | EntityMergeResult<LprResultValueGroupEntity> resultValueGroupMergeResult = resultValueGroupMergeHelper |
| 133 | |
.mergeStringList(this.resultValueGroups, |
| 134 | |
dto.getResultValuesGroupKeys(), |
| 135 | 0 | new StringMergeOptions<LprResultValueGroupEntity>() { |
| 136 | |
|
| 137 | |
@Override |
| 138 | |
public String getKey( |
| 139 | |
LprResultValueGroupEntity entity) { |
| 140 | 0 | return entity.getResultValueGroupId(); |
| 141 | |
} |
| 142 | |
|
| 143 | |
@Override |
| 144 | |
public LprResultValueGroupEntity create(String value) { |
| 145 | |
|
| 146 | 0 | LprResultValueGroupEntity entity = new LprResultValueGroupEntity(); |
| 147 | |
|
| 148 | 0 | entity.setResultValueGroupId(value); |
| 149 | |
|
| 150 | 0 | entity.setLpr(LprEntity.this); |
| 151 | |
|
| 152 | 0 | return entity; |
| 153 | |
} |
| 154 | |
|
| 155 | |
}); |
| 156 | |
|
| 157 | 0 | this.resultValueGroups = resultValueGroupMergeResult.getMergedList(); |
| 158 | |
|
| 159 | 0 | orphanData.addAll(resultValueGroupMergeResult.getOrphanList()); |
| 160 | |
|
| 161 | 0 | return orphanData; |
| 162 | |
} |
| 163 | |
|
| 164 | |
public String getPersonId() { |
| 165 | 0 | return personId; |
| 166 | |
} |
| 167 | |
|
| 168 | |
public void setPersonId(String personId) { |
| 169 | 0 | this.personId = personId; |
| 170 | 0 | } |
| 171 | |
|
| 172 | |
public String getLuiId() { |
| 173 | 0 | return luiId; |
| 174 | |
} |
| 175 | |
|
| 176 | |
public void setLuiId(String luiId) { |
| 177 | 0 | this.luiId = luiId; |
| 178 | 0 | } |
| 179 | |
|
| 180 | |
public Date getEffectiveDate() { |
| 181 | 0 | return effectiveDate; |
| 182 | |
} |
| 183 | |
|
| 184 | |
public void setEffectiveDate(Date effectiveDate) { |
| 185 | 0 | this.effectiveDate = effectiveDate; |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
public Date getExpirationDate() { |
| 189 | 0 | return expirationDate; |
| 190 | |
} |
| 191 | |
|
| 192 | |
public void setExpirationDate(Date expirationDate) { |
| 193 | 0 | this.expirationDate = expirationDate; |
| 194 | 0 | } |
| 195 | |
|
| 196 | |
public String getPersonRelationTypeId() { |
| 197 | 0 | return personRelationTypeId; |
| 198 | |
} |
| 199 | |
|
| 200 | |
public void setPersonRelationTypeId(String personRelationTypeId) { |
| 201 | 0 | this.personRelationTypeId = personRelationTypeId; |
| 202 | 0 | } |
| 203 | |
|
| 204 | |
public String getPersonRelationStateId() { |
| 205 | 0 | return personRelationStateId; |
| 206 | |
} |
| 207 | |
|
| 208 | |
public void setPersonRelationStateId(String personRelationStateId) { |
| 209 | 0 | this.personRelationStateId = personRelationStateId; |
| 210 | 0 | } |
| 211 | |
|
| 212 | |
public List<LprAttributeEntity> getAttributes() { |
| 213 | 0 | return attributes; |
| 214 | |
} |
| 215 | |
|
| 216 | |
public void setAttributes(List<LprAttributeEntity> attributes) { |
| 217 | 0 | this.attributes = attributes; |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
public LprInfo toDto() { |
| 221 | 0 | LprInfo lprInfo = new LprInfo(); |
| 222 | 0 | lprInfo.setId(getId()); |
| 223 | 0 | lprInfo.setLuiId(luiId); |
| 224 | 0 | lprInfo.setCommitmentPercent("" + commitmentPercent); |
| 225 | 0 | lprInfo.setPersonId(personId); |
| 226 | 0 | lprInfo.setEffectiveDate(effectiveDate); |
| 227 | 0 | lprInfo.setExpirationDate(expirationDate); |
| 228 | 0 | lprInfo.setTypeKey(personRelationTypeId); |
| 229 | 0 | lprInfo.setStateKey(personRelationStateId); |
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | 0 | List<String> rvGroupIds = new ArrayList<String>(); |
| 234 | 0 | if (null != getResultValueGroups()) { |
| 235 | 0 | for (LprResultValueGroupEntity rvGroup : getResultValueGroups()) { |
| 236 | 0 | rvGroupIds.add(rvGroup.getResultValueGroupId()); |
| 237 | |
} |
| 238 | |
} |
| 239 | 0 | lprInfo.setResultValuesGroupKeys(rvGroupIds); |
| 240 | |
|
| 241 | 0 | lprInfo.setMeta(super.toDTO()); |
| 242 | 0 | List<AttributeInfo> atts = lprInfo.getAttributes(); |
| 243 | 0 | if (getAttributes() != null) { |
| 244 | 0 | for (LprAttributeEntity att : getAttributes()) { |
| 245 | 0 | AttributeInfo attInfo = att.toDto(); |
| 246 | 0 | atts.add(attInfo); |
| 247 | 0 | } |
| 248 | |
} |
| 249 | |
|
| 250 | 0 | return lprInfo; |
| 251 | |
} |
| 252 | |
|
| 253 | |
public List<LprResultValueGroupEntity> getResultValueGroups() { |
| 254 | 0 | return resultValueGroups; |
| 255 | |
} |
| 256 | |
|
| 257 | |
public void setResultValueGroups( |
| 258 | |
List<LprResultValueGroupEntity> resultValueGroups) { |
| 259 | 0 | this.resultValueGroups = resultValueGroups; |
| 260 | 0 | } |
| 261 | |
|
| 262 | |
public BigDecimal getCommitmentPercent() { |
| 263 | 0 | return commitmentPercent; |
| 264 | |
} |
| 265 | |
|
| 266 | |
public void setCommitmentPercent(BigDecimal commitmentPercent) { |
| 267 | 0 | this.commitmentPercent = commitmentPercent; |
| 268 | 0 | } |
| 269 | |
|
| 270 | |
} |