1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.organization.entity; |
17 | |
|
18 | |
import java.util.Date; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import javax.persistence.CascadeType; |
22 | |
import javax.persistence.Column; |
23 | |
import javax.persistence.Entity; |
24 | |
import javax.persistence.Id; |
25 | |
import javax.persistence.JoinColumn; |
26 | |
import javax.persistence.ManyToOne; |
27 | |
import javax.persistence.NamedQueries; |
28 | |
import javax.persistence.NamedQuery; |
29 | |
import javax.persistence.OneToMany; |
30 | |
import javax.persistence.Table; |
31 | |
import javax.persistence.Temporal; |
32 | |
import javax.persistence.TemporalType; |
33 | |
|
34 | |
import org.kuali.student.common.util.UUIDHelper; |
35 | |
import org.kuali.student.common.entity.AttributeOwner; |
36 | |
import org.kuali.student.common.entity.MetaEntity; |
37 | |
@Entity |
38 | |
@Table(name = "KSOR_ORG_ORG_RELTN") |
39 | |
@NamedQueries( { |
40 | |
@NamedQuery(name = "OrgOrgRelation.getAllDescendants", query = "SELECT oor.relatedOrg.id FROM OrgOrgRelation oor " |
41 | |
+ " WHERE oor.org.id = :orgId " |
42 | |
+ " AND oor.type.orgHierarchy.id = :orgHierarchy" |
43 | |
+ " AND oor.org.effectiveDate<=CURRENT_TIMESTAMP " |
44 | |
+ " AND (oor.org.expirationDate IS NULL OR oor.org.expirationDate>=CURRENT_TIMESTAMP)"), |
45 | |
@NamedQuery(name = "OrgOrgRelation.getAncestors", query = "SELECT oor.org.id FROM OrgOrgRelation oor " |
46 | |
+ " WHERE oor.relatedOrg.id = :orgId " |
47 | |
+ " AND oor.type.orgHierarchy.id = :orgHierarchy" |
48 | |
+ " AND oor.relatedOrg.effectiveDate<=CURRENT_TIMESTAMP " |
49 | |
+ " AND (oor.relatedOrg.expirationDate IS NULL OR oor.relatedOrg.expirationDate>=CURRENT_TIMESTAMP)"), |
50 | |
@NamedQuery(name = "OrgOrgRelation.getOrgOrgRelationsByIdList", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.id IN (:idList)"), |
51 | |
@NamedQuery(name = "OrgOrgRelation.OrgOrgRelation", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.org.id = :orgId"), |
52 | |
@NamedQuery(name = "OrgOrgRelation.getOrgOrgRelationsByRelatedOrg", query = "SELECT oor FROM OrgOrgRelation oor WHERE oor.relatedOrg.id = :relatedOrgId"), |
53 | |
@NamedQuery(name = "OrgOrgRelation.getOrgTreeInfo", query = "SELECT NEW org.kuali.student.core.organization.dto.OrgTreeInfo(oor.relatedOrg.id, oor.org.id, oor.relatedOrg.longName) " |
54 | |
+ " FROM OrgOrgRelation oor " |
55 | |
+ " WHERE oor.org.id = :orgId " |
56 | |
+ " AND oor.type.orgHierarchy.id = :orgHierarchyId " |
57 | |
+ " AND oor.relatedOrg.effectiveDate<=CURRENT_TIMESTAMP " |
58 | |
+ " AND (oor.relatedOrg.expirationDate IS NULL OR oor.relatedOrg.expirationDate>=CURRENT_TIMESTAMP)"), |
59 | |
@NamedQuery(name = "OrgOrgRelation.hasOrgOrgRelation", query = "SELECT COUNT(oor) " |
60 | |
+ " FROM OrgOrgRelation oor " |
61 | |
+ " WHERE oor.org.id = :orgId " |
62 | |
+ " AND oor.relatedOrg.id = :comparisonOrgId " |
63 | |
+ " AND oor.type.id = :orgOrgRelationTypeKey") }) |
64 | 16 | public class OrgOrgRelation extends MetaEntity implements |
65 | |
AttributeOwner<OrgOrgRelationAttribute> { |
66 | |
@Id |
67 | |
@Column(name = "ID") |
68 | |
private String id; |
69 | |
|
70 | |
@ManyToOne |
71 | |
@JoinColumn(name = "ORG") |
72 | |
private Org org; |
73 | |
|
74 | |
@ManyToOne |
75 | |
@JoinColumn(name = "RELATED_ORG") |
76 | |
private Org relatedOrg; |
77 | |
|
78 | |
@Temporal(TemporalType.TIMESTAMP) |
79 | |
@Column(name = "EFF_DT") |
80 | |
private Date effectiveDate; |
81 | |
|
82 | |
@Temporal(TemporalType.TIMESTAMP) |
83 | |
@Column(name = "EXPIR_DT") |
84 | |
private Date expirationDate; |
85 | |
|
86 | |
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") |
87 | |
private List<OrgOrgRelationAttribute> attributes; |
88 | |
|
89 | |
@ManyToOne |
90 | |
@JoinColumn(name = "TYPE") |
91 | |
private OrgOrgRelationType type; |
92 | |
|
93 | |
@Column(name = "ST") |
94 | |
private String state; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
@Override |
100 | |
public void onPrePersist() { |
101 | 1 | this.id = UUIDHelper.genStringUUID(this.id); |
102 | 1 | } |
103 | |
|
104 | |
public String getId() { |
105 | 15 | return id; |
106 | |
} |
107 | |
|
108 | |
public void setId(String id) { |
109 | 1 | this.id = id; |
110 | 1 | } |
111 | |
|
112 | |
public Org getOrg() { |
113 | 15 | return org; |
114 | |
} |
115 | |
|
116 | |
public void setOrg(Org org) { |
117 | 1 | this.org = org; |
118 | 1 | } |
119 | |
|
120 | |
public Org getRelatedOrg() { |
121 | 15 | return relatedOrg; |
122 | |
} |
123 | |
|
124 | |
public void setRelatedOrg(Org relatedOrg) { |
125 | 1 | this.relatedOrg = relatedOrg; |
126 | 1 | } |
127 | |
|
128 | |
public Date getEffectiveDate() { |
129 | 15 | return effectiveDate; |
130 | |
} |
131 | |
|
132 | |
public void setEffectiveDate(Date effectiveDate) { |
133 | 1 | this.effectiveDate = effectiveDate; |
134 | 1 | } |
135 | |
|
136 | |
public Date getExpirationDate() { |
137 | 15 | return expirationDate; |
138 | |
} |
139 | |
|
140 | |
public void setExpirationDate(Date expirationDate) { |
141 | 1 | this.expirationDate = expirationDate; |
142 | 1 | } |
143 | |
|
144 | |
@Override |
145 | |
public List<OrgOrgRelationAttribute> getAttributes() { |
146 | 18 | return attributes; |
147 | |
} |
148 | |
|
149 | |
@Override |
150 | |
public void setAttributes(List<OrgOrgRelationAttribute> attributes) { |
151 | 2 | this.attributes = attributes; |
152 | 2 | } |
153 | |
|
154 | |
public OrgOrgRelationType getType() { |
155 | 15 | return type; |
156 | |
} |
157 | |
|
158 | |
public void setType(OrgOrgRelationType type) { |
159 | 1 | this.type = type; |
160 | 1 | } |
161 | |
|
162 | |
public String getState() { |
163 | 15 | return state; |
164 | |
} |
165 | |
|
166 | |
public void setState(String state) { |
167 | 1 | this.state = state; |
168 | 1 | } |
169 | |
|
170 | |
} |