View Javadoc

1   /**
2    * Copyright 2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by venkat on 1/22/13
16   */
17  package org.kuali.student.enrollment.class1.lui.model;
18  
19  import org.kuali.student.enrollment.lui.dto.LuiSetInfo;
20  import org.kuali.student.enrollment.lui.infc.LuiSet;
21  import org.kuali.student.r1.common.entity.KSEntityConstants;
22  import org.kuali.student.r2.common.assembler.TransformUtility;
23  import org.kuali.student.r2.common.entity.AttributeOwner;
24  import org.kuali.student.r2.common.entity.MetaEntity;
25  import org.kuali.student.r2.common.infc.Attribute;
26  import org.kuali.student.r2.common.util.RichTextHelper;
27  
28  import javax.persistence.CascadeType;
29  import javax.persistence.CollectionTable;
30  import javax.persistence.Column;
31  import javax.persistence.ElementCollection;
32  import javax.persistence.Entity;
33  import javax.persistence.FetchType;
34  import javax.persistence.JoinColumn;
35  import javax.persistence.NamedQueries;
36  import javax.persistence.NamedQuery;
37  import javax.persistence.OneToMany;
38  import javax.persistence.Table;
39  import java.util.ArrayList;
40  import java.util.HashSet;
41  import java.util.List;
42  import java.util.Set;
43  
44  /**
45   * This is the entity representation for <code>KSEN_LUI_SET</code> table. And, this is mapped with the dto <code>LuiSetInfo</code>
46   * at class1. This entity isn't currently used.
47   *
48   * @author Kuali Student Team
49   */
50  @Entity
51  @Table(name = "KSEN_LUI_SET")
52  @NamedQueries({
53      @NamedQuery(name="LuiSet.getLuiSetIdsByType", query="Select luiSetEntity.id from LuiSetEntity luiSetEntity where luiSetEntity.luiSetType =:typeKey"),
54      @NamedQuery(name="LuiSet.getLuiSetsByLui", query="Select luiSetEntity from LuiSetEntity luiSetEntity where :lui in elements(luiSetEntity.luiIds)")
55  })
56  public class LuiSetEntity extends MetaEntity implements AttributeOwner<LuiSetAttributeEntity> {
57  
58      @Column(name = "NAME")
59      private String name;
60  
61      @Column(name = "DESCR_FORMATTED", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
62      private String descrFormatted;
63  
64      @Column(name = "DESCR_PLAIN", length = KSEntityConstants.EXTRA_LONG_TEXT_LENGTH)
65      private String descrPlain;
66  
67      @Column(name = "LUI_SET_TYPE")
68      private String luiSetType;
69  
70      @Column(name = "LUI_SET_STATE")
71      private String luiSetState;
72  
73      @ElementCollection(fetch = FetchType.EAGER)
74      @CollectionTable(name ="KSEN_LUI_SET_LUI",joinColumns = @JoinColumn(name = "LUI_SET_ID"))
75      @Column(name="LUI_ID")
76      private List<String> luiIds = new ArrayList<String>();
77  
78      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner",orphanRemoval=true, fetch = FetchType.EAGER)
79      private Set<LuiSetAttributeEntity> attributes = new HashSet<LuiSetAttributeEntity>();
80  
81      public LuiSetEntity() {
82      }
83  
84      public LuiSetEntity(LuiSet luiSet) {
85          super(luiSet);
86          this.setId(luiSet.getId());
87          fromDto(luiSet);
88      }
89  
90      public void fromDto(LuiSet luiSet) {
91  
92          this.setLuiSetType(luiSet.getTypeKey());
93          this.setLuiSetState(luiSet.getStateKey());
94          this.setName(luiSet.getName());
95          this.getLuiIds().clear();
96          this.getLuiIds().addAll(luiSet.getLuiIds());
97  
98          this.getAttributes().clear();
99          for (Attribute attributeInfo : luiSet.getAttributes()) {
100             LuiSetAttributeEntity luiSetAttributeEntity = new LuiSetAttributeEntity(attributeInfo,this);
101             this.getAttributes().add(luiSetAttributeEntity);
102         }
103 
104         if (luiSet.getDescr() == null) {
105             this.setDescrFormatted(null);
106             this.setDescrPlain(null);
107         } else {
108             this.setDescrFormatted(luiSet.getDescr().getFormatted());
109             this.setDescrPlain(luiSet.getDescr().getPlain());
110         }
111     }
112 
113     public LuiSetInfo toDto() {
114 
115         LuiSetInfo luiSetInfo = new LuiSetInfo();
116 
117         luiSetInfo.setId(getId());
118         luiSetInfo.setName(getName());
119         luiSetInfo.setTypeKey(getLuiSetType());
120         luiSetInfo.setStateKey(getLuiSetState());
121         luiSetInfo.setMeta(super.toDTO());
122         luiSetInfo.setDescr(new RichTextHelper().toRichTextInfo(descrPlain, descrFormatted));
123 
124         if (luiSetInfo.getLuiIds() == null){
125             luiSetInfo.setLuiIds(new ArrayList<String>());
126         }
127 
128         luiSetInfo.getLuiIds().addAll(luiIds);
129 
130         luiSetInfo.setAttributes(TransformUtility.toAttributeInfoList(this));
131 
132         return luiSetInfo;
133     }
134 
135     public String getName() {
136         return name;
137     }
138 
139     public void setName(String name) {
140         this.name = name;
141     }
142 
143     public String getLuiSetType() {
144         return luiSetType;
145     }
146 
147     public void setLuiSetType(String luiSetType) {
148         this.luiSetType = luiSetType;
149     }
150 
151     public String getLuiSetState() {
152         return luiSetState;
153     }
154 
155     public void setLuiSetState(String luiSetState) {
156         this.luiSetState = luiSetState;
157     }
158 
159     public List<String> getLuiIds() {
160         return luiIds;
161     }
162 
163     public void setLuiIds(List<String> luiIds) {
164         this.luiIds = luiIds;
165     }
166 
167     public String getDescrFormatted() {
168         return descrFormatted;
169     }
170 
171     public void setDescrFormatted(String descrFormatted) {
172         this.descrFormatted = descrFormatted;
173     }
174 
175     public String getDescrPlain() {
176         return descrPlain;
177     }
178 
179     public void setDescrPlain(String descrPlain) {
180         this.descrPlain = descrPlain;
181     }
182 
183     @Override
184     public void setAttributes(Set<LuiSetAttributeEntity> attributes) {
185         this.attributes = attributes;
186     }
187 
188     @Override
189     public Set<LuiSetAttributeEntity> getAttributes() {
190         return attributes;
191     }
192 }