View Javadoc

1   /**
2    * Copyright 2012 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   */
16  package org.kuali.student.enrollment.class2.courseoffering.model;
17  
18  import org.kuali.student.r1.common.entity.KSEntityConstants;
19  import org.kuali.student.enrollment.courseoffering.dto.SeatPoolDefinitionInfo;
20  import org.kuali.student.r2.common.dto.AttributeInfo;
21  import org.kuali.student.r2.common.dto.RichTextInfo;
22  import org.kuali.student.r2.common.entity.AttributeOwner;
23  import org.kuali.student.r2.common.entity.MetaEntity;
24  import org.kuali.student.r2.common.infc.Attribute;
25  import org.kuali.student.enrollment.courseoffering.infc.SeatPoolDefinition;
26  
27  import javax.persistence.*;
28  import java.util.HashSet;
29  import java.util.Set;
30  
31  /**
32   * This class //TODO ...
33   *
34   * @author Kuali Student Team
35   */
36  @Entity
37  @Table(name = "KSEN_CO_SEAT_POOL_DEFN")
38  public class SeatPoolDefinitionEntity extends MetaEntity implements AttributeOwner<SeatPoolDefinitionAttributeEntity> {
39  
40      @Column(name = "NAME")
41      private String name;
42  
43      @Column(name = "ACTIVITY_OFFERING_ID")
44      private String activityOfferingId;
45  
46      @Column(name = "EXPIR_MSTONE_TYPE")
47      private String expirationMilestoneTypeKey;
48  
49      @Column(name = "PERCENTAGE_IND")
50      private boolean isPercentage;
51  
52      @Column(name = "SEAT_LIMIT")
53      private Integer seatLimit;
54  
55      @Column(name = "PROCESSING_PRIORITY")
56      private Integer processingPriority;
57  
58      @Column(name = "POPULATION_ID")
59      private String populationId;
60  
61      // =====================================================================
62      // The fields below are inherited from MetaEntity (and everything MetaEntity inherits from)
63      // MetaEntity is what EnrollmentFee extends (Meta fields are included by inheritance from MetaIdentity)
64      @Column(name = "SEAT_POOL_DEFN_TYPE")
65      private String seatPoolDefnType;
66  
67      @Column(name = "SEAT_POOL_DEFN_STATE")
68      private String seatPoolDefnState;
69  
70      @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
71      private Set<SeatPoolDefinitionAttributeEntity> attributes = new HashSet<SeatPoolDefinitionAttributeEntity>();
72  
73      public SeatPoolDefinitionEntity() { // no-arg constructor expected in entity
74      }
75  
76      public SeatPoolDefinitionEntity(SeatPoolDefinition pool) {
77          super(pool);
78          this.setId(pool.getId()); // read-only field
79          this.setSeatPoolDefnType(pool.getTypeKey()); // read-only field
80          this.fromDto(pool);
81      }
82  
83      public void fromDto(SeatPoolDefinition pool) {
84          this.setSeatPoolDefnState(pool.getStateKey());
85          this.setSeatPoolDefnType(pool.getTypeKey());
86          this.setName(pool.getName());
87          this.setExpirationMilestoneTypeKey(pool.getExpirationMilestoneTypeKey());
88          this.setIsPercentage(defaultFalse(pool.getIsPercentage()));
89          this.setSeatLimit(pool.getSeatLimit());
90          this.setProcessingPriority(pool.getProcessingPriority());
91          this.setPopulationId(pool.getPopulationId());
92          this.setAttributes(new HashSet<SeatPoolDefinitionAttributeEntity>());
93          for (Attribute att : pool.getAttributes()) {
94              SeatPoolDefinitionAttributeEntity attEntity = new SeatPoolDefinitionAttributeEntity(att, this);
95              this.getAttributes().add(attEntity);
96          }
97      }
98  
99      public SeatPoolDefinitionInfo toDto() {
100         SeatPoolDefinitionInfo poolInfo = new SeatPoolDefinitionInfo();
101         // Set the instance variables that are common to most entities
102         poolInfo.setId(getId());
103         poolInfo.setStateKey(getSeatPoolDefnState());
104         poolInfo.setTypeKey(getSeatPoolDefnType());
105         // Then, all the instance variables that are specific to SeatPoolDefinitionEntity
106         poolInfo.setName(getName());
107         poolInfo.setExpirationMilestoneTypeKey(getExpirationMilestoneTypeKey());
108         poolInfo.setIsPercentage(getIsPercentage());
109         poolInfo.setSeatLimit(getSeatLimit());
110         poolInfo.setProcessingPriority(getProcessingPriority());
111         poolInfo.setPopulationId(getPopulationId());
112         // Then, the meta fields
113         poolInfo.setMeta(super.toDTO());
114         // Finally, attributes
115         for (SeatPoolDefinitionAttributeEntity att: getAttributes()) {
116             AttributeInfo attInfo = att.toDto();
117             poolInfo.getAttributes().add(attInfo);
118         }
119         return poolInfo;
120     }
121 
122     public String getName() {
123         return name;
124     }
125 
126     public void setName(String name) {
127         this.name = name;
128     }
129 
130     public String getActivityOfferingId() {
131         return activityOfferingId;
132     }
133 
134     public void setActivityOfferingId(String activityOfferingId) {
135         this.activityOfferingId = activityOfferingId;
136     }
137 
138     public String getExpirationMilestoneTypeKey() {
139         return expirationMilestoneTypeKey;
140     }
141 
142     public void setExpirationMilestoneTypeKey(String expirationMilestoneTypeKey) {
143         this.expirationMilestoneTypeKey = expirationMilestoneTypeKey;
144     }
145 
146     public Boolean getIsPercentage() {
147         return isPercentage;
148     }
149 
150     public void setIsPercentage(Boolean percentage) {
151         isPercentage = percentage;
152     }
153 
154     public void setIsPercentage(boolean percentage) {
155         isPercentage = percentage;
156     }
157 
158     public Integer getSeatLimit() {
159         return seatLimit;
160     }
161 
162     public void setSeatLimit(Integer seatLimit) {
163         this.seatLimit = seatLimit;
164     }
165 
166     public Integer getProcessingPriority() {
167         return processingPriority;
168     }
169 
170     public void setProcessingPriority(Integer processingPriority) {
171         this.processingPriority = processingPriority;
172     }
173 
174     public String getPopulationId() {
175         return populationId;
176     }
177 
178     public void setPopulationId(String populationId) {
179         this.populationId = populationId;
180     }
181 
182     public String getSeatPoolDefnType() {
183         return seatPoolDefnType;
184     }
185 
186     public void setSeatPoolDefnType(String seatPoolDefnType) {
187         this.seatPoolDefnType = seatPoolDefnType;
188     }
189 
190     public String getSeatPoolDefnState() {
191         return seatPoolDefnState;
192     }
193 
194     public void setSeatPoolDefnState(String seatPoolDefnState) {
195         this.seatPoolDefnState = seatPoolDefnState;
196     }
197 
198     public Set<SeatPoolDefinitionAttributeEntity> getAttributes() {
199         return attributes;
200     }
201 
202     public void setAttributes(Set<SeatPoolDefinitionAttributeEntity> attributes) {
203         this.attributes = attributes;
204     }
205 
206     private boolean defaultFalse(Boolean b) {
207         if (b == null) {
208             return false;
209         }
210         return b.booleanValue();
211     }
212 
213 }