| 1 | |
package org.kuali.student.r2.core.class1.process.model; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.Date; |
| 5 | |
import java.util.List; |
| 6 | |
|
| 7 | |
import javax.persistence.CascadeType; |
| 8 | |
import javax.persistence.Column; |
| 9 | |
import javax.persistence.Entity; |
| 10 | |
import javax.persistence.JoinColumn; |
| 11 | |
import javax.persistence.JoinTable; |
| 12 | |
import javax.persistence.ManyToMany; |
| 13 | |
import javax.persistence.ManyToOne; |
| 14 | |
import javax.persistence.OneToMany; |
| 15 | |
import javax.persistence.Table; |
| 16 | |
import javax.persistence.Temporal; |
| 17 | |
import javax.persistence.TemporalType; |
| 18 | |
import javax.persistence.Transient; |
| 19 | |
|
| 20 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 21 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
| 22 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 23 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 24 | |
import org.kuali.student.r2.core.class1.population.model.PopulationEntity; |
| 25 | |
import org.kuali.student.r2.core.process.dto.InstructionInfo; |
| 26 | |
import org.kuali.student.r2.core.process.infc.Instruction; |
| 27 | |
|
| 28 | |
@Entity |
| 29 | |
@Table(name = "KSEN_INSTR") |
| 30 | |
public class InstructionEntity extends MetaEntity implements AttributeOwner<InstructionAttributeEntity> { |
| 31 | |
|
| 32 | |
@Temporal(TemporalType.TIMESTAMP) |
| 33 | |
@Column(name = "EFF_DT") |
| 34 | |
private Date effectiveDate; |
| 35 | |
|
| 36 | |
@Temporal(TemporalType.TIMESTAMP) |
| 37 | |
@Column(name = "EXPIR_DT") |
| 38 | |
private Date expirationDate; |
| 39 | |
|
| 40 | |
@Column(name = "INSTRUCTION_TYPE") |
| 41 | |
private String instructionType; |
| 42 | |
|
| 43 | |
@Column(name = "INSTRUCTION_STATE") |
| 44 | |
private String instructionState; |
| 45 | |
|
| 46 | |
@ManyToOne(optional = false) |
| 47 | |
@JoinColumn(name = "PROCESS_ID") |
| 48 | |
private ProcessEntity process; |
| 49 | |
|
| 50 | |
@ManyToOne(optional = false) |
| 51 | |
@JoinColumn(name = "CHECK_ID") |
| 52 | |
private CheckEntity check; |
| 53 | |
|
| 54 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 55 | |
@JoinColumn(name = "MESSAGE") |
| 56 | |
private InstructionMessageEntity message; |
| 57 | |
|
| 58 | |
@Column(name = "POSITION") |
| 59 | |
private int position; |
| 60 | |
|
| 61 | |
@Column(name = "IS_WARNING") |
| 62 | |
private boolean warning; |
| 63 | |
|
| 64 | |
@Column(name = "CONTINUE_ON_FAIL") |
| 65 | |
private boolean continueOnFail; |
| 66 | |
|
| 67 | |
@Column(name = "IS_EXEMPTABLE") |
| 68 | |
private boolean exemptable; |
| 69 | |
|
| 70 | |
@ManyToMany(cascade = CascadeType.ALL) |
| 71 | |
@JoinTable(name = "KSEN_INSTR_POPLTN_RELTN", joinColumns = @JoinColumn(name = "INSTR_ID"), inverseJoinColumns = @JoinColumn(name = "POPLTN_ID")) |
| 72 | |
private List<PopulationEntity> appliedPopulation; |
| 73 | |
|
| 74 | |
@Transient |
| 75 | |
private List<String> appliedAtpTypes; |
| 76 | |
|
| 77 | 0 | @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", orphanRemoval = true) |
| 78 | |
private List<InstructionAttributeEntity> attributes = new ArrayList<InstructionAttributeEntity>(); |
| 79 | |
|
| 80 | 0 | public InstructionEntity() {} |
| 81 | |
|
| 82 | |
public InstructionEntity(Instruction dto) { |
| 83 | 0 | super(dto); |
| 84 | |
|
| 85 | 0 | setId(dto.getId()); |
| 86 | 0 | setContinueOnFail(dto.getContinueOnFail()); |
| 87 | 0 | setExemptable(dto.getIsExemptable()); |
| 88 | 0 | setPosition(dto.getPosition()); |
| 89 | 0 | setWarning(dto.getIsWarning()); |
| 90 | 0 | this.setInstructionState(dto.getStateKey()); |
| 91 | 0 | if (dto.getExpirationDate() != null) { |
| 92 | 0 | setExpirationDate(dto.getExpirationDate()); |
| 93 | |
} |
| 94 | |
|
| 95 | 0 | if (dto.getEffectiveDate() != null) { |
| 96 | 0 | setEffectiveDate(dto.getEffectiveDate()); |
| 97 | |
} |
| 98 | |
|
| 99 | 0 | if (dto.getMessage() != null) { |
| 100 | 0 | this.setMessage(new InstructionMessageEntity(dto.getMessage())); |
| 101 | |
} |
| 102 | 0 | this.setAttributes(new ArrayList<InstructionAttributeEntity>()); |
| 103 | 0 | if (null != dto.getAttributes()) { |
| 104 | 0 | for (Attribute att : dto.getAttributes()) { |
| 105 | 0 | this.getAttributes().add(new InstructionAttributeEntity(att, this)); |
| 106 | |
} |
| 107 | |
} |
| 108 | |
|
| 109 | 0 | } |
| 110 | |
|
| 111 | |
public InstructionInfo toDto() { |
| 112 | |
|
| 113 | 0 | InstructionInfo dto = new InstructionInfo(); |
| 114 | |
|
| 115 | 0 | dto.setId(getId()); |
| 116 | 0 | dto.setContinueOnFail(isContinueOnFail()); |
| 117 | 0 | dto.setPosition(getPosition()); |
| 118 | 0 | dto.setIsExemptable(isExemptable()); |
| 119 | 0 | dto.setIsWarning(isWarning()); |
| 120 | |
|
| 121 | 0 | if (getEffectiveDate() != null) { |
| 122 | 0 | dto.setEffectiveDate(getEffectiveDate()); |
| 123 | |
} |
| 124 | |
|
| 125 | 0 | if (getExpirationDate() != null) { |
| 126 | 0 | dto.setExpirationDate(getExpirationDate()); |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | if (getInstructionState() != null) { |
| 130 | 0 | dto.setStateKey(getInstructionState()); |
| 131 | |
} |
| 132 | |
|
| 133 | 0 | if (getProcess() != null) { |
| 134 | 0 | dto.setProcessKey(getProcess().getId()); |
| 135 | |
} |
| 136 | |
|
| 137 | 0 | if (getCheck() != null) { |
| 138 | 0 | dto.setCheckKey(getCheck().getId()); |
| 139 | |
} |
| 140 | |
|
| 141 | 0 | if (getInstructionType() != null) { |
| 142 | 0 | dto.setTypeKey(getInstructionType()); |
| 143 | |
} |
| 144 | |
|
| 145 | 0 | List<String> appliedPopulation = new ArrayList<String>(); |
| 146 | 0 | if (getAppliedPopulation() != null) { |
| 147 | 0 | for (PopulationEntity population : getAppliedPopulation()) { |
| 148 | 0 | appliedPopulation.add(population.getId()); |
| 149 | |
} |
| 150 | |
} |
| 151 | 0 | dto.setAppliedPopulationKeys(appliedPopulation); |
| 152 | |
|
| 153 | 0 | List<String> appliedAtpTypeKeys = new ArrayList<String>(); |
| 154 | 0 | if (getAppliedAtpTypes() != null) { |
| 155 | 0 | for (String atpType : getAppliedAtpTypes()) { |
| 156 | 0 | appliedAtpTypeKeys.add(atpType); |
| 157 | |
} |
| 158 | |
} |
| 159 | 0 | dto.setAppliedAtpTypeKeys(appliedAtpTypeKeys); |
| 160 | |
|
| 161 | 0 | dto.setMeta(super.toDTO()); |
| 162 | 0 | if (getMessage() != null) { |
| 163 | 0 | dto.setMessage(message.toDto()); |
| 164 | |
} |
| 165 | |
|
| 166 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
| 167 | 0 | for (InstructionAttributeEntity att : getAttributes()) { |
| 168 | 0 | AttributeInfo attInfo = att.toDto(); |
| 169 | 0 | atts.add(attInfo); |
| 170 | 0 | } |
| 171 | 0 | dto.setAttributes(atts); |
| 172 | |
|
| 173 | 0 | return dto; |
| 174 | |
} |
| 175 | |
|
| 176 | |
public Date getEffectiveDate() { |
| 177 | 0 | return effectiveDate; |
| 178 | |
} |
| 179 | |
|
| 180 | |
public void setEffectiveDate(Date effectiveDate) { |
| 181 | 0 | this.effectiveDate = effectiveDate; |
| 182 | 0 | } |
| 183 | |
|
| 184 | |
public Date getExpirationDate() { |
| 185 | 0 | return expirationDate; |
| 186 | |
} |
| 187 | |
|
| 188 | |
public void setExpirationDate(Date expirationDate) { |
| 189 | 0 | this.expirationDate = expirationDate; |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
public String getInstructionType() { |
| 193 | 0 | return instructionType; |
| 194 | |
} |
| 195 | |
|
| 196 | |
public void setInstructionType(String instructionType) { |
| 197 | 0 | this.instructionType = instructionType; |
| 198 | 0 | } |
| 199 | |
|
| 200 | |
public String getInstructionState() { |
| 201 | 0 | return instructionState; |
| 202 | |
} |
| 203 | |
|
| 204 | |
public void setInstructionState(String instructionState) { |
| 205 | 0 | this.instructionState = instructionState; |
| 206 | 0 | } |
| 207 | |
|
| 208 | |
public ProcessEntity getProcess() { |
| 209 | 0 | return process; |
| 210 | |
} |
| 211 | |
|
| 212 | |
public void setProcess(ProcessEntity process) { |
| 213 | 0 | this.process = process; |
| 214 | 0 | } |
| 215 | |
|
| 216 | |
public CheckEntity getCheck() { |
| 217 | 0 | return check; |
| 218 | |
} |
| 219 | |
|
| 220 | |
public void setCheck(CheckEntity check) { |
| 221 | 0 | this.check = check; |
| 222 | 0 | } |
| 223 | |
|
| 224 | |
public InstructionMessageEntity getMessage() { |
| 225 | 0 | return message; |
| 226 | |
} |
| 227 | |
|
| 228 | |
public void setMessage(InstructionMessageEntity message) { |
| 229 | 0 | this.message = message; |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
public int getPosition() { |
| 233 | 0 | return position; |
| 234 | |
} |
| 235 | |
|
| 236 | |
public void setPosition(int position) { |
| 237 | 0 | this.position = position; |
| 238 | 0 | } |
| 239 | |
|
| 240 | |
public boolean isWarning() { |
| 241 | 0 | return warning; |
| 242 | |
} |
| 243 | |
|
| 244 | |
public void setWarning(boolean warning) { |
| 245 | 0 | this.warning = warning; |
| 246 | 0 | } |
| 247 | |
|
| 248 | |
public boolean isContinueOnFail() { |
| 249 | 0 | return continueOnFail; |
| 250 | |
} |
| 251 | |
|
| 252 | |
public void setContinueOnFail(boolean continueOnFail) { |
| 253 | 0 | this.continueOnFail = continueOnFail; |
| 254 | 0 | } |
| 255 | |
|
| 256 | |
public boolean isExemptable() { |
| 257 | 0 | return exemptable; |
| 258 | |
} |
| 259 | |
|
| 260 | |
public void setExemptable(boolean exemptable) { |
| 261 | 0 | this.exemptable = exemptable; |
| 262 | 0 | } |
| 263 | |
|
| 264 | |
public List<PopulationEntity> getAppliedPopulation() { |
| 265 | 0 | return appliedPopulation; |
| 266 | |
} |
| 267 | |
|
| 268 | |
public void setAppliedPopulation(List<PopulationEntity> appliedPopulation) { |
| 269 | 0 | this.appliedPopulation = appliedPopulation; |
| 270 | 0 | } |
| 271 | |
|
| 272 | |
public List<String> getAppliedAtpTypes() { |
| 273 | 0 | return appliedAtpTypes; |
| 274 | |
} |
| 275 | |
|
| 276 | |
public void setAppliedAtpTypes(List<String> appliedAtpTypes) { |
| 277 | 0 | this.appliedAtpTypes = appliedAtpTypes; |
| 278 | 0 | } |
| 279 | |
|
| 280 | |
@Override |
| 281 | |
public void setAttributes(List<InstructionAttributeEntity> attributes) { |
| 282 | 0 | this.attributes = attributes; |
| 283 | 0 | } |
| 284 | |
|
| 285 | |
@Override |
| 286 | |
public List<InstructionAttributeEntity> getAttributes() { |
| 287 | 0 | return attributes; |
| 288 | |
} |
| 289 | |
} |