| 1 | |
package org.kuali.student.r2.core.classI.atp.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.FetchType; |
| 11 | |
import javax.persistence.JoinColumn; |
| 12 | |
import javax.persistence.ManyToOne; |
| 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.r2.common.entity.AttributeOwner; |
| 19 | |
import org.kuali.student.r2.common.entity.MetaEntity; |
| 20 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 21 | |
import org.kuali.student.r2.core.atp.dto.MilestoneInfo; |
| 22 | |
import org.kuali.student.r2.core.atp.infc.Milestone; |
| 23 | |
|
| 24 | |
@Entity |
| 25 | |
@Table(name = "KSEN_MSTONE") |
| 26 | |
public class MilestoneEntity extends MetaEntity implements AttributeOwner<AtpAttributeEntity> { |
| 27 | |
|
| 28 | |
@Column(name = "NAME") |
| 29 | |
private String name; |
| 30 | |
|
| 31 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 32 | |
@JoinColumn(name = "RT_DESCR_ID") |
| 33 | |
private AtpRichTextEntity descr; |
| 34 | |
|
| 35 | |
@Temporal(TemporalType.TIMESTAMP) |
| 36 | |
@Column(name = "START_DT") |
| 37 | |
private Date startDate; |
| 38 | |
|
| 39 | |
@Temporal(TemporalType.TIMESTAMP) |
| 40 | |
@Column(name = "END_DT") |
| 41 | |
private Date endDate; |
| 42 | |
|
| 43 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 44 | |
@JoinColumn(name = "MILESTONE_TYPE_ID") |
| 45 | |
private MilestoneTypeEntity milestoneType; |
| 46 | |
|
| 47 | |
@ManyToOne(cascade = CascadeType.ALL) |
| 48 | |
@JoinColumn(name = "MILESTONE_STATE_ID") |
| 49 | |
private AtpStateEntity atpState; |
| 50 | |
|
| 51 | |
@Column(name="IS_ALL_DAY") |
| 52 | |
private boolean isAllDay; |
| 53 | |
|
| 54 | |
@Column(name="IS_DATE_RANGE") |
| 55 | |
private boolean isDateRange; |
| 56 | |
|
| 57 | |
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER) |
| 58 | |
private List<AtpAttributeEntity> attributes; |
| 59 | |
|
| 60 | 0 | public MilestoneEntity() { |
| 61 | 0 | } |
| 62 | |
|
| 63 | 0 | public MilestoneEntity(Milestone milestone) { |
| 64 | 0 | this.setId(milestone.getKey()); |
| 65 | 0 | this.name = milestone.getName(); |
| 66 | |
|
| 67 | 0 | this.startDate = milestone.getStartDate(); |
| 68 | 0 | this.endDate = milestone.getEndDate(); |
| 69 | |
|
| 70 | 0 | if(milestone.getDescr() != null) { |
| 71 | 0 | this.descr = new AtpRichTextEntity(milestone.getDescr()); |
| 72 | |
} |
| 73 | |
|
| 74 | 0 | this.setAttributes(new ArrayList<AtpAttributeEntity>()); |
| 75 | 0 | if (null != milestone.getAttributes()) { |
| 76 | 0 | for (Attribute att : milestone.getAttributes()) { |
| 77 | 0 | this.getAttributes().add(new AtpAttributeEntity(att)); |
| 78 | |
} |
| 79 | |
} |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
public String getName() { |
| 83 | 0 | return name; |
| 84 | |
} |
| 85 | |
|
| 86 | |
public void setName(String name) { |
| 87 | 0 | this.name = name; |
| 88 | 0 | } |
| 89 | |
|
| 90 | |
public AtpRichTextEntity getDescr() { |
| 91 | 0 | return descr; |
| 92 | |
} |
| 93 | |
|
| 94 | |
public void setDescr(AtpRichTextEntity descr) { |
| 95 | 0 | this.descr = descr; |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
public Date getStartDate() { |
| 99 | 0 | return startDate; |
| 100 | |
} |
| 101 | |
|
| 102 | |
public void setStartDate(Date startDate) { |
| 103 | 0 | this.startDate = startDate; |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
public Date getEndDate() { |
| 107 | 0 | return endDate; |
| 108 | |
} |
| 109 | |
|
| 110 | |
public void setEndDate(Date endDate) { |
| 111 | 0 | this.endDate = endDate; |
| 112 | 0 | } |
| 113 | |
|
| 114 | |
public MilestoneTypeEntity getMilestoneType() { |
| 115 | 0 | return milestoneType; |
| 116 | |
} |
| 117 | |
|
| 118 | |
public void setMilestoneType(MilestoneTypeEntity atpType) { |
| 119 | 0 | this.milestoneType = atpType; |
| 120 | 0 | } |
| 121 | |
|
| 122 | |
public AtpStateEntity getAtpState() { |
| 123 | 0 | return atpState; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public void setAtpState(AtpStateEntity atpState) { |
| 127 | 0 | this.atpState = atpState; |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
public boolean isAllDay() { |
| 131 | 0 | return isAllDay; |
| 132 | |
} |
| 133 | |
|
| 134 | |
public void setAllDay(boolean isAllDay) { |
| 135 | 0 | this.isAllDay = isAllDay; |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
public boolean isDateRange() { |
| 139 | 0 | return isDateRange; |
| 140 | |
} |
| 141 | |
|
| 142 | |
public void setDateRange(boolean isDateRange) { |
| 143 | 0 | this.isDateRange = isDateRange; |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
@Override |
| 147 | |
public void setAttributes(List<AtpAttributeEntity> attributes) { |
| 148 | 0 | this.attributes = attributes; |
| 149 | |
|
| 150 | 0 | } |
| 151 | |
|
| 152 | |
@Override |
| 153 | |
public List<AtpAttributeEntity> getAttributes() { |
| 154 | 0 | return attributes; |
| 155 | |
} |
| 156 | |
|
| 157 | |
public MilestoneInfo toDto() { |
| 158 | 0 | MilestoneInfo info = MilestoneInfo.newInstance(); |
| 159 | |
|
| 160 | 0 | info.setKey(getId()); |
| 161 | 0 | info.setName(getName()); |
| 162 | 0 | info.setDescr(getDescr().toDto()); |
| 163 | 0 | info.setTypeKey(getMilestoneType().getId()); |
| 164 | 0 | info.setStateKey(getAtpState().getId()); |
| 165 | 0 | info.setStartDate(getStartDate()); |
| 166 | 0 | info.setEndDate(getEndDate()); |
| 167 | 0 | info.setAllDay(isAllDay()); |
| 168 | 0 | info.setDateRange(isDateRange()); |
| 169 | |
|
| 170 | 0 | List<Attribute> atts = new ArrayList<Attribute>(); |
| 171 | 0 | for (AtpAttributeEntity att : getAttributes()) { |
| 172 | 0 | Attribute attInfo = att.toDto(); |
| 173 | 0 | atts.add(attInfo); |
| 174 | 0 | } |
| 175 | 0 | info.setAttributes(atts); |
| 176 | |
|
| 177 | 0 | return info; |
| 178 | |
} |
| 179 | |
|
| 180 | |
} |