| 1 | |
package org.kuali.student.r2.core.process.model; |
| 2 | |
|
| 3 | |
import java.util.ArrayList; |
| 4 | |
import java.util.List; |
| 5 | |
|
| 6 | |
import javax.persistence.CascadeType; |
| 7 | |
import javax.persistence.Column; |
| 8 | |
import javax.persistence.Entity; |
| 9 | |
import javax.persistence.JoinColumn; |
| 10 | |
import javax.persistence.ManyToOne; |
| 11 | |
import javax.persistence.OneToMany; |
| 12 | |
import javax.persistence.Table; |
| 13 | |
|
| 14 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 15 | |
import org.kuali.student.r2.common.entity.AttributeOwner; |
| 16 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 17 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 18 | |
import org.kuali.student.r2.core.class1.state.model.StateEntity; |
| 19 | |
import org.kuali.student.r2.core.process.dto.ProcessInfo; |
| 20 | |
import org.kuali.student.r2.core.process.infc.Process; |
| 21 | |
|
| 22 | |
@Entity |
| 23 | |
@Table(name = "KSEN_PROCESS") |
| 24 | |
public class ProcessEntity extends MetaEntity implements AttributeOwner<ProcessAttributeEntity>{ |
| 25 | |
|
| 26 | |
@Column(name = "NAME") |
| 27 | |
private String name; |
| 28 | |
|
| 29 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 30 | |
@JoinColumn(name = "RT_DESCR_ID") |
| 31 | |
private ProcessRichTextEntity descr; |
| 32 | |
|
| 33 | |
@ManyToOne(optional=false) |
| 34 | |
@JoinColumn(name = "STATE_ID") |
| 35 | |
private StateEntity processState; |
| 36 | |
|
| 37 | |
@ManyToOne(optional=false) |
| 38 | |
@JoinColumn(name = "TYPE_ID") |
| 39 | |
private ProcessTypeEntity processType; |
| 40 | |
|
| 41 | |
@Column(name = "OWNER_ORG_ID") |
| 42 | |
private String ownerOrgID; |
| 43 | |
|
| 44 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner",orphanRemoval = true) |
| 45 | |
private List<ProcessAttributeEntity> attributes; |
| 46 | |
|
| 47 | 0 | public ProcessEntity(){ |
| 48 | |
|
| 49 | 0 | } |
| 50 | |
|
| 51 | |
public ProcessEntity(Process process){ |
| 52 | 0 | super(process); |
| 53 | |
|
| 54 | 0 | this.setId(process.getKey()); |
| 55 | 0 | this.setName(process.getName()); |
| 56 | |
|
| 57 | 0 | if(process.getDescr() != null) { |
| 58 | 0 | this.setDescr(new ProcessRichTextEntity(process.getDescr())); |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | this.setOwnerOrgID(process.getOwnerOrgId()); |
| 62 | |
|
| 63 | 0 | this.setAttributes(new ArrayList<ProcessAttributeEntity>()); |
| 64 | 0 | if (null != process.getAttributes()) { |
| 65 | 0 | for (Attribute att : process.getAttributes()) { |
| 66 | 0 | ProcessAttributeEntity attEntity = new ProcessAttributeEntity(att); |
| 67 | 0 | this.getAttributes().add(attEntity); |
| 68 | 0 | } |
| 69 | |
} |
| 70 | |
|
| 71 | 0 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public ProcessInfo toDto(){ |
| 77 | |
|
| 78 | 0 | ProcessInfo obj = new ProcessInfo(); |
| 79 | |
|
| 80 | 0 | obj.setKey(getId()); |
| 81 | 0 | obj.setName(name); |
| 82 | 0 | obj.setOwnerOrgId(getOwnerOrgID()); |
| 83 | |
|
| 84 | 0 | if (processType != null){ |
| 85 | 0 | obj.setTypeKey(processType.getId()); |
| 86 | |
} |
| 87 | |
|
| 88 | 0 | if (processState != null){ |
| 89 | 0 | obj.setStateKey(processState.getId()); |
| 90 | |
} |
| 91 | |
|
| 92 | 0 | obj.setMeta(super.toDTO()); |
| 93 | |
|
| 94 | 0 | if (descr != null){ |
| 95 | 0 | obj.setDescr(descr.toDto()); |
| 96 | |
} |
| 97 | |
|
| 98 | 0 | List<AttributeInfo> atts = new ArrayList<AttributeInfo>(); |
| 99 | 0 | for (ProcessAttributeEntity att : getAttributes()) { |
| 100 | 0 | AttributeInfo attInfo = att.toDto(); |
| 101 | 0 | atts.add(attInfo); |
| 102 | 0 | } |
| 103 | 0 | obj.setAttributes(atts); |
| 104 | |
|
| 105 | 0 | return obj; |
| 106 | |
} |
| 107 | |
|
| 108 | |
|
| 109 | 0 | public String getName() { return name; } |
| 110 | 0 | public void setName(String name) { this.name = name; } |
| 111 | |
|
| 112 | |
|
| 113 | 0 | public ProcessRichTextEntity getDescr() { return descr; } |
| 114 | 0 | public void setDescr(ProcessRichTextEntity descr) { this.descr = descr; } |
| 115 | |
|
| 116 | |
|
| 117 | |
public StateEntity getProcessState() { |
| 118 | 0 | return processState; |
| 119 | |
} |
| 120 | |
public void setProcessState(StateEntity processState) { |
| 121 | 0 | this.processState = processState; |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
|
| 125 | |
public ProcessTypeEntity getProcessType() { |
| 126 | 0 | return processType; |
| 127 | |
} |
| 128 | |
public void setProcessType(ProcessTypeEntity processType) { |
| 129 | 0 | this.processType = processType; |
| 130 | 0 | } |
| 131 | |
|
| 132 | |
|
| 133 | 0 | public String getOwnerOrgID() { return ownerOrgID; } |
| 134 | 0 | public void setOwnerOrgID(String ownerOrgID) { this.ownerOrgID = ownerOrgID; } |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public List<ProcessAttributeEntity> getAttributes() { |
| 138 | 0 | return attributes; |
| 139 | |
} |
| 140 | |
|
| 141 | |
@Override |
| 142 | |
public void setAttributes(List<ProcessAttributeEntity> attributes) { |
| 143 | 0 | this.attributes = attributes; |
| 144 | 0 | } |
| 145 | |
} |