View Javadoc

1   package org.kuali.student.enrollment.class2.courseofferingset.model;
2   
3   import org.kuali.student.r1.common.entity.KSEntityConstants;
4   import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
5   import org.kuali.student.enrollment.courseofferingset.infc.SocRolloverResultItem;
6   import org.kuali.student.r2.common.dto.AttributeInfo;
7   import org.kuali.student.r2.common.entity.AttributeOwner;
8   import org.kuali.student.r2.common.entity.MetaEntity;
9   import org.kuali.student.r2.common.infc.Attribute;
10  import org.kuali.student.r2.common.util.RichTextHelper;
11  
12  import javax.persistence.*;
13  import java.util.HashSet;
14  import java.util.Set;
15  
16  @Entity
17  @Table(name = "KSEN_SOC_ROR_ITEM")
18  @NamedQueries({
19          @NamedQuery(name="SocRorItem.getSocRorItemsBySocType", query="Select a from SocRolloverResultItemEntity a where a.socRorType =:socRorType"),
20          @NamedQuery(name="SocRorItem.getSocRorItemsBySocRorId", query="Select a from SocRolloverResultItemEntity a where a.socRolloverResultId=:socRolloverResultId"),
21          @NamedQuery(name="SocRor.getSocRorItemsBySocRorIdAndSourceCourseOfferingId", query="Select a from SocRolloverResultItemEntity a where a.socRolloverResultId=:socRolloverResultId and a.sourceCourseOfferingId=:sourceCourseOfferingId"),
22          @NamedQuery(name="SocRor.getSocRorItemsBySocRorIdAndTargetCourseOfferingId", query="Select a from SocRolloverResultItemEntity a where a.socRolloverResultId=:socRolloverResultId and a.targetCourseOfferingId=:targetCourseOfferingId")
23  })
24  public class SocRolloverResultItemEntity extends MetaEntity implements AttributeOwner<SocRolloverResultItemAttributeEntity> {
25  
26      @Column(name = "ROR_ID")
27      private String socRolloverResultId;
28      @Column(name = "SOC_ROR_TYPE", nullable = false)
29      private String socRorType;
30      @Column(name = "SOC_ROR_STATE", nullable = false)
31      private String socRorState;
32      @Column(name = "SOURCE_CO_ID")
33      private String sourceCourseOfferingId;
34      @Column(name = "TARGET_CO_ID")
35      private String targetCourseOfferingId;
36      @Column(name = "MESG_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
37      private String mesgFormatted;
38      @Column(name = "MESG_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
39      private String mesgPlain;
40      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner", fetch = FetchType.EAGER, orphanRemoval = true)
41      private final Set<SocRolloverResultItemAttributeEntity> attributes = new HashSet<SocRolloverResultItemAttributeEntity>();
42  
43      public SocRolloverResultItemEntity() {
44      }
45  
46      public SocRolloverResultItemEntity(SocRolloverResultItem item) {
47          super(item);
48          this.setId(item.getId());
49          this.setSocRolloverResultId(item.getSocRolloverResultId());
50          this.setSocRorType(item.getTypeKey());
51          this.fromDTO(item);
52      }
53  
54      public void fromDTO(SocRolloverResultItem item) {
55          this.setSocRorState(item.getStateKey());
56          this.setSourceCourseOfferingId(item.getSourceCourseOfferingId());
57          this.setTargetCourseOfferingId(item.getTargetCourseOfferingId());
58          if (item.getMessage() != null) {
59              this.setMesgFormatted(item.getMessage().getFormatted());
60              this.setMesgPlain(item.getMessage().getPlain());
61          } else {
62              this.setMesgFormatted(null);
63              this.setMesgPlain(null);
64          }
65          this.setAttributes(new HashSet<SocRolloverResultItemAttributeEntity>());
66          for (Attribute att : item.getAttributes()) {
67              this.getAttributes().add(new SocRolloverResultItemAttributeEntity(att, this));
68          }
69      }
70  
71  
72      public SocRolloverResultItemInfo toDto() {
73          SocRolloverResultItemInfo info = new SocRolloverResultItemInfo();
74          info.setId(getId());
75          info.setTypeKey(socRorType);
76          info.setStateKey(socRorState);
77          info.setSocRolloverResultId(socRolloverResultId);
78          info.setSourceCourseOfferingId(sourceCourseOfferingId);
79          info.setTargetCourseOfferingId(targetCourseOfferingId);
80          info.setMessage(new RichTextHelper().toRichTextInfo(getMesgPlain(), getMesgFormatted()));
81          info.setMeta(super.toDTO());
82          if (getAttributes() != null) {
83              for (SocRolloverResultItemAttributeEntity att : getAttributes()) {
84                  AttributeInfo attInfo = att.toDto();
85                  info.getAttributes().add(attInfo);
86              }
87          }
88  
89          return info;
90      }
91  
92      
93  
94      public String getMesgFormatted() {
95          return mesgFormatted;
96      }
97  
98      public void setMesgFormatted(String mesgFormatted) {
99          this.mesgFormatted = mesgFormatted;
100     }
101 
102     public String getMesgPlain() {
103         return mesgPlain;
104     }
105 
106     public void setMesgPlain(String mesgPlain) {
107         this.mesgPlain = mesgPlain;
108     }
109 
110     public String getSocRolloverResultId() {
111         return socRolloverResultId;
112     }
113 
114     public void setSocRolloverResultId(String socRolloverResultId) {
115         this.socRolloverResultId = socRolloverResultId;
116     }
117 
118     public String getSocRorState() {
119         return socRorState;
120     }
121 
122     public void setSocRorState(String socRorState) {
123         this.socRorState = socRorState;
124     }
125 
126     public String getSocRorType() {
127         return socRorType;
128     }
129 
130     public void setSocRorType(String socRorType) {
131         this.socRorType = socRorType;
132     }
133 
134     public String getSourceCourseOfferingId() {
135         return sourceCourseOfferingId;
136     }
137 
138     public void setSourceCourseOfferingId(String sourceCourseOfferingId) {
139         this.sourceCourseOfferingId = sourceCourseOfferingId;
140     }
141 
142     public String getTargetCourseOfferingId() {
143         return targetCourseOfferingId;
144     }
145 
146     public void setTargetCourseOfferingId(String targetCourseOfferingId) {
147         this.targetCourseOfferingId = targetCourseOfferingId;
148     }
149 
150     public Set<SocRolloverResultItemAttributeEntity> getAttributes() {
151         return attributes;
152     }
153 
154     public void setAttributes(Set<SocRolloverResultItemAttributeEntity> attributes) {
155         this.attributes.clear();
156         if (attributes != null) {
157             this.attributes.addAll(attributes);
158         }
159     }
160 
161     
162 }