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