1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.organization.dao.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.LinkedHashSet; |
20 | |
import java.util.List; |
21 | |
import java.util.Set; |
22 | |
|
23 | |
import javax.persistence.EntityManager; |
24 | |
import javax.persistence.NoResultException; |
25 | |
import javax.persistence.PersistenceContext; |
26 | |
import javax.persistence.Query; |
27 | |
|
28 | |
import org.kuali.student.common.dao.impl.AbstractSearchableCrudDaoImpl; |
29 | |
import org.kuali.student.core.organization.dao.OrganizationDao; |
30 | |
import org.kuali.student.core.organization.dto.OrgTreeInfo; |
31 | |
import org.kuali.student.core.organization.entity.Org; |
32 | |
import org.kuali.student.core.organization.entity.OrgOrgRelation; |
33 | |
import org.kuali.student.core.organization.entity.OrgOrgRelationType; |
34 | |
import org.kuali.student.core.organization.entity.OrgPersonRelation; |
35 | |
import org.kuali.student.core.organization.entity.OrgPersonRelationType; |
36 | |
import org.kuali.student.core.organization.entity.OrgPositionRestriction; |
37 | |
|
38 | 24 | public class OrganizationDaoImpl extends AbstractSearchableCrudDaoImpl implements OrganizationDao { |
39 | |
|
40 | |
@PersistenceContext(unitName = "Organization") |
41 | |
@Override |
42 | |
public void setEm(EntityManager em) { |
43 | 0 | super.setEm(em); |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public List<OrgPersonRelation> getAllOrgPersonRelationsByPerson(String personId) { |
48 | 0 | Query query = em.createNamedQuery("OrgPersonRelation.getAllOrgPersonRelationsByPerson"); |
49 | 0 | query.setParameter("personId", personId); |
50 | |
@SuppressWarnings("unchecked") |
51 | 0 | List<OrgPersonRelation> resultList = query.getResultList(); |
52 | 0 | return resultList; |
53 | |
} |
54 | |
|
55 | |
@Override |
56 | |
public List<OrgPersonRelation> getAllOrgPersonRelationsByOrg(String orgId) { |
57 | 0 | Query query = em.createNamedQuery("OrgPersonRelation.getAllOrgPersonRelationsByOrg"); |
58 | 0 | query.setParameter("orgId", orgId); |
59 | |
@SuppressWarnings("unchecked") |
60 | 0 | List<OrgPersonRelation> resultList = query.getResultList(); |
61 | 0 | return resultList; |
62 | |
} |
63 | |
|
64 | |
@Override |
65 | |
public List<String> getPersonIdsForOrgByRelationType(String orgId, String orgPersonRelationTypeKey) { |
66 | 0 | Query query = em.createNamedQuery("OrgPersonRelationType.getPersonIdsForOrgByRelationType"); |
67 | 0 | query.setParameter("orgId", orgId); |
68 | 0 | query.setParameter("orgPersonRelationTypeKey", orgPersonRelationTypeKey); |
69 | |
@SuppressWarnings("unchecked") |
70 | 0 | List<String> resultList = query.getResultList(); |
71 | 0 | return resultList; |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public List<Org> getOrganizationsByIdList(List<String> orgIdList) { |
76 | 0 | Query query = em.createNamedQuery("Org.getOrganizationsByIdList"); |
77 | 0 | query.setParameter("orgIdList", orgIdList); |
78 | |
@SuppressWarnings("unchecked") |
79 | 0 | List<Org> orgs = query.getResultList(); |
80 | 0 | return orgs; |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public List<OrgOrgRelation> getOrgOrgRelationsByOrg(String orgId) { |
85 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.OrgOrgRelation"); |
86 | 0 | query.setParameter("orgId", orgId); |
87 | |
@SuppressWarnings("unchecked") |
88 | 0 | List<OrgOrgRelation> orgOrgRelations = query.getResultList(); |
89 | 0 | return orgOrgRelations; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public List<OrgPositionRestriction> getPositionRestrictionsByOrg( |
94 | |
String orgId) { |
95 | 0 | Query query = em.createNamedQuery("OrgPositionRestriction.findOrgPositionRestrictions"); |
96 | 0 | query.setParameter("orgId", orgId); |
97 | |
@SuppressWarnings("unchecked") |
98 | 0 | List<OrgPositionRestriction> orgPositionRestrictions = query.getResultList(); |
99 | 0 | return orgPositionRestrictions; |
100 | |
|
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public List<String> getAllDescendants(String orgId, String orgHierarchy) { |
105 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.getAllDescendants"); |
106 | 0 | query.setParameter("orgHierarchy", orgHierarchy); |
107 | 0 | return getAllLevels(query, "orgId", orgId); |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public List<String> getAllAncestors(String orgId, String orgHierarchy) { |
112 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.getAncestors"); |
113 | 0 | query.setParameter("orgHierarchy", orgHierarchy); |
114 | 0 | return getAllLevels(query, "orgId", orgId); |
115 | |
} |
116 | |
|
117 | |
private List<String> getAllLevels(Query query, String paramName, String paramValue) { |
118 | |
|
119 | 0 | Set<String> valSet = new LinkedHashSet<String>(); |
120 | 0 | query.setParameter(paramName, paramValue); |
121 | |
@SuppressWarnings("unchecked") |
122 | 0 | List<String> nextLevelList = query.getResultList(); |
123 | 0 | valSet.addAll(nextLevelList); |
124 | 0 | for (String resultStr : nextLevelList) { |
125 | 0 | valSet.addAll(getAllLevels(query, paramName, resultStr)); |
126 | |
} |
127 | 0 | return new ArrayList<String>(valSet); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public List<OrgOrgRelationType> getOrgOrgRelationTypesForOrgHierarchy(String orgHierarchyKey) { |
132 | 0 | Query query = em.createNamedQuery("OrgOrgRelationType.getOrgOrgRelationTypesForOrgHierarchy"); |
133 | 0 | query.setParameter("orgHierarchy", orgHierarchyKey); |
134 | |
@SuppressWarnings("unchecked") |
135 | 0 | List<OrgOrgRelationType> orgOrgRelationTypes = query.getResultList(); |
136 | 0 | return orgOrgRelationTypes; |
137 | |
|
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public boolean validatePositionRestriction(String orgId, |
142 | |
String orgPersonRelationTypeKey) { |
143 | 0 | Query query = em.createNamedQuery("OrgPositionRestriction.validatePositionRestriction"); |
144 | 0 | query.setParameter("orgId", orgId); |
145 | 0 | query.setParameter("orgPersonRelationTypeKey", orgPersonRelationTypeKey); |
146 | 0 | Long valid = (Long)query.getSingleResult(); |
147 | 0 | return valid.intValue()>0; |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public List<OrgPersonRelationType> getOrgPersonRelationTypesForOrgType(String orgTypeKey) { |
152 | 0 | Query query = em.createNamedQuery("OrgPersonRelationType.getOrgPersonRelationTypesForOrgType"); |
153 | 0 | query.setParameter("orgTypeKey", orgTypeKey); |
154 | |
@SuppressWarnings("unchecked") |
155 | 0 | List<OrgPersonRelationType> orgRelationTypes = query.getResultList(); |
156 | 0 | return orgRelationTypes; |
157 | |
} |
158 | |
|
159 | |
@Override |
160 | |
public List<OrgOrgRelation> getOrgOrgRelationsByIdList(List<String> orgOrgRelationIdList) { |
161 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.getOrgOrgRelationsByIdList"); |
162 | 0 | query.setParameter("idList", orgOrgRelationIdList); |
163 | |
@SuppressWarnings("unchecked") |
164 | 0 | List<OrgOrgRelation> orgRelationTypes = query.getResultList(); |
165 | 0 | return orgRelationTypes; |
166 | |
} |
167 | |
|
168 | |
@Override |
169 | |
public List<OrgPersonRelation> getOrgPersonRelationsByIdList(List<String> orgPersonRelationIdList) { |
170 | 0 | Query query = em.createNamedQuery("OrgPersonRelation.getOrgPersonRelationsByIdList"); |
171 | 0 | query.setParameter("idList", orgPersonRelationIdList); |
172 | |
@SuppressWarnings("unchecked") |
173 | 0 | List<OrgPersonRelation> orgRelations = query.getResultList(); |
174 | 0 | return orgRelations; |
175 | |
} |
176 | |
|
177 | |
@Override |
178 | |
public List<OrgPersonRelation> getOrgPersonRelationsByPerson(String personId, String orgId) { |
179 | 0 | Query query = em.createNamedQuery("OrgPersonRelation.getOrgPersonRelationsByPerson"); |
180 | 0 | query.setParameter("personId", personId); |
181 | 0 | query.setParameter("orgId", orgId); |
182 | |
@SuppressWarnings("unchecked") |
183 | 0 | List<OrgPersonRelation> orgRelations = query.getResultList(); |
184 | |
|
185 | 0 | return orgRelations; |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
public List<OrgOrgRelationType> getOrgOrgRelationTypesForOrgType(String orgTypeKey) { |
190 | |
|
191 | |
|
192 | 0 | Query query = em.createNamedQuery("OrgOrgRelationType.getOrgOrgRelationTypesForOrgType"); |
193 | 0 | query.setParameter("orgTypeKey", orgTypeKey); |
194 | |
@SuppressWarnings("unchecked") |
195 | 0 | List<OrgOrgRelationType> orgOrgRelations = query.getResultList(); |
196 | |
|
197 | 0 | return orgOrgRelations; |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public List<OrgOrgRelation> getOrgOrgRelationsByRelatedOrg(String relatedOrgId) { |
202 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.getOrgOrgRelationsByRelatedOrg"); |
203 | 0 | query.setParameter("relatedOrgId", relatedOrgId); |
204 | |
@SuppressWarnings("unchecked") |
205 | 0 | List<OrgOrgRelation> orgOrgRelations = query.getResultList(); |
206 | |
|
207 | 0 | return orgOrgRelations; |
208 | |
|
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
public List<OrgTreeInfo> getOrgTreeInfo(String orgId, |
213 | |
String orgHierarchyId) { |
214 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.getOrgTreeInfo"); |
215 | 0 | query.setParameter("orgId",orgId); |
216 | 0 | query.setParameter("orgHierarchyId",orgHierarchyId); |
217 | |
@SuppressWarnings("unchecked") |
218 | 0 | List<OrgTreeInfo> orgTreeInfos = query.getResultList(); |
219 | |
|
220 | 0 | return orgTreeInfos; |
221 | |
} |
222 | |
|
223 | |
@Override |
224 | |
public boolean hasOrgPersonRelation(String orgId, String personId, String orgPersonRelationTypeKey) { |
225 | 0 | Query query = em.createNamedQuery("OrgPersonRelationType.hasOrgPersonRelation"); |
226 | 0 | query.setParameter("orgId", orgId); |
227 | 0 | query.setParameter("personId", personId); |
228 | 0 | query.setParameter("orgPersonRelationTypeKey", orgPersonRelationTypeKey); |
229 | 0 | Long valid = (Long)query.getSingleResult(); |
230 | 0 | return valid.intValue()>0; |
231 | |
} |
232 | |
|
233 | |
@Override |
234 | |
public boolean hasOrgOrgRelation(String orgId, String comparisonOrgId, |
235 | |
String orgOrgRelationTypeKey) { |
236 | |
|
237 | 0 | Query query = em.createNamedQuery("OrgOrgRelation.hasOrgOrgRelation"); |
238 | 0 | query.setParameter("orgId",orgId); |
239 | 0 | query.setParameter("comparisonOrgId",comparisonOrgId); |
240 | 0 | query.setParameter("orgOrgRelationTypeKey",orgOrgRelationTypeKey); |
241 | |
|
242 | 0 | Long relationCount = (Long)query.getSingleResult(); |
243 | |
|
244 | 0 | return relationCount>0; |
245 | |
} |
246 | |
@Override |
247 | |
public OrgPositionRestriction getPositionRestrictionByOrgAndPersonRelationTypeKey(String orgId, String orgPersonRelationTypeKey) { |
248 | 0 | Query query = em.createNamedQuery("OrgPositionRestriction.getPositionRestrictionByOrgAndPersonRelationTypeKey"); |
249 | 0 | query.setParameter("orgId",orgId); |
250 | 0 | query.setParameter("orgPersonRelationTypeKey",orgPersonRelationTypeKey); |
251 | |
|
252 | 0 | return (OrgPositionRestriction) query.getSingleResult(); |
253 | |
} |
254 | |
|
255 | |
@Override |
256 | |
public Long getOrgMemebershipCount(String orgId) { |
257 | 0 | Query query = em.createNamedQuery("OrgPersonRelation.getOrgMembershipCount"); |
258 | 0 | query.setParameter("orgId", orgId); |
259 | |
|
260 | 0 | return (Long)query.getSingleResult(); |
261 | |
} |
262 | |
|
263 | |
@Override |
264 | |
public Org getOrgByRelatedOrgAndType(String relatedOrgId, String relationTypeKey) { |
265 | 0 | Query query = em.createNamedQuery("Org.getOrgByRelatedOrgAndType"); |
266 | 0 | query.setParameter("relatedOrgId", relatedOrgId); |
267 | 0 | query.setParameter("relationTypeKey", relationTypeKey); |
268 | |
|
269 | |
try{ |
270 | 0 | return (Org) query.getSingleResult(); |
271 | 0 | }catch(NoResultException e){ |
272 | 0 | return null; |
273 | |
} |
274 | |
} |
275 | |
} |