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