001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.lum.lu.entity;
017    
018    import java.util.Date;
019    import java.util.List;
020    
021    import javax.persistence.AttributeOverride;
022    import javax.persistence.AttributeOverrides;
023    import javax.persistence.CascadeType;
024    import javax.persistence.Column;
025    import javax.persistence.Embedded;
026    import javax.persistence.Entity;
027    import javax.persistence.JoinColumn;
028    import javax.persistence.JoinTable;
029    import javax.persistence.ManyToOne;
030    import javax.persistence.NamedQueries;
031    import javax.persistence.NamedQuery;
032    import javax.persistence.OneToMany;
033    import javax.persistence.OneToOne;
034    import javax.persistence.Table;
035    import javax.persistence.Temporal;
036    import javax.persistence.TemporalType;
037    import javax.persistence.UniqueConstraint;
038    
039    import org.kuali.student.core.entity.Amount;
040    import org.kuali.student.core.entity.AttributeOwner;
041    import org.kuali.student.core.entity.TimeAmount;
042    import org.kuali.student.core.entity.VersionEntity;
043    
044    @Entity
045    @Table(name = "KSLU_CLU", uniqueConstraints={@UniqueConstraint(columnNames={"VER_IND_ID", "SEQ_NUM"})} )
046    @NamedQueries( {
047            //FIXME dates should be either set from the DB time as part of the insert statement, or set from the application.
048            //DB timestamp (CURRENT_TIMESTAMP) is preferred
049        @NamedQuery(name = "Clu.findCurrentVersionInfo", query = "SELECT " +
050                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
051                    "FROM Clu c " +
052                    "WHERE c.version.versionIndId = :versionIndId " +
053                    "AND c.version.currentVersionStart <= :currentTime AND (c.version.currentVersionEnd > :currentTime OR c.version.currentVersionEnd IS NULL)"),
054            @NamedQuery(name = "Clu.findCurrentVersionOnDate", query = "SELECT " +
055                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
056                    "FROM Clu c " +
057                    "WHERE c.version.versionIndId = :versionIndId " +
058                    "AND c.version.currentVersionStart <= :date AND (c.version.currentVersionEnd > :date OR c.version.currentVersionEnd IS NULL)"),
059            @NamedQuery(name = "Clu.findFirstVersion", query = "SELECT " +
060                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
061                    "FROM Clu c " +
062                    "WHERE c.version.versionIndId = :versionIndId " +
063                    "AND c.version.sequenceNumber IN (SELECT MIN(nc.version.sequenceNumber) FROM Clu nc WHERE nc.version.versionIndId = :versionIndId)"),
064        @NamedQuery(name = "Clu.findLatestVersion", query = "SELECT " +
065                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
066                "FROM Clu c " +
067                "WHERE c.version.versionIndId = :versionIndId " +
068                "AND c.version.sequenceNumber IN (SELECT MAX(nc.version.sequenceNumber) FROM Clu nc WHERE nc.version.versionIndId = :versionIndId)"),
069        @NamedQuery(name = "Clu.findVersionBySequence", query = "SELECT " +
070                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
071                    "FROM Clu c " +
072                    "WHERE c.version.versionIndId = :versionIndId " +
073                    "AND c.version.sequenceNumber = :sequenceNumber"),
074            @NamedQuery(name = "Clu.findVersions", query = "SELECT " +
075                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
076                    "FROM Clu c " +
077                    "WHERE c.version.versionIndId = :versionIndId"),
078            @NamedQuery(name = "Clu.findVersionsInDateRange", query = "SELECT " +
079                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
080                    "FROM Clu c " +
081                    "WHERE c.version.versionIndId = :versionIndId " +
082                    "AND ( (c.version.currentVersionStart >= :from AND c.version.currentVersionStart < :to)" +
083                    "   OR (c.version.currentVersionStart < :from AND c.version.currentVersionEnd > :from) )"),
084            @NamedQuery(name = "Clu.findVersionsBeforeDate", query = "SELECT " +
085                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
086                    "FROM Clu c " +
087                    "WHERE c.version.versionIndId = :versionIndId " +
088                    "AND c.version.currentVersionStart <= :date"),
089            @NamedQuery(name = "Clu.findVersionsAfterDate", query = "SELECT " +
090                    "NEW org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo(c.id, c.version.versionIndId, c.version.sequenceNumber, c.version.currentVersionStart, c.version.currentVersionEnd, c.version.versionComment, c.version.versionedFromId) " +
091                    "FROM Clu c " +
092                    "WHERE c.version.versionIndId = :versionIndId " +
093                    "AND c.version.currentVersionStart >= :date"),
094        @NamedQuery(name = "Clu.findLatestClu", query = "SELECT c FROM Clu c WHERE c.version.versionIndId = :versionIndId AND c.version.sequenceNumber IN (SELECT MAX(nc.version.sequenceNumber) FROM Clu nc WHERE nc.version.versionIndId = :versionIndId)"),
095        @NamedQuery(name = "Clu.findCurrentClu", query = "SELECT c FROM Clu c WHERE c.version.versionIndId = :versionIndId AND c.version.currentVersionStart <= :currentTime AND (c.version.currentVersionEnd > :currentTime OR c.version.currentVersionEnd IS NULL)"),
096        @NamedQuery(name = "Clu.findClusByIdList", query = "SELECT c FROM Clu c WHERE c.id IN (:idList)"),
097        @NamedQuery(name = "Clu.getClusByLuType", query = "SELECT c FROM Clu c WHERE c.state = :luState AND c.luType.id = :luTypeKey"),
098        @NamedQuery(name = "Clu.getClusByRelation", query = "SELECT c FROM Clu c WHERE c.id IN (SELECT ccr.relatedClu.id FROM CluCluRelation ccr WHERE ccr.clu.id = :parentCluId AND ccr.luLuRelationType.id = :luLuRelationTypeKey)")
099    })
100    public class Clu extends VersionEntity implements AttributeOwner<CluAttribute> {
101    
102        @OneToOne(cascade=CascadeType.ALL)
103        @JoinColumn(name = "OFFIC_CLU_ID")
104        private CluIdentifier officialIdentifier;
105        
106        @OneToMany(cascade=CascadeType.ALL)
107        @JoinTable(name = "KSLU_CLU_JN_CLU_IDENT", joinColumns = @JoinColumn(name = "CLU_ID"), inverseJoinColumns = @JoinColumn(name = "ALT_CLU_ID"))
108        private List<CluIdentifier> alternateIdentifiers;
109    
110        @Column(name = "STDY_SUBJ_AREA")
111        private String studySubjectArea;
112        
113        @ManyToOne(cascade=CascadeType.ALL)
114        @JoinColumn(name = "RT_DESCR_ID")
115        private LuRichText descr;
116    
117        @OneToMany(cascade=CascadeType.ALL, mappedBy = "clu")
118        private List<CluCampusLocation> campusLocations;
119        
120        @OneToMany(cascade=CascadeType.ALL)
121        @JoinTable(name = "KSLU_CLU_JN_ACCRED", joinColumns = @JoinColumn(name = "CLU_ID"), inverseJoinColumns = @JoinColumn(name = "CLU_ACCRED_ID"))
122        private List<CluAccreditation> accreditations;
123        
124        @OneToMany(cascade = CascadeType.ALL, mappedBy = "clu")
125        private List<CluAdminOrg> adminOrgs;
126        
127        @ManyToOne(cascade=CascadeType.ALL)
128        @JoinColumn(name="PRI_INSTR_ID")
129        private CluInstructor primaryInstructor;
130        
131        @OneToMany(cascade=CascadeType.ALL)
132        @JoinTable(name = "KSLU_CLU_JN_CLU_INSTR", joinColumns = @JoinColumn(name = "CLU_ID"), inverseJoinColumns = @JoinColumn(name = "CLU_INSTR_ID"))
133        private List<CluInstructor> instructors;
134            
135        @Column(name = "EXP_FIRST_ATP")
136        private String expectedFirstAtp;
137    
138        @Column(name = "LAST_ATP")
139        private String lastAtp;
140    
141        @Column(name = "LAST_ADMIT_ATP")
142        private String lastAdmitAtp;
143        
144        @Temporal(TemporalType.TIMESTAMP)
145        @Column(name = "EFF_DT")
146        private Date effectiveDate;
147    
148        @Temporal(TemporalType.TIMESTAMP)
149        @Column(name = "EXPIR_DT")
150        private Date expirationDate;
151    
152        @Embedded
153        @AttributeOverrides({
154            @AttributeOverride(name="unitType", column=@Column(name="CLU_INTSTY_TYPE")),
155            @AttributeOverride(name="unitQuantity", column=@Column(name="CLU_INTSTY_QTY")
156            )})
157         private Amount intensity;
158    
159        @Embedded
160        @Column(name = "STD_DUR")
161        private TimeAmount stdDuration;
162        
163        @Column(name = "CAN_CREATE_LUI")
164        private boolean canCreateLui;
165    
166        @Column(name = "REF_URL")
167        private String referenceURL;
168    
169        @OneToMany(cascade = CascadeType.ALL, mappedBy="clu")
170        private List<LuCode> luCodes;
171            
172        @Column(name = "NEXT_REVIEW_PRD")
173        private String nextReviewPeriod;
174    
175        @Column(name = "IS_ENRL")
176        private boolean enrollable;
177        
178        @OneToMany(cascade=CascadeType.ALL, mappedBy="clu")
179        private List<CluAtpTypeKey> offeredAtpTypes;
180        
181        @Column(name = "HAS_EARLY_DROP_DEDLN")
182        private boolean hasEarlyDropDeadline;
183    
184        @Column(name = "DEF_ENRL_EST")
185        private int defaultEnrollmentEstimate;
186    
187        @Column(name = "DEF_MAX_ENRL")
188        private int defaultMaximumEnrollment;
189    
190        @Column(name = "IS_HAZR_DISBLD_STU")
191        private boolean hazardousForDisabledStudents;
192    
193        @OneToOne(cascade=CascadeType.ALL)
194        @JoinColumn(name = "FEE_ID")
195        private CluFee fee;
196        
197        @OneToOne(cascade=CascadeType.ALL)
198        @JoinColumn(name = "ACCT_ID")
199        private CluAccounting accounting;
200        
201        @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
202        private List<CluAttribute> attributes;
203    
204        @ManyToOne
205        @JoinColumn(name = "LUTYPE_ID")
206        private LuType luType;
207        
208        @Column(name = "ST")
209        private String state;
210        
211        public LuType getLuType() {
212            return luType;
213        }
214    
215        public void setLuType(LuType luType) {
216            this.luType = luType;
217        }
218    
219        @Override
220        public List<CluAttribute> getAttributes() {
221            return attributes;
222        }
223    
224        @Override
225        public void setAttributes(List<CluAttribute> attributes) {
226            this.attributes = attributes;
227        }
228    
229        public CluIdentifier getOfficialIdentifier() {
230            return officialIdentifier;
231        }
232    
233        public void setOfficialIdentifier(CluIdentifier officialIdentifier) {
234            this.officialIdentifier = officialIdentifier;
235        }
236    
237        public List<CluIdentifier> getAlternateIdentifiers() {
238            return alternateIdentifiers;
239        }
240    
241        public void setAlternateIdentifiers(List<CluIdentifier> alternateIdentifiers) {
242            this.alternateIdentifiers = alternateIdentifiers;
243        }
244    
245        public String getStudySubjectArea() {
246            return studySubjectArea;
247        }
248    
249        public void setStudySubjectArea(String studySubjectArea) {
250            this.studySubjectArea = studySubjectArea;
251        }
252    
253        public LuRichText getDescr() {
254            return descr;
255        }
256    
257        public void setDescr(LuRichText descr) {
258            this.descr = descr;
259        }
260    
261        public List<CluInstructor> getInstructors() {
262            return instructors;
263        }
264    
265        public void setInstructors(List<CluInstructor> instructors) {
266            this.instructors = instructors;
267        }
268    
269        public Date getEffectiveDate() {
270            return effectiveDate;
271        }
272    
273        public void setEffectiveDate(Date effectiveDate) {
274            this.effectiveDate = effectiveDate;
275        }
276    
277        public Date getExpirationDate() {
278            return expirationDate;
279        }
280    
281        public void setExpirationDate(Date expirationDate) {
282            this.expirationDate = expirationDate;
283        }
284    
285        public TimeAmount getStdDuration() {
286            return stdDuration;
287        }
288    
289        public void setStdDuration(TimeAmount stdDuration) {
290            this.stdDuration = stdDuration;
291        }
292    
293        public boolean isCanCreateLui() {
294            return canCreateLui;
295        }
296    
297        public void setCanCreateLui(boolean canCreateLui) {
298            this.canCreateLui = canCreateLui;
299        }
300    
301        public String getReferenceURL() {
302            return referenceURL;
303        }
304    
305        public void setReferenceURL(String referenceURL) {
306            this.referenceURL = referenceURL;
307        }
308    
309        public List<LuCode> getLuCodes() {
310            return luCodes;
311        }
312    
313        public void setLuCodes(List<LuCode> luCodes) {
314            this.luCodes = luCodes;
315        }
316    
317         public String getNextReviewPeriod() {
318             return nextReviewPeriod;
319         }
320    
321         public void setNextReviewPeriod(String nextReviewPeriod) {
322             this.nextReviewPeriod = nextReviewPeriod;
323         }
324    
325         public boolean isEnrollable() {
326             return enrollable;
327         }
328    
329         public void setEnrollable(boolean enrollable) {
330             this.enrollable = enrollable;
331         }
332    
333         public List<CluAtpTypeKey> getOfferedAtpTypes() {
334             return offeredAtpTypes;
335         }
336    
337         public void setOfferedAtpTypes(List<CluAtpTypeKey> offeredAtpTypes) {
338             this.offeredAtpTypes = offeredAtpTypes;
339         }
340    
341         public boolean isHasEarlyDropDeadline() {
342             return hasEarlyDropDeadline;
343         }
344    
345         public void setHasEarlyDropDeadline(boolean hasEarlyDropDeadline) {
346             this.hasEarlyDropDeadline = hasEarlyDropDeadline;
347         }
348    
349         public int getDefaultEnrollmentEstimate() {
350             return defaultEnrollmentEstimate;
351         }
352    
353         public void setDefaultEnrollmentEstimate(int defaultEnrollmentEstimate) {
354             this.defaultEnrollmentEstimate = defaultEnrollmentEstimate;
355         }
356    
357         public int getDefaultMaximumEnrollment() {
358             return defaultMaximumEnrollment;
359         }
360    
361         public void setDefaultMaximumEnrollment(int defaultMaximumEnrollment) {
362             this.defaultMaximumEnrollment = defaultMaximumEnrollment;
363         }
364    
365         public boolean isHazardousForDisabledStudents() {
366             return hazardousForDisabledStudents;
367         }
368    
369         public void setHazardousForDisabledStudents(
370                 boolean hazardousForDisabledStudents) {
371             this.hazardousForDisabledStudents = hazardousForDisabledStudents;
372         }
373    
374         public CluFee getFee() {
375             return fee;
376         }
377    
378         public void setFee(CluFee fee) {
379             this.fee = fee;
380         }
381    
382         public CluAccounting getAccounting() {
383             return accounting;
384         }
385    
386         public void setAccounting(CluAccounting accounting) {
387             this.accounting = accounting;
388         }
389    
390         public String getState() {
391             return state;
392         }
393    
394         public void setState(String state) {
395             this.state = state;
396         }
397    
398          public CluInstructor getPrimaryInstructor() {
399              return primaryInstructor;
400          }
401    
402          public void setPrimaryInstructor(CluInstructor primaryInstructor) {
403              this.primaryInstructor = primaryInstructor;
404          }
405    
406          public List<CluCampusLocation> getCampusLocations() {
407              return campusLocations;
408          }
409    
410          public void setCampusLocations(List<CluCampusLocation> campusLocationList) {
411              this.campusLocations = campusLocationList;
412          }
413    
414          public Amount getIntensity() {
415              return intensity;
416          }
417    
418          public void setIntensity(Amount intensity) {
419              this.intensity = intensity;
420          }
421    
422          public List<CluAccreditation> getAccreditations() {
423              return accreditations;
424          }
425    
426          public void setAccreditations(List<CluAccreditation> accreditations) {
427              this.accreditations = accreditations;
428          }
429    
430    
431          public List<CluAdminOrg> getAdminOrgs() {
432              return adminOrgs;
433          }
434    
435          public void setAdminOrgs(List<CluAdminOrg> adminOrgs) {
436              this.adminOrgs = adminOrgs;
437          }
438    
439            public String getExpectedFirstAtp() {
440                    return expectedFirstAtp;
441            }
442    
443            public void setExpectedFirstAtp(String expectedFirstAtp) {
444                    this.expectedFirstAtp = expectedFirstAtp;
445            }      
446    
447            public String getLastAtp() {
448                    return lastAtp;
449    }
450    
451            public void setLastAtp(String lastAtp) {
452                    this.lastAtp = lastAtp;
453            }
454    
455        public String getLastAdmitAtp() {
456            return lastAdmitAtp;
457        }
458    
459        public void setLastAdmitAtp(String lastAdmitAtp) {
460            this.lastAdmitAtp = lastAdmitAtp;
461        }
462    }