1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.r2.lum.lo.dao.impl;
17
18 import java.util.List;
19
20 import javax.persistence.EntityManager;
21 import javax.persistence.PersistenceContext;
22 import javax.persistence.Query;
23
24 import org.kuali.student.r1.common.dao.impl.AbstractCrudDaoImpl;
25 import org.kuali.student.r2.common.exceptions.DependentObjectsExistException;
26 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
27 import org.kuali.student.r2.common.exceptions.UnsupportedActionException;
28 import org.kuali.student.r2.lum.lo.dao.LoDao;
29 import org.kuali.student.r2.lum.lo.entity.Lo;
30 import org.kuali.student.r2.lum.lo.entity.LoCategory;
31 import org.kuali.student.r2.lum.lo.entity.LoLoCategoryJoin;
32 import org.kuali.student.r2.lum.lo.entity.LoLoRelation;
33
34
35
36
37
38 public class LoDaoImpl extends AbstractCrudDaoImpl implements LoDao {
39 @PersistenceContext(unitName = "Lo")
40 @Override
41 public void setEm(EntityManager em) {
42 super.setEm(em);
43 }
44
45
46
47
48 @Override
49 public boolean addLoCategoryToLo(String loCategoryId, String loId) throws UnsupportedActionException, DoesNotExistException {
50 Lo lo = fetch(Lo.class, loId);
51 LoCategory loCategory = fetch(LoCategory.class, loCategoryId);
52 String loRepoId = lo.getLoRepository().getId();
53 String loCategoryRepoId = loCategory.getLoRepository().getId();
54
55 if ( ! loRepoId.equals(loCategoryRepoId) ) {
56 throw new UnsupportedActionException("The learning objective category is not associated with the learning objective's repository");
57 }
58 LoLoCategoryJoin join = new LoLoCategoryJoin();
59 join.setLo(lo);
60 join.setLoCategory(loCategory);
61 create(join);
62 return true;
63 }
64
65
66
67
68 @Override
69 public boolean removeLoCategoryFromLo(String loCategoryId, String loId) throws DoesNotExistException {
70 Query query = em.createNamedQuery("Lo.getLoCategoryJoin");
71 query.setParameter("loCategoryId", loCategoryId);
72 query.setParameter("loId", loId);
73 LoLoCategoryJoin join = (LoLoCategoryJoin) query.getSingleResult();
74 delete(join);
75 return true;
76 }
77
78
79
80
81 @Override
82 public List<Lo> getLoByIdList(List<String> loIds) {
83 Query query = em.createNamedQuery("Lo.findLosByIdList");
84 query.setParameter("idList", loIds);
85 @SuppressWarnings("unchecked")
86 List<Lo> resultList = query.getResultList();
87 return resultList;
88 }
89
90
91
92
93 @Override
94 public boolean deleteLo(String loId) throws DoesNotExistException, DependentObjectsExistException {
95
96 if ( ! getIncludedLos(loId).isEmpty() ) {
97 throw new DependentObjectsExistException("Lo(" +
98 loId+
99 ") cannot be deleted without orphaning child Lo(s).");
100 }
101
102
103
104
105
106
107
108 delete(Lo.class, loId);
109 return true;
110 }
111
112
113
114
115 private List<Lo> getIncludedLos(String loId) throws DoesNotExistException {
116 return getRelatedLosByLoId(loId, "kuali.lo.relation.type.includes");
117 }
118
119
120
121
122 private List<Lo> getIncludingLos(String loId) throws DoesNotExistException {
123 return getLosByRelatedLoId(loId, "kuali.lo.relation.type.includes");
124 }
125
126
127
128
129 @Override
130 public List<Lo> getLosByLoCategory(String loCategoryId) {
131 Query query = em.createNamedQuery("Lo.getLosByLoCategory");
132 query.setParameter("loCategoryId", loCategoryId);
133 @SuppressWarnings("unchecked")
134 List<Lo> resultList = query.getResultList();
135 return resultList;
136 }
137
138
139
140
141 @Override
142 public List<LoCategory> getLoCategories(String loRepositoryKey) {
143 Query query = em.createNamedQuery("Lo.getLoCategories");
144 query.setParameter("repositoryId", loRepositoryKey);
145 @SuppressWarnings("unchecked")
146 List<LoCategory> resultList = query.getResultList();
147 return resultList;
148 }
149
150
151
152
153 @Override
154 public boolean deleteLoCategory(String loCategoryId) throws DoesNotExistException, DependentObjectsExistException {
155 List<Lo> los = getLosByLoCategory(loCategoryId);
156 if (null != los && !los.isEmpty()) {
157 throw new DependentObjectsExistException("LoCategory(" + loCategoryId + ") still has " + los.size() + " Learning Objective(s) associated with it.");
158 }
159 delete(LoCategory.class, loCategoryId);
160 return true;
161 }
162
163 @Override
164 public List<Lo> getRelatedLosByLoId(String loId, String loLoRelationTypeId)
165 throws DoesNotExistException {
166 Query query = em.createNamedQuery("Lo.getRelatedLosByLoId");
167 query.setParameter("loId", loId);
168 query.setParameter("loLoRelationTypeId", loLoRelationTypeId);
169 @SuppressWarnings("unchecked")
170 List<Lo> resultList = query.getResultList();
171 return resultList;
172 }
173
174 @Override
175 public List<Lo> getLosByRelatedLoId(String relatedLoId,
176 String loLoRelationTypeId) throws DoesNotExistException {
177 Query query = em.createNamedQuery("Lo.getLosByRelatedLoId");
178 query.setParameter("relatedLoId", relatedLoId);
179 query.setParameter("loLoRelationTypeId", loLoRelationTypeId);
180 @SuppressWarnings("unchecked")
181 List<Lo> resultList = query.getResultList();
182 return resultList;
183 }
184
185 @Override
186 public void deleteLoLoRelation(String loLoRelationId) throws DoesNotExistException {
187
188
189
190
191
192
193
194
195
196 delete(LoLoRelation.class, loLoRelationId);
197 }
198
199 @Override
200 public List<LoCategory> getLoCategoriesForLo(String loId) {
201 Query query = em.createNamedQuery("Lo.getLoCategoriesForLo");
202 query.setParameter("loId", loId);
203
204 List<LoCategory> resultList = query.getResultList();
205 return resultList;
206 }
207
208 @Override
209 public List<String> getAllowedLoLoRelationTypesForLoType(String loTypeKey, String relatedLoTypeKey) {
210 Query query = em.createNamedQuery("Lo.getAllowedLoLoRelationTypes");
211 query.setParameter("loTypeKey", loTypeKey);
212 query.setParameter("relatedLoTypeKey", relatedLoTypeKey);
213 @SuppressWarnings("unchecked")
214 List<String> resultList = query.getResultList();
215 return resultList;
216 }
217
218 @Override
219 public List<Lo> getLosByRepository(String loRepositoryId) {
220 Query query = em.createNamedQuery("Lo.getLosByRepository");
221 query.setParameter("loRepositoryId", loRepositoryId);
222 @SuppressWarnings("unchecked")
223 List<Lo> resultList = query.getResultList();
224 return resultList;
225 }
226
227 @Override
228 public List<LoLoRelation> getLoLoRelationsByLoId(String loId) {
229 Query query = em.createNamedQuery("Lo.getLoLoRelationsByLoId");
230 query.setParameter("loId", loId);
231 @SuppressWarnings("unchecked")
232 List<LoLoRelation> resultList = query.getResultList();
233 return resultList;
234 }
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370 }