View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the the Educational Community License, Version 1.0
5    * (the "License"); you may not use this file except in compliance
6    * with the License.  You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.student.enrollment.class1.lui.service.impl;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.criteria.GenericQueryResults;
21  import org.kuali.rice.core.api.criteria.QueryByCriteria;
22  import org.kuali.student.enrollment.class1.lui.dao.LuiDao;
23  import org.kuali.student.enrollment.class1.lui.dao.LuiLuiRelationDao;
24  import org.kuali.student.enrollment.class1.lui.dao.LuiSetDao;
25  import org.kuali.student.enrollment.class1.lui.model.LuCodeEntity;
26  import org.kuali.student.enrollment.class1.lui.model.LuiAttributeEntity;
27  import org.kuali.student.enrollment.class1.lui.model.LuiEntity;
28  import org.kuali.student.enrollment.class1.lui.model.LuiIdentifierEntity;
29  import org.kuali.student.enrollment.class1.lui.model.LuiLuiRelationEntity;
30  import org.kuali.student.enrollment.class1.lui.model.LuiSetEntity;
31  import org.kuali.student.enrollment.class1.lui.model.LuiUnitsDeploymentEntity;
32  import org.kuali.student.enrollment.lui.dto.LuiCapacityInfo;
33  import org.kuali.student.enrollment.lui.dto.LuiInfo;
34  import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
35  import org.kuali.student.enrollment.lui.dto.LuiSetInfo;
36  import org.kuali.student.enrollment.lui.service.LuiService;
37  import org.kuali.student.r2.common.criteria.CriteriaLookupService;
38  import org.kuali.student.r2.common.dto.ContextInfo;
39  import org.kuali.student.r2.common.dto.StatusInfo;
40  import org.kuali.student.r2.common.dto.ValidationResultInfo;
41  import org.kuali.student.r2.common.exceptions.*;
42  import org.kuali.student.r2.common.infc.ValidationResult;
43  import org.springframework.transaction.annotation.Transactional;
44  
45  import javax.jws.WebParam;
46  import javax.persistence.OptimisticLockException;
47  import java.util.ArrayList;
48  import java.util.List;
49  
50  
51  public class LuiServiceImpl 
52      implements LuiService {
53  
54      private CriteriaLookupService criteriaLookupService;
55  
56      private LuiDao luiDao;
57      private LuiLuiRelationDao luiLuiRelationDao;
58      private LuiSetDao luiSetDao;
59  
60      public LuiDao getLuiDao() {
61          return luiDao;
62      }
63  
64      public void setLuiDao(LuiDao luiDao) {
65          this.luiDao = luiDao;
66      }
67  
68      public LuiSetDao getLuiSetDao() {
69          return luiSetDao;
70      }
71  
72      public void setLuiSetDao(LuiSetDao luiSetDao) {
73          this.luiSetDao = luiSetDao;
74      }
75      
76      public CriteriaLookupService getCriteriaLookupService() {
77          return criteriaLookupService;
78      }
79  
80      public void setCriteriaLookupService(CriteriaLookupService criteriaLookupService) {
81          this.criteriaLookupService = criteriaLookupService;
82      }
83  
84      public LuiLuiRelationDao getLuiLuiRelationDao() {
85          return luiLuiRelationDao;
86      }
87  
88      public void setLuiLuiRelationDao(LuiLuiRelationDao luiLuiRelationDao) {
89          this.luiLuiRelationDao = luiLuiRelationDao;
90      }
91  
92      @Override
93      @Transactional(readOnly = true)
94      public LuiInfo getLui(String luiId, ContextInfo context) 
95          throws DoesNotExistException, InvalidParameterException, 
96                 MissingParameterException, OperationFailedException, 
97                 PermissionDeniedException {
98  
99          LuiEntity lui = luiDao.find(luiId);
100         if (null == lui) {
101             throw new DoesNotExistException(luiId);
102         }
103 
104         return lui.toDto();
105     }
106 
107     @Override
108     @Transactional(readOnly = true)
109     public List<LuiInfo> getLuisByIds(List<String> luiIds, ContextInfo context) 
110         throws DoesNotExistException, InvalidParameterException, 
111                MissingParameterException, OperationFailedException, 
112                PermissionDeniedException {
113 
114         List<LuiEntity> entityList = luiDao.findByIds(luiIds);
115         List<LuiInfo> infoList = new ArrayList<LuiInfo>();
116 
117 
118         for (LuiEntity luiEntity : entityList) {
119 
120             infoList.add(luiEntity.toDto());
121         }
122 
123         return infoList;
124     }
125 
126     @Override
127     @Transactional(readOnly = true)
128     public List<String> getLuiIdsByType(String luiTypeKey, ContextInfo context) 
129         throws InvalidParameterException, MissingParameterException, 
130                OperationFailedException, PermissionDeniedException {
131 
132         // make sure the given type key is a valid lui type
133 
134         List<LuiEntity> luis = luiDao.getLuisByType(luiTypeKey);
135         List<String> luiIds = new ArrayList<String>();
136 
137         for (LuiEntity lui : luis) {
138             luiIds.add(lui.getId());
139         }
140 
141         return luiIds;
142     }
143 
144     @Override
145     @Transactional(readOnly = true)
146     public List<String> getLuiIdsByClu(String cluId, ContextInfo context) 
147         throws InvalidParameterException, MissingParameterException, 
148                OperationFailedException, PermissionDeniedException {
149 
150         List<LuiEntity> luis = luiDao.getLuisByClu(cluId);
151         List<String> luiIds = new ArrayList<String>();
152 
153         for (LuiEntity lui : luis) {
154             luiIds.add(lui.getId());
155         }
156 
157         return luiIds;
158     }
159 
160     @Override
161     @Transactional(readOnly = true)
162     public List<String> getLuiIdsByAtpAndType(String atpId, String typeKey, 
163                                               ContextInfo context) 
164         throws InvalidParameterException, MissingParameterException, 
165                OperationFailedException, PermissionDeniedException {
166         return luiDao.getLuisIdsByAtpAndType(atpId,typeKey);
167     }
168 
169     @Override
170     @Transactional(readOnly = true)
171     public List<String> getLuiIdsByAtpAndClu(String cluId, String atpId,ContextInfo context)
172         throws InvalidParameterException, MissingParameterException, 
173                OperationFailedException, PermissionDeniedException {
174 
175         List<LuiEntity> luis = luiDao.getLuisByAtpAndClu(atpId, cluId);
176         List<String> luiIds = new ArrayList<String>();
177 
178         for (LuiEntity lui : luis) {
179             luiIds.add(lui.getId());
180         }
181 
182         return luiIds;
183     }
184 
185     @Override
186     @Transactional(readOnly = true)
187     public List<LuiInfo> getLuisByAtpAndClu(String cluId, String atpId, 
188                                             ContextInfo context) 
189         throws InvalidParameterException, MissingParameterException, 
190                OperationFailedException, PermissionDeniedException {
191 
192         List<LuiEntity> luiEntities = luiDao.getLuisByAtpAndClu(atpId, cluId);
193         List<LuiInfo> luiInfos = new ArrayList<LuiInfo>();
194         for(LuiEntity luiEntity: luiEntities){
195             luiInfos.add(luiEntity.toDto());
196         }
197       return luiInfos;
198 
199     }
200 
201     @Override
202     @Transactional(readOnly = true)
203     public List<String> searchForLuiIds(QueryByCriteria criteria, 
204                                         ContextInfo context) 
205         throws InvalidParameterException, MissingParameterException, 
206                OperationFailedException, PermissionDeniedException {
207 
208         GenericQueryResults<String> results = criteriaLookupService.lookupIds(LuiEntity.class, criteria);
209         return results.getResults();
210 
211     }
212 
213     @Override
214     @Transactional(readOnly = true)
215     public List<LuiInfo> searchForLuis(QueryByCriteria criteria, 
216                                        ContextInfo context) 
217         throws InvalidParameterException, MissingParameterException, 
218                OperationFailedException, PermissionDeniedException {
219 
220         return new ArrayList<LuiInfo>();
221     }
222 
223     @Override
224     public List<ValidationResultInfo> validateLui(String validationTypeKey, 
225                                                   String luiTypeKey, 
226                                                   String cluId, 
227                                                   String atpId, 
228                                                   LuiInfo luiInfo, 
229                                                   ContextInfo context) 
230         throws DoesNotExistException, InvalidParameterException, 
231                MissingParameterException, OperationFailedException, 
232                PermissionDeniedException {
233         return new ArrayList<ValidationResultInfo>();
234     }
235 
236     @Override
237     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
238     public LuiInfo createLui(String cluId, String atpId, String luiTypeKey, LuiInfo luiInfo, ContextInfo context) 
239         throws DataValidationErrorException, DoesNotExistException, 
240                InvalidParameterException, MissingParameterException, 
241                OperationFailedException, PermissionDeniedException, 
242                ReadOnlyException {
243 
244         if (!cluId.equals(luiInfo.getCluId())) {
245             throw new InvalidParameterException(cluId + " does not match the cluId in the info object " + luiInfo.getCluId());
246         }
247         if (!atpId.equals(luiInfo.getAtpId())) {
248             throw new InvalidParameterException(atpId + " does not match the atp in the info object " + luiInfo.getAtpId());
249         }
250         if (!luiTypeKey.equals(luiInfo.getTypeKey())) {
251             throw new InvalidParameterException(luiTypeKey + " does not match the type in the info object " + luiInfo.getTypeKey());
252         }
253 
254         LuiEntity entity = new LuiEntity(luiInfo);
255         entity.setAtpId(atpId);
256         entity.setCluId(cluId);
257         entity.setLuiType(luiTypeKey);
258         
259         entity.setEntityCreated(context);
260         
261         if(entity.getIdentifiers() != null){
262             for(LuiIdentifierEntity ident:entity.getIdentifiers()){
263                 ident.setCreateId(context.getPrincipalId());
264                 ident.setCreateTime(context.getCurrentDate());
265                 ident.setUpdateId(context.getPrincipalId());
266                 ident.setUpdateTime(context.getCurrentDate());
267             }
268         }
269         if(entity.getLuiCodes() != null){
270             for(LuCodeEntity code : entity.getLuiCodes()){
271                 code.setCreateId(context.getPrincipalId());
272                 code.setCreateTime(context.getCurrentDate());
273                 code.setUpdateId(context.getPrincipalId());
274                 code.setUpdateTime(context.getCurrentDate());
275             }
276         }
277 
278 
279         luiDao.persist(entity);
280 
281         return entity.toDto();
282     }
283 
284     @Override
285     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
286     public LuiInfo updateLui(String luiId, LuiInfo luiInfo, ContextInfo context) 
287         throws DataValidationErrorException, DoesNotExistException, 
288                InvalidParameterException, MissingParameterException, 
289                OperationFailedException, PermissionDeniedException, 
290                ReadOnlyException, VersionMismatchException {
291 
292         LuiEntity entity = luiDao.find(luiId);
293 
294         if (!luiId.equals(luiInfo.getId())) {
295             throw new InvalidParameterException(luiId + " does not match the id on the object " + luiInfo.getId());
296         }
297         if (null == entity) {
298             throw new DoesNotExistException(luiId);
299         }
300 
301         //Transform the DTO to the entity
302         List<Object> orphans = entity.fromDto(luiInfo);
303 
304         //Delete any orphaned children
305         for(Object orphan : orphans){
306             luiDao.getEm().remove(orphan);
307         }
308 
309         //Update any Meta information
310        
311         entity.setEntityUpdated(context);
312         
313 
314         if(entity.getIdentifiers() != null){
315             for(LuiIdentifierEntity ident:entity.getIdentifiers()){
316                 if(ident.getCreateId() == null){
317                     ident.setCreateId(context.getPrincipalId());
318                 }
319                 if(ident.getCreateTime() == null){
320                     ident.setCreateTime(context.getCurrentDate());
321                 }
322                 ident.setUpdateId(context.getPrincipalId());
323                 ident.setUpdateTime(context.getCurrentDate());
324             }
325         }
326         if(entity.getLuiCodes() != null){
327             for(LuCodeEntity code : entity.getLuiCodes()){
328                 if(code.getCreateId() == null){
329                     code.setCreateId(context.getPrincipalId());
330                 }
331                 if(code.getCreateTime() == null){
332                     code.setCreateTime(context.getCurrentDate());
333                 }
334                 code.setUpdateId(context.getPrincipalId());
335                 code.setUpdateTime(context.getCurrentDate());
336             }
337         }
338 
339         //Perform the merge
340         entity = luiDao.merge(entity);
341 
342         return entity.toDto();
343     }
344 
345     @Override
346     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
347     public StatusInfo deleteLui(String luiId, ContextInfo context) 
348         throws DependentObjectsExistException, DoesNotExistException, 
349                InvalidParameterException, MissingParameterException, 
350                OperationFailedException, PermissionDeniedException {
351 
352         LuiEntity entity = luiDao.find(luiId);
353         if (null == entity) {
354             throw new DoesNotExistException(luiId);
355         }
356         //Delete relationships
357         for (LuiLuiRelationEntity rel : luiLuiRelationDao.getLuiLuiRelationsByLui(luiId)) {
358             luiLuiRelationDao.remove(rel);
359         }
360         //Delete attributes
361         if(entity.getAttributes()!=null){
362             for(LuiAttributeEntity attr:entity.getAttributes()){
363                 luiDao.getEm().remove(attr); //TODO why is the dao strongly typed to a single entity?
364             }
365         }
366         //Delete identifiers
367         if(entity.getIdentifiers()!=null){
368             for(LuiIdentifierEntity ident:entity.getIdentifiers()){
369                 luiDao.getEm().remove(ident);
370             }
371         }
372         //Delete units
373         if(entity.getLuiUnitsDeployment()!=null){
374             for(LuiUnitsDeploymentEntity units:entity.getLuiUnitsDeployment()){
375                 luiDao.getEm().remove(units);
376             }
377         }
378         //Delete Codes
379         if(entity.getLuiCodes()!=null){
380             for(LuCodeEntity luiCode:entity.getLuiCodes()){
381                 luiDao.getEm().remove(luiCode);
382             }
383         }
384 
385         //Delete the actual Lui entity
386         luiDao.remove(entity);
387 
388         return new StatusInfo();
389     }
390 
391     @Override
392     @Transactional(readOnly = true)
393     public LuiLuiRelationInfo getLuiLuiRelation(String luiLuiRelationId, 
394                                                 ContextInfo context) 
395         throws InvalidParameterException, MissingParameterException, 
396                OperationFailedException, PermissionDeniedException {
397 
398         return luiLuiRelationDao.find(luiLuiRelationId).toDto();
399     }
400 
401     @Override
402     @Transactional(readOnly = true)
403     public List<LuiLuiRelationInfo> getLuiLuiRelationsByIds(List<String> luiLuiRelationIds, 
404                                                             ContextInfo context) 
405         throws InvalidParameterException, MissingParameterException, 
406                OperationFailedException, PermissionDeniedException {
407 
408         throw new UnsupportedOperationException("Not supported yet.");
409     }
410 
411     @Override
412     @Transactional(readOnly = true)
413     public List<String> getLuiLuiRelationIdsByType(String luiLuiRelationTypeKey, 
414                                                    ContextInfo context) 
415         throws InvalidParameterException, MissingParameterException, 
416                OperationFailedException, PermissionDeniedException {
417 
418         throw new UnsupportedOperationException("Not supported yet.");
419     }
420 
421     @Override
422     @Transactional(readOnly = true)
423     public List<LuiLuiRelationInfo> getLuiLuiRelationsByLui(String luiId, 
424                                                             ContextInfo context) 
425         throws InvalidParameterException, MissingParameterException, 
426                OperationFailedException, PermissionDeniedException { 
427 
428 
429 
430         List<LuiLuiRelationEntity> relEntities = luiLuiRelationDao.getLuiLuiRelationsByLui(luiId);
431         List<LuiLuiRelationInfo> relInfos = new ArrayList<LuiLuiRelationInfo>();
432         if (relEntities != null && !relEntities.isEmpty()) {
433             for (LuiLuiRelationEntity relEntity : relEntities) {
434                 LuiLuiRelationInfo relInfo = relEntity.toDto();
435                 relInfos.add(relInfo);
436             }
437         }
438         return relInfos;
439     }
440 
441     @Override
442     @Transactional(readOnly = true)
443     public List<LuiLuiRelationInfo> getLuiLuiRelationsByLuiAndRelatedLui(String luiId,
444                                                                          String relatedLuiId,
445                                                                          ContextInfo context)
446         throws InvalidParameterException, MissingParameterException, 
447                OperationFailedException, PermissionDeniedException { 
448 
449         throw new UnsupportedOperationException("Not supported yet.");
450     }
451     
452     @Override
453     @Transactional(readOnly = true)
454     public List<LuiInfo> getLuiLuiRelationsByLuiAndRelatedLuiType(String luiId,
455                                                                   String relatedLuiTypeKey,
456                                                                   ContextInfo contextInfo)
457         throws InvalidParameterException, MissingParameterException, 
458                OperationFailedException, PermissionDeniedException {
459         throw new UnsupportedOperationException("Not supported yet.");
460     }
461 
462     @Override
463     @Transactional(readOnly = true)
464     public List<LuiInfo> getLuisByRelatedLuiAndRelationType(String relatedLuiId,
465                                                             String luiLuiRelationTypeKey,
466                                                             ContextInfo context)
467         throws InvalidParameterException, MissingParameterException, 
468                OperationFailedException, PermissionDeniedException {
469         
470         List<LuiEntity> entityList = luiLuiRelationDao.getLuisByRelation(relatedLuiId, luiLuiRelationTypeKey);
471         List<LuiInfo> infoList = new ArrayList<LuiInfo>();
472         if (entityList != null && !entityList.isEmpty()) {
473             for (LuiEntity entity : entityList) {
474                 infoList.add(entity.toDto());
475             }
476 
477         }
478 
479         return infoList;
480     }
481 
482     @Override
483     @Transactional(readOnly = true)
484     public List<String> getLuiIdsByRelatedLuiAndRelationType(String relatedLuiId,
485                                                              String luiLuiRelationTypeKey,
486                                                              ContextInfo context)
487         throws InvalidParameterException, MissingParameterException, 
488                OperationFailedException, PermissionDeniedException {
489 
490         List<String> returnVals = new ArrayList<String>();
491         returnVals.addAll(luiLuiRelationDao.getLuiIdsByRelation(relatedLuiId, luiLuiRelationTypeKey));
492         return returnVals;
493     }
494 
495     @Override
496     @Transactional(readOnly = true)
497     public List<String> getLuiIdsByLuiAndRelationType(String luiId,
498                                                       String luiLuiRelationTypeKey,
499                                                       ContextInfo context)
500         throws InvalidParameterException, MissingParameterException, 
501                OperationFailedException, PermissionDeniedException {
502 
503         List<String> returnVals = new ArrayList<String>();
504         returnVals.addAll(luiLuiRelationDao.getRelatedLuisByLuiId(luiId, luiLuiRelationTypeKey));
505         return returnVals;
506     }
507 
508     @Override
509     @Transactional(readOnly = true)
510     public List<LuiInfo> getRelatedLuisByLuiAndRelationType(String luiId,
511                                                             String luiLuiRelationTypeKey,
512                                                             ContextInfo context)
513         throws InvalidParameterException, MissingParameterException, 
514                OperationFailedException, PermissionDeniedException {
515         if (luiId == null) {
516             throw new MissingParameterException("luiId is null");
517         }
518         List<LuiInfo> relatedLuis =  new ArrayList<LuiInfo>();
519         List<LuiEntity> relatedLuiEntities =  luiLuiRelationDao.getRelatedLuisByLuiIdAndRelationType(luiId, luiLuiRelationTypeKey);
520         for(LuiEntity relatedLuiEntity : relatedLuiEntities) {
521             relatedLuis.add(relatedLuiEntity.toDto());
522         }
523 
524         return  relatedLuis;
525     }
526 
527     @Override
528     @Transactional(readOnly = true)
529     public List<String> searchForLuiLuiRelationIds(QueryByCriteria criteria, 
530                                                    ContextInfo context) 
531         throws InvalidParameterException, MissingParameterException, 
532                OperationFailedException, PermissionDeniedException {
533 
534         GenericQueryResults<String> results = criteriaLookupService.lookupIds(LuiLuiRelationEntity.class, criteria);
535         return results.getResults();
536     }
537 
538     @Override
539     @Transactional(readOnly = true)
540     public List<LuiLuiRelationInfo> searchForLuiLuiRelations(QueryByCriteria criteria, 
541                                                              ContextInfo context) 
542         throws InvalidParameterException, MissingParameterException, 
543                OperationFailedException, PermissionDeniedException {
544 
545         List<LuiLuiRelationInfo> relationInfos = new ArrayList<LuiLuiRelationInfo>();
546 
547         GenericQueryResults<LuiLuiRelationEntity> results = criteriaLookupService.lookup(LuiLuiRelationEntity.class, criteria);
548         for(LuiLuiRelationEntity entity : results.getResults()){
549             relationInfos.add(entity.toDto());
550         }
551         return relationInfos;
552     }
553 
554     @Override
555     @Transactional(readOnly = true)
556     public List<ValidationResultInfo> validateLuiLuiRelation(String validationTypeKey, 
557                                                              String luiId,
558                                                              String relatedLuiId,
559                                                              String luiLuiRelationTypeKey,
560                                                              LuiLuiRelationInfo luiLuiRelationInfo, 
561                                                              ContextInfo context) 
562         throws DoesNotExistException, InvalidParameterException, 
563                MissingParameterException, OperationFailedException {
564 
565        List<ValidationResultInfo> validationResultInfos = new ArrayList<ValidationResultInfo>() ;
566         ValidationResultInfo invalidIdsValidationInfo = new ValidationResultInfo();
567         if(luiLuiRelationInfo.getLuiId() ==null || luiLuiRelationInfo.getRelatedLuiId() == null)        {
568             invalidIdsValidationInfo.setError("Relation Info is missing relation id data");
569             invalidIdsValidationInfo.setLevel(ValidationResult.ErrorLevel.ERROR);
570             validationResultInfos.add(invalidIdsValidationInfo);
571         }
572         ValidationResultInfo typeStateValidation = new ValidationResultInfo();
573         if(luiLuiRelationInfo.getTypeKey() ==null || luiLuiRelationInfo.getStateKey()==null ){
574             typeStateValidation.setError("Missing type or state data");
575             typeStateValidation.setLevel(ValidationResult.ErrorLevel.ERROR);
576             validationResultInfos.add(typeStateValidation);
577 
578         }
579             return validationResultInfos;
580     }
581 
582     @Override
583     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
584     public LuiLuiRelationInfo createLuiLuiRelation(String luiId, 
585                                                    String relatedLuiId, 
586                                                    String luiLuiRelationTypeKey, 
587                                                    LuiLuiRelationInfo luiLuiRelationInfo, 
588                                                    ContextInfo context)
589         throws DataValidationErrorException,
590                DoesNotExistException, InvalidParameterException,
591                MissingParameterException, OperationFailedException, 
592                PermissionDeniedException, ReadOnlyException  {
593 
594         LuiLuiRelationEntity entity = new LuiLuiRelationEntity(luiLuiRelationInfo);
595         entity.setLuiLuiRelationType(luiLuiRelationTypeKey);
596         entity.setLui(luiDao.find(luiId));
597         if (entity.getLui() == null) {
598             throw new DoesNotExistException(luiId);
599         }
600 
601         entity.setRelatedLui(luiDao.find(relatedLuiId));
602         if (entity.getRelatedLui() == null) {
603             throw new DoesNotExistException(relatedLuiId);
604         }
605 
606         entity.setLuiLuiRelationType(luiLuiRelationTypeKey);
607         
608         entity.setEntityCreated(context);
609         
610         luiLuiRelationDao.persist(entity);
611 
612         return entity.toDto();
613     }
614 
615     @Override
616     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
617     public LuiLuiRelationInfo updateLuiLuiRelation(String luiLuiRelationId, 
618                                                    LuiLuiRelationInfo luiLuiRelationInfo, 
619                                                    ContextInfo context) 
620         throws DataValidationErrorException, DoesNotExistException, 
621                InvalidParameterException, MissingParameterException, 
622                OperationFailedException, PermissionDeniedException, 
623                ReadOnlyException, VersionMismatchException {
624 
625 
626         if (!luiLuiRelationId.equals(luiLuiRelationInfo.getId())) {
627             throw new InvalidParameterException(luiLuiRelationId + " does not match the id on the object " + luiLuiRelationInfo.getId());
628         }
629 
630         LuiLuiRelationEntity entity = luiLuiRelationDao.find(luiLuiRelationId);
631         if (entity == null) {
632             throw new DoesNotExistException(luiLuiRelationId);
633         }
634 
635 
636         //Transform the DTO to the entity
637         List<Object> orphans = entity.fromDto(luiLuiRelationInfo);
638         
639         entity.setEntityUpdated(context);
640         
641 
642         luiLuiRelationDao.merge(entity);
643 
644         //Delete any orphaned children
645         for(Object orphan : orphans){
646             luiLuiRelationDao.getEm().remove(orphan);
647         }
648 
649         return entity.toDto();
650     }
651 
652     @Override
653     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
654     public StatusInfo deleteLuiLuiRelation(String luiLuiRelationId, 
655                                            ContextInfo context) 
656         throws DoesNotExistException, InvalidParameterException, 
657                MissingParameterException, OperationFailedException, 
658                PermissionDeniedException {
659 
660         LuiLuiRelationEntity entity = luiLuiRelationDao.find(luiLuiRelationId);
661         if (entity == null) {
662             throw new DoesNotExistException(luiLuiRelationId);
663         }
664         luiLuiRelationDao.remove(entity);
665         StatusInfo status = new StatusInfo();
666         status.setSuccess(Boolean.TRUE);
667 
668         return status;
669     }
670 
671     @Override
672     @Transactional(readOnly = true)
673     public LuiCapacityInfo getLuiCapacity(String luiCapacityId, 
674                                           ContextInfo context) 
675         throws DoesNotExistException, InvalidParameterException, 
676                MissingParameterException, OperationFailedException, 
677                PermissionDeniedException {
678 
679         throw new UnsupportedOperationException("Not supported yet.");
680     }
681 
682     @Override
683     @Transactional(readOnly = true)
684     public List<LuiCapacityInfo> getLuiCapacitiesByIds(List<String> luiCapacityIds, 
685                                                        ContextInfo context) 
686         throws DoesNotExistException, InvalidParameterException, 
687                MissingParameterException, OperationFailedException, 
688                PermissionDeniedException {
689 
690         throw new UnsupportedOperationException("Not supported yet.");
691     }
692 
693     @Override
694     @Transactional(readOnly = true)
695     public List<LuiCapacityInfo> getLuiCapacitiesByLui(String luiId, 
696                                                        ContextInfo context) 
697         throws InvalidParameterException, MissingParameterException, 
698                OperationFailedException, PermissionDeniedException {
699 
700         throw new UnsupportedOperationException("Not supported yet.");
701     }
702 
703     @Override
704     @Transactional(readOnly = true)
705     public List<String> getLuiCapacityIdsByType(String luiCapacityTypeKey, 
706                                                 ContextInfo context) 
707         throws InvalidParameterException, MissingParameterException, 
708                OperationFailedException, PermissionDeniedException {
709 
710         throw new UnsupportedOperationException("Not supported yet.");
711     }
712 
713     @Override
714     @Transactional(readOnly = true)
715     public List<String> searchForLuiCapacityIds(QueryByCriteria criteria, 
716                                                 ContextInfo context) 
717         throws InvalidParameterException, MissingParameterException, 
718                OperationFailedException, PermissionDeniedException {
719 
720         throw new UnsupportedOperationException("Not supported yet.");
721     }
722 
723     @Override
724     @Transactional(readOnly = true)
725     public List<LuiCapacityInfo> searchForLuiCapacities(QueryByCriteria criteria, 
726                                                         ContextInfo context) 
727         throws InvalidParameterException, MissingParameterException, 
728                OperationFailedException, PermissionDeniedException {
729 
730         throw new UnsupportedOperationException("Not supported yet.");
731     }
732 
733     @Override
734     public List<ValidationResultInfo> validateLuiCapacity(String validationTypeKey, 
735                                                           String luiCapacityTypeKey, 
736                                                           LuiCapacityInfo luiCapacityInfo, 
737                                                           ContextInfo context) 
738         throws DoesNotExistException, InvalidParameterException, 
739                MissingParameterException, OperationFailedException, 
740                PermissionDeniedException {
741 
742         throw new UnsupportedOperationException("Not supported yet.");
743     }
744 
745     @Override
746     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
747     public LuiCapacityInfo createLuiCapacity(String luiCapacityTypeKey, 
748                                              LuiCapacityInfo luiCapacityInfo, 
749                                              ContextInfo context) 
750         throws DataValidationErrorException, DoesNotExistException, 
751                InvalidParameterException, MissingParameterException, 
752                OperationFailedException, PermissionDeniedException, 
753                ReadOnlyException {
754 
755         throw new UnsupportedOperationException("Not supported yet.");
756     }
757 
758     @Override
759     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
760     public LuiCapacityInfo updateLuiCapacity(String luiCapacityId, 
761                                              LuiCapacityInfo luiCapacityInfo, 
762                                              ContextInfo context) 
763         throws DataValidationErrorException, DoesNotExistException, 
764                InvalidParameterException, MissingParameterException, 
765                OperationFailedException, PermissionDeniedException, 
766                ReadOnlyException, VersionMismatchException {
767 
768         throw new UnsupportedOperationException("Not supported yet.");
769     }
770 
771     @Override
772     @Transactional(readOnly = false, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
773     public StatusInfo deleteLuiCapacity(String luiCapacityId, 
774                                         ContextInfo context) 
775         throws DoesNotExistException, InvalidParameterException, 
776                MissingParameterException, OperationFailedException, 
777                PermissionDeniedException {
778 
779         throw new UnsupportedOperationException("Not supported yet.");
780     }
781 
782     @Override
783     public LuiSetInfo getLuiSet(String luiSetId,  ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
784         LuiSetEntity luiSetEntity = luiSetDao.find (luiSetId);
785 
786         if (luiSetEntity == null) {
787             throw new DoesNotExistException("No existing Lui for id = " + luiSetId);
788         }
789 
790         return luiSetEntity.toDto();
791     }
792 
793     @Override
794     public List<LuiSetInfo> getLuiSetsByIds(List<String> luiSetIds,  ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
795 
796         List<LuiSetEntity> luiSetEntities = luiSetDao.findByIds(luiSetIds);
797         List<LuiSetInfo> luiSetInfos = new ArrayList<LuiSetInfo>();
798 
799         for (LuiSetEntity luiSetEntity : luiSetEntities) {
800             luiSetInfos.add(luiSetEntity.toDto());
801         }
802 
803         return luiSetInfos;
804     }
805 
806     @Override
807     public List<String> getLuiIdsFromLuiSet( String luiSetId,  ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
808         LuiSetEntity luiSetEntity = luiSetDao.find(luiSetId);
809 
810         if (luiSetEntity == null) {
811             throw new DoesNotExistException("No existing Lui set for id = " + luiSetId);
812         }
813 
814         return luiSetEntity.getLuiIds();
815     }
816 
817     @Override
818     public List<ValidationResultInfo> validateLuiSet( String validationTypeKey,  String luiSetTypeKey, LuiSetInfo LuiSetInfo,  ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
819         return new ArrayList<ValidationResultInfo>();
820     }
821 
822     @Override
823     public LuiSetInfo createLuiSet( String luiSetTypeKey, LuiSetInfo luiSetInfo,  ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, UnsupportedActionException {
824 
825         if (!StringUtils.equals(luiSetTypeKey,luiSetInfo.getTypeKey())) {
826             throw new InvalidParameterException(luiSetTypeKey + " does not match the type in the info object " + luiSetInfo.getTypeKey());
827         }
828 
829         LuiSetEntity entity = new LuiSetEntity(luiSetInfo);
830         entity.setEntityCreated(contextInfo);
831         luiSetDao.persist(entity);
832 
833         return entity.toDto();
834     }
835 
836     @Override
837     public LuiSetInfo updateLuiSet( String luiSetId, LuiSetInfo luiSetInfo,  ContextInfo contextInfo) throws CircularRelationshipException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, UnsupportedActionException, VersionMismatchException {
838         LuiSetEntity luiSetEntity = luiSetDao.find (luiSetId);
839         
840         if (luiSetEntity == null) {
841             throw new DoesNotExistException("No existing Lui set for id = " + luiSetId);
842         }
843 
844         luiSetEntity.fromDto(luiSetInfo);
845         luiSetEntity.setUpdateId(contextInfo.getPrincipalId());
846         luiSetEntity.setUpdateTime(contextInfo.getCurrentDate());
847 
848         // this line can be removed once KSENROLL-4605 is resolved
849         if (luiSetInfo.getMeta() != null)
850             luiSetEntity.setVersionNumber(new Long (luiSetInfo.getMeta().getVersionInd()));
851 
852         try {
853             luiSetEntity = luiSetDao.merge(luiSetEntity);
854         } catch (OptimisticLockException e) {
855             throw new VersionMismatchException();
856         }
857 
858 //        luiSetDao.getEm().flush();
859         return luiSetEntity.toDto();
860     }
861 
862     @Override
863     public StatusInfo deleteLuiSet( String luiSetId,  ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
864         LuiSetEntity luiSetEntity = luiSetDao.find (luiSetId);
865 
866         if (luiSetEntity == null) {
867             throw new DoesNotExistException("No existing Lui set for id = " + luiSetId);
868         }
869 
870         luiSetDao.remove(luiSetEntity);
871 
872         return new StatusInfo();
873     }
874 
875     @Override
876     public List<LuiSetInfo> getLuiSetsByLui(String luiId,  ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
877         List<LuiSetEntity> luiSetEntities = luiSetDao.getLuiSetsByLui(luiId);
878         List<LuiSetInfo> luiSetInfos = new ArrayList<LuiSetInfo>();
879         for (LuiSetEntity luiSetEntity : luiSetEntities) {
880             luiSetInfos.add(luiSetEntity.toDto());
881         }
882         return luiSetInfos;
883     }
884 
885     @Override
886     public List<String> getLuiSetIdsByType(String luiSetTypeKey,  ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
887         return luiSetDao.getLuiSetIdsByType(luiSetTypeKey);
888     }
889 }