1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.lum.lu.dao.impl;
17
18 import java.util.Date;
19 import java.util.List;
20
21 import javax.persistence.EntityManager;
22 import javax.persistence.PersistenceContext;
23 import javax.persistence.Query;
24
25 import org.kuali.student.core.dao.impl.AbstractSearchableCrudDaoImpl;
26 import org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo;
27 import org.kuali.student.lum.lu.dao.LuDao;
28 import org.kuali.student.lum.lu.entity.Clu;
29 import org.kuali.student.lum.lu.entity.CluCluRelation;
30 import org.kuali.student.lum.lu.entity.CluLoRelation;
31 import org.kuali.student.lum.lu.entity.CluPublication;
32 import org.kuali.student.lum.lu.entity.CluResult;
33 import org.kuali.student.lum.lu.entity.CluResultType;
34 import org.kuali.student.lum.lu.entity.CluSet;
35 import org.kuali.student.lum.lu.entity.Lui;
36 import org.kuali.student.lum.lu.entity.LuiLuiRelation;
37
38 import edu.emory.mathcs.backport.java.util.Collections;
39
40 public class LuDaoImpl extends AbstractSearchableCrudDaoImpl implements LuDao {
41
42 @PersistenceContext(unitName = "Lu")
43 @Override
44 public void setEm(EntityManager em) {
45 super.setEm(em);
46 }
47
48 @Override
49 public List<Clu> getClusByIdList(List<String> cluIdList) {
50 Query query = em.createNamedQuery("Clu.findClusByIdList");
51 query.setParameter("idList", cluIdList);
52 @SuppressWarnings("unchecked")
53 List<Clu> resultList = query.getResultList();
54 return resultList;
55 }
56
57 @Override
58 public List<Clu> getClusByLuType(String luTypeKey, String luState) {
59 Query query = em.createNamedQuery("Clu.getClusByLuType");
60 query.setParameter("luTypeKey", luTypeKey);
61 query.setParameter("luState", luState);
62 @SuppressWarnings("unchecked")
63 List<Clu> resultList = query.getResultList();
64 return resultList;
65 }
66
67 @Override
68 public List<CluSet> getCluSetInfoByIdList(List<String> cluSetIdList) {
69 Query query = em.createNamedQuery("CluSet.getCluSetInfoByIdList");
70 query.setParameter("cluSetIdList", cluSetIdList);
71 @SuppressWarnings("unchecked")
72 List<CluSet> resultList = query.getResultList();
73 return resultList;
74 }
75
76 @Override
77 public List<Lui> getLuisByIdList(List<String> luiIds) {
78 Query query = em.createNamedQuery("Lui.getLuisByIdList");
79 query.setParameter("luiIdList", luiIds);
80 @SuppressWarnings("unchecked")
81 List<Lui> luis = query.getResultList();
82 return luis;
83 }
84
85 @Override
86 public List<String> getLuiIdsByCluId(String cluId) {
87 Query query = em.createNamedQuery("Lui.getLuiIdsByCluId");
88 query.setParameter("cluId", cluId);
89 @SuppressWarnings("unchecked")
90 List<String> luiIds = query.getResultList();
91 return luiIds;
92 }
93
94 @Override
95 public List<Lui> getLuisByRelationType(String luiId,
96 String luLuRelationTypeId) {
97 Query query = em
98 .createNamedQuery("LuiLuiRelation.getLuisByRelationType");
99 query.setParameter("luiId", luiId);
100 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
101
102 @SuppressWarnings("unchecked")
103 List<Lui> luis = query.getResultList();
104 return luis;
105 }
106
107 @Override
108 public List<String> getLuiIdsByRelationType(String relatedLuiId,
109 String luLuRelationTypeId) {
110 Query query = em
111 .createNamedQuery("LuiLuiRelation.getLuiIdsByRelationType");
112 query.setParameter("luiId", relatedLuiId);
113 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
114
115 @SuppressWarnings("unchecked")
116 List<String> luiIds = query.getResultList();
117 return luiIds;
118 }
119
120 @Override
121 public List<String> getLuiIdsInAtpByCluId(String cluId, String atpKey) {
122 Query query = em.createNamedQuery("Lui.getLuiIdsInAtpByCluId");
123 query.setParameter("cluId", cluId);
124 query.setParameter("atpKey", atpKey);
125 @SuppressWarnings("unchecked")
126 List<String> luiIds = query.getResultList();
127 return luiIds;
128 }
129
130 @Override
131 public Boolean isCluInCluSet(String cluId, String cluSetId) {
132 Query query = em.createNamedQuery("CluSet.isCluInCluSet");
133 query.setParameter("cluId", cluId);
134 query.setParameter("cluSetId", cluSetId);
135 Long valid = (Long) query.getSingleResult();
136 return valid.intValue() > 0;
137 }
138
139 @Override
140 public List<LuiLuiRelation> getLuiLuiRelations(String luiId) {
141 Query query = em
142 .createNamedQuery("LuiLuiRelation.getLuiLuiRelationsByLuiId");
143 query.setParameter("luiId", luiId);
144 @SuppressWarnings("unchecked")
145 List<LuiLuiRelation> luiLuiRelations = query.getResultList();
146 return luiLuiRelations;
147 }
148
149 @Override
150 public List<CluCluRelation> getCluCluRelationsByClu(String cluId) {
151 Query query = em.createNamedQuery("CluCluRelation.getCluCluRelation");
152 query.setParameter("cluId", cluId);
153 @SuppressWarnings("unchecked")
154 List<CluCluRelation> cluCluRelations = query.getResultList();
155 return cluCluRelations;
156 }
157
158 @Override
159 public List<String> getCluIdsByLoId(String loId) {
160 Query query = em.createNamedQuery("Clu.getCluIdsByLoId");
161 query.setParameter("loId", loId);
162 @SuppressWarnings("unchecked")
163 List<String> cluIds = query.getResultList();
164 return cluIds;
165 }
166
167 @Override
168 public List<String> getRelatedCluIdsByCluId(String cluId,
169 String luLuRelationTypeId) {
170 Query query = em
171 .createNamedQuery("CluCluRelation.getRelatedCluIdsByCluId");
172 query.setParameter("cluId", cluId);
173 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
174 @SuppressWarnings("unchecked")
175 List<String> relatedCluIds = query.getResultList();
176 return relatedCluIds;
177 }
178
179 @Override
180 public List<String> getCluIdsByRelatedCluId(String relatedCluId, String luLuRelationTypeId) {
181 Query query = em.createNamedQuery("CluCluRelation.getCluIdsByRelatedCluId");
182 query.setParameter("relatedCluId", relatedCluId);
183 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
184 @SuppressWarnings("unchecked")
185 List<String> relatedCluIds = query.getResultList();
186 return relatedCluIds;
187 }
188
189 @Override
190 public List<Clu> getRelatedClusByCluId(String cluId,
191 String luLuRelationTypeId) {
192 Query query = em
193 .createNamedQuery("CluCluRelation.getRelatedClusByCluId");
194 query.setParameter("cluId", cluId);
195 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
196 @SuppressWarnings("unchecked")
197 List<Clu> relatedClus = query.getResultList();
198 return relatedClus;
199 }
200
201 @Override
202 public List<String> getRelatedLuiIdsByLuiId(String luiId,
203 String luLuRelationTypeId) {
204 Query query = em
205 .createNamedQuery("LuiLuiRelation.getRelatedLuiIdsByLuiId");
206 query.setParameter("luiId", luiId);
207 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
208 @SuppressWarnings("unchecked")
209 List<String> relatedLuiIds = query.getResultList();
210 return relatedLuiIds;
211 }
212
213 @Override
214 public List<Lui> getRelatedLuisByLuiId(String luiId,
215 String luLuRelationTypeId) {
216 Query query = em
217 .createNamedQuery("LuiLuiRelation.getRelatedLuisByLuiId");
218 query.setParameter("luiId", luiId);
219 query.setParameter("luLuRelationTypeId", luLuRelationTypeId);
220 @SuppressWarnings("unchecked")
221 List<Lui> relatedLuis = query.getResultList();
222 return relatedLuis;
223 }
224
225 @Override
226 public List<Clu> getClusByRelation(String parentCluId,
227 String luLuRelationTypeKey) {
228 Query query = em.createNamedQuery("Clu.getClusByRelation");
229 query.setParameter("parentCluId", parentCluId);
230 query.setParameter("luLuRelationTypeKey", luLuRelationTypeKey);
231 @SuppressWarnings("unchecked")
232 List<Clu> resultList = query.getResultList();
233 return resultList;
234 }
235
236 @Override
237 public List<CluLoRelation> getCluLoRelationsByClu(String cluId) {
238 Query query = em
239 .createNamedQuery("CluLoRelation.getCluLoRelationByClu");
240 query.setParameter("cluId", cluId);
241 @SuppressWarnings("unchecked")
242 List<CluLoRelation> cluLoRelations = query.getResultList();
243 return cluLoRelations;
244 }
245
246 @Override
247 public List<CluLoRelation> getCluLoRelationsByLo(String loId) {
248 Query query = em
249 .createNamedQuery("CluLoRelation.getCluLoRelationByLo");
250 query.setParameter("loId", loId);
251 @SuppressWarnings("unchecked")
252 List<CluLoRelation> cluLoRelations = query.getResultList();
253 return cluLoRelations;
254 }
255
256 @Override
257 public List<CluLoRelation> getCluLoRelationsByCludIdAndLoId(String cluId,
258 String loId) {
259 Query query = em.createNamedQuery("CluLoRelation.getCluLoRelation");
260 query.setParameter("cluId", cluId);
261 query.setParameter("loId", loId);
262
263 @SuppressWarnings("unchecked")
264 List<CluLoRelation> rels = query.getResultList();
265 return rels;
266 }
267
268 @Override
269 public List<String> getAllowedLuLuRelationTypesForLuType(String luTypeId,
270 String relatedLuTypeId) {
271 Query query = em
272 .createNamedQuery("AllowedLuLuRelationType.getAllowedTypesByLuTypes");
273 query.setParameter("luTypeId", luTypeId);
274 query.setParameter("relatedLuTypeId", relatedLuTypeId);
275 @SuppressWarnings("unchecked")
276 List<String> resultList = query.getResultList();
277 return resultList;
278 }
279
280 @Override
281 public List<String> getAllowedCluLoRelationTypesForLuType(String luTypeId) {
282 Query query = em
283 .createNamedQuery("AllowedCluLoRealtionType.getAllowedTypesByLuType");
284 query.setParameter("luTypeId", luTypeId);
285 @SuppressWarnings("unchecked")
286 List<String> resultList = query.getResultList();
287 return resultList;
288 }
289
290 @Override
291 public List<String> getAllowedResultUsageTypesForLuType(String luTypeId) {
292 Query query = em
293 .createNamedQuery("AllowedResultUsageLuType.getAllowedTypesByLuType");
294 query.setParameter("luTypeId", luTypeId);
295 @SuppressWarnings("unchecked")
296 List<String> resultList = query.getResultList();
297 return resultList;
298 }
299
300 @Override
301 public List<String> getAllowedResultComponentTypesForResultUsageType(
302 String resultUsageType) {
303 Query query = em
304 .createNamedQuery("AllowedResultComponentUsageType.getAllowedComponentsByUsageType");
305 query.setParameter("resultUsageType", resultUsageType);
306 @SuppressWarnings("unchecked")
307 List<String> resultList = query.getResultList();
308 return resultList;
309 }
310
311 @Override
312 public List<CluResultType> getAllowedCluResultTypesForLuType(String luTypeId) {
313 Query query = em
314 .createNamedQuery("AllowedCluResultLuType.getAllowedTypesByLuType");
315 query.setParameter("luTypeId", luTypeId);
316 @SuppressWarnings("unchecked")
317 List<CluResultType> resultList = query.getResultList();
318 return resultList;
319 }
320
321 @Override
322 public List<String> getCluIdsByResultUsageType(String resultUsageTypeKey) {
323 Query query = em
324 .createNamedQuery("CluResult.getCluIdByResultUsageType");
325 query.setParameter("resultUsageType", resultUsageTypeKey);
326 @SuppressWarnings("unchecked")
327 List<String> resultList = query.getResultList();
328 return resultList;
329 }
330
331 @Override
332 public List<String> getCluIdsByResultComponentId(String resultComponentId) {
333 Query query = em
334 .createNamedQuery("CluResult.getCluIdByResultComponentId");
335 query.setParameter("resultComponentId", resultComponentId);
336 @SuppressWarnings("unchecked")
337 List<String> resultList = query.getResultList();
338 return resultList;
339 }
340
341 @Override
342 public List<String> getAllowedLuLuRelationTypesByLuiId(String luiId,
343 String relatedLuiId) {
344 Query query = em
345 .createNamedQuery("LuiLuiRelation.getRelationTypeByLuiId");
346 query.setParameter("luiId", luiId);
347 query.setParameter("relatedLuiId", relatedLuiId);
348 @SuppressWarnings("unchecked")
349 List<String> resultList = query.getResultList();
350 return resultList;
351 }
352
353 @Override
354 public List<String> getAllowedLuLuRelationTypesByCluId(String cluId,
355 String relatedCluId) {
356 Query query = em
357 .createNamedQuery("CluCluRelation.getRelationTypeByCluId");
358 query.setParameter("cluId", cluId);
359 query.setParameter("relatedCluId", relatedCluId);
360 @SuppressWarnings("unchecked")
361 List<String> resultList = query.getResultList();
362 return resultList;
363 }
364
365 @Override
366 public List<CluResult> getCluResultByClu(String cluId) {
367 Query query = em
368 .createNamedQuery("CluResult.getCluResultByCluId");
369 query.setParameter("cluId", cluId);
370 @SuppressWarnings("unchecked")
371 List<CluResult> resultList = query.getResultList();
372 return resultList;
373 }
374
375 @Override
376 public Clu getLatestCluVersion(String cluVersionIndId) {
377 Query query = em.createNamedQuery("Clu.findLatestClu");
378 query.setParameter("versionIndId", cluVersionIndId);
379 Clu clu = (Clu)query.getSingleResult();
380 return clu;
381 }
382
383 @Override
384 public Clu getCurrentCluVersion(String cluVersionIndId) {
385 Query query = em.createNamedQuery("Clu.findCurrentClu");
386 query.setParameter("versionIndId", cluVersionIndId);
387 query.setParameter("currentTime", new Date());
388 Clu clu = (Clu)query.getSingleResult();
389 return clu;
390 }
391
392 @Override
393 public VersionDisplayInfo getCurrentCluVersionInfo(String cluVersionIndId, String objectTypeURI) {
394 Query query = em.createNamedQuery("Clu.findCurrentVersionInfo");
395 query.setParameter("versionIndId", cluVersionIndId);
396 query.setParameter("currentTime", new Date());
397 VersionDisplayInfo versionDisplayInfo = (VersionDisplayInfo)query.getSingleResult();
398 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
399 return versionDisplayInfo;
400 }
401
402 @Override
403 public VersionDisplayInfo getCurrentVersionOnDate(String versionIndId,
404 String objectTypeURI, Date date) {
405 Query query = em.createNamedQuery("Clu.findCurrentVersionOnDate");
406 query.setParameter("versionIndId", versionIndId);
407 query.setParameter("date", date);
408 VersionDisplayInfo versionDisplayInfo = (VersionDisplayInfo)query.getSingleResult();
409 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
410 return versionDisplayInfo;
411 }
412
413 @Override
414 public VersionDisplayInfo getFirstVersion(String versionIndId,
415 String objectTypeURI) {
416 Query query = em.createNamedQuery("Clu.findFirstVersion");
417 query.setParameter("versionIndId", versionIndId);
418 VersionDisplayInfo versionDisplayInfo = (VersionDisplayInfo)query.getSingleResult();
419 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
420 return versionDisplayInfo;
421 }
422
423 @Override
424 public VersionDisplayInfo getLatestVersion(String versionIndId,
425 String objectTypeURI) {
426 Query query = em.createNamedQuery("Clu.findLatestVersion");
427 query.setParameter("versionIndId", versionIndId);
428 VersionDisplayInfo versionDisplayInfo = (VersionDisplayInfo)query.getSingleResult();
429 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
430 return versionDisplayInfo;
431 }
432
433 @Override
434 public VersionDisplayInfo getVersionBySequenceNumber(String versionIndId,
435 String objectTypeURI, Long sequenceNumber) {
436 Query query = em.createNamedQuery("Clu.findVersionBySequence");
437 query.setParameter("versionIndId", versionIndId);
438 query.setParameter("sequenceNumber", sequenceNumber);
439 VersionDisplayInfo versionDisplayInfo = (VersionDisplayInfo)query.getSingleResult();
440 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
441 return versionDisplayInfo;
442 }
443
444 @Override
445 public List<VersionDisplayInfo> getVersions(String versionIndId,
446 String objectTypeURI) {
447 Query query = em.createNamedQuery("Clu.findVersions");
448 query.setParameter("versionIndId", versionIndId);
449 List<VersionDisplayInfo> versionDisplayInfos = (List<VersionDisplayInfo>)query.getResultList();
450 if(versionDisplayInfos==null){
451 versionDisplayInfos = Collections.emptyList();
452 }
453 for(VersionDisplayInfo versionDisplayInfo:versionDisplayInfos){
454 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
455 }
456 return versionDisplayInfos;
457 }
458
459 @Override
460 public List<VersionDisplayInfo> getVersionsInDateRange(String versionIndId,
461 String objectTypeURI, Date from, Date to) {
462 if(from==null&&to==null){
463 throw new IllegalArgumentException("from and to dates can not both be null");
464 }
465 Query query;
466 if(from==null){
467 query = em.createNamedQuery("Clu.findVersionsBeforeDate");
468 query.setParameter("versionIndId", versionIndId);
469 query.setParameter("date", to);
470 }else if(to==null){
471 query = em.createNamedQuery("Clu.findVersionsAfterDate");
472 query.setParameter("versionIndId", versionIndId);
473 query.setParameter("date", from);
474 }else{
475 query = em.createNamedQuery("Clu.findVersionsInDateRange");
476 query.setParameter("versionIndId", versionIndId);
477 query.setParameter("from", from);
478 query.setParameter("to", to);
479 }
480
481 List<VersionDisplayInfo> versionDisplayInfos = (List<VersionDisplayInfo>)query.getResultList();
482 if(versionDisplayInfos==null){
483 versionDisplayInfos = Collections.emptyList();
484 }
485 for(VersionDisplayInfo versionDisplayInfo:versionDisplayInfos){
486 versionDisplayInfo.setObjectTypeURI(objectTypeURI);
487 }
488 return versionDisplayInfos;
489 }
490
491 @Override
492 public List<CluPublication> getCluPublicationsByType(
493 String luPublicationTypeKey) {
494 Query query = em.createNamedQuery("CluPublication.findCluPublicationsByType");
495 query.setParameter("luPublicationTypeKey", luPublicationTypeKey);
496 List<CluPublication> cluPublications = query.getResultList();
497 return cluPublications;
498 }
499
500 @Override
501 public List<CluPublication> getCluPublicationsByCluId(String cluId) {
502 Query query = em.createNamedQuery("CluPublication.findPublicationsByCluId");
503 query.setParameter("cluId", cluId);
504 List<CluPublication> cluPublications = query.getResultList();
505 return cluPublications;
506 }
507
508 }