Coverage Report - org.kuali.student.enrollment.class1.lpr.service.impl.LprServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
LprServiceImpl
0%
0/289
0%
0/122
2.977
 
 1  
 /*
 2  
  * Copyright 2009 The Kuali Foundation Licensed under the Educational Community License, Version 1.0 (the "License"); you may
 3  
  * not use this file except in compliance with the License. You may obtain a copy of the License at
 4  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law or agreed to in writing, software
 5  
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 6  
  * express or implied. See the License for the specific language governing permissions and limitations under the License.
 7  
  */
 8  
 package org.kuali.student.enrollment.class1.lpr.service.impl;
 9  
 
 10  
 import java.util.ArrayList;
 11  
 import java.util.List;
 12  
 
 13  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 14  
 import org.kuali.student.common.util.UUIDHelper;
 15  
 import org.kuali.student.enrollment.class1.lpr.dao.LprDao;
 16  
 import org.kuali.student.enrollment.class1.lpr.dao.LprRosterDao;
 17  
 import org.kuali.student.enrollment.class1.lpr.dao.LprRosterEntryDao;
 18  
 import org.kuali.student.enrollment.class1.lpr.dao.LprTransactionDao;
 19  
 import org.kuali.student.enrollment.class1.lpr.dao.LprTransactionItemDao;
 20  
 import org.kuali.student.enrollment.class1.lpr.model.LprTransactionEntity;
 21  
 import org.kuali.student.enrollment.class1.lpr.model.LprTransactionItemEntity;
 22  
 import org.kuali.student.enrollment.class1.lpr.model.LprEntity;
 23  
 import org.kuali.student.enrollment.class1.roster.model.LprRichTextEntity;
 24  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo;
 25  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo;
 26  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemResultInfo;
 27  
 import org.kuali.student.enrollment.lpr.dto.LprInfo;
 28  
 import org.kuali.student.enrollment.lpr.service.LprService;
 29  
 import org.kuali.student.r2.common.dto.BulkStatusInfo;
 30  
 import org.kuali.student.r2.common.dto.ContextInfo;
 31  
 import org.kuali.student.r2.common.dto.RichTextInfo;
 32  
 import org.kuali.student.r2.common.dto.StatusInfo;
 33  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 34  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 35  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 36  
 import org.kuali.student.r2.common.exceptions.DisabledIdentifierException;
 37  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 38  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 39  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 40  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 41  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 42  
 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
 43  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 44  
 import org.kuali.student.r2.core.class1.util.ValidationUtils;
 45  
 import org.springframework.transaction.annotation.Transactional;
 46  
 
 47  
 /**
 48  
  * @author sambit
 49  
  */
 50  
 //@Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
 51  0
 public class LprServiceImpl implements LprService {
 52  
 
 53  
     private LprDao lprDao;
 54  
     private LprTransactionDao lprTransDao;
 55  
     private LprTransactionItemDao lprTransItemDao;
 56  
 
 57  
     public void setLprTransItemDao(LprTransactionItemDao lprTransItemDao) {
 58  0
         this.lprTransItemDao = lprTransItemDao;
 59  0
     }
 60  
 
 61  
     public LprTransactionDao getLprTransDao() {
 62  0
         return lprTransDao;
 63  
     }
 64  
 
 65  
     public void setLprTransDao(LprTransactionDao lprTransDao) {
 66  0
         this.lprTransDao = lprTransDao;
 67  0
     }
 68  
 
 69  
     public LprDao getLprDao() {
 70  0
         return lprDao;
 71  
     }
 72  
 
 73  
     public void setLprDao(LprDao lprDao) {
 74  0
         this.lprDao = lprDao;
 75  0
     }
 76  
   
 77  
     private List<LprInfo> getLprsByLuiPersonAndState(String personId, String luiId, String stateKey, ContextInfo context) throws
 78  
             DoesNotExistException, DisabledIdentifierException, InvalidParameterException, MissingParameterException,
 79  
             OperationFailedException, PermissionDeniedException {
 80  0
         List<LprInfo> lprs = this.getLprsByPersonAndLui(personId, luiId, context);
 81  0
         List<LprInfo> list = new ArrayList<LprInfo>(lprs.size());
 82  0
         for (LprInfo lpr : lprs) {
 83  0
             if (lpr.getStateKey().equals(stateKey)) {
 84  0
                 list.add(lpr);
 85  
             }
 86  
         }
 87  0
         return list;
 88  
     }
 89  
     /*
 90  
     @Transactional
 91  
     private String createLprFromLprTransactionItem(LprTransactionItemInfo lprTransactionItemInfo, ContextInfo context) throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 92  
     LprInfo luiPersonRelation = new LprInfo();
 93  
     luiPersonRelation.setCommitmentPercent(100.00F);
 94  
     luiPersonRelation.setEffectiveDate(new Date());
 95  
     luiPersonRelation.setLuiId(lprTransactionItemInfo.getNewLuiId());
 96  
     luiPersonRelation.setPersonId(lprTransactionItemInfo.getPersonId());
 97  
     luiPersonRelation.setStateKey(LprServiceConstants.REGISTERED_STATE_KEY);
 98  
     luiPersonRelation.setTypeKey(LprServiceConstants.REGISTRANT_TYPE_KEY);
 99  
     String createdLpr;
 100  
     try {
 101  
     createdLpr = createLpr(lprTransactionItemInfo.getPersonId(), lprTransactionItemInfo.getNewLuiId(), LprServiceConstants.REGISTRANT_TYPE_KEY, luiPersonRelation, context);
 102  
     
 103  
     } catch (DisabledIdentifierException e) {
 104  
     throw new OperationFailedException(e.getMessage(), e);
 105  
     } catch (ReadOnlyException e) {
 106  
     throw new OperationFailedException(e.getMessage(), e);
 107  
     }
 108  
     
 109  
     return createdLpr;
 110  
     }
 111  
      */
 112  
 
 113  
     @Override
 114  
     @Transactional(readOnly=true)
 115  
     public List<LprInfo> getLprsByLui(String luiId, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 116  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 117  0
         List<LprEntity> luiPersonRelations = lprDao.getByLuiId(luiId);
 118  0
         List<LprInfo> dtos = new ArrayList<LprInfo>();
 119  0
         for (LprEntity entity : luiPersonRelations) {
 120  0
             dtos.add(entity.toDto());
 121  
         }
 122  0
         return dtos;
 123  
     }
 124  
 
 125  
     @Override
 126  
     @Transactional
 127  
     public List<BulkStatusInfo> createLprsForPerson(String personId,
 128  
             String lprTypeKey,
 129  
             List<LprInfo> lprInfos,
 130  
             ContextInfo contextInfo)
 131  
             throws DataValidationErrorException,
 132  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 133  
             PermissionDeniedException, ReadOnlyException {
 134  0
               List<BulkStatusInfo> bulkStatusInfoList = new ArrayList<BulkStatusInfo>();
 135  
           
 136  
           /*
 137  
            * This is an intentionally simple implementation.
 138  
            * 
 139  
            * Later we can manage the transactions ourselves and use a paging approach.
 140  
            */
 141  
           
 142  0
           for (LprInfo lprInfo : lprInfos) {
 143  
                   
 144  0
                   BulkStatusInfo bsi = new BulkStatusInfo();
 145  
                   
 146  
                   try {
 147  0
                   LprInfo created = this.createLpr(personId, lprInfo.getLuiId(), lprTypeKey, lprInfo, contextInfo);
 148  0
                   bsi.setSuccess(Boolean.TRUE);
 149  0
                   bsi.setId(created.getId());
 150  0
               } catch (DataValidationErrorException de) {
 151  0
                   bsi.setSuccess(Boolean.FALSE);
 152  0
                   bsi.setMessage(ValidationUtils.asString(de.getValidationResults()));
 153  0
               }
 154  0
           }
 155  
           
 156  
           
 157  0
                   return bulkStatusInfoList;
 158  
     }
 159  
 
 160  
     @Override
 161  
     @Transactional(readOnly=true)
 162  
     public LprInfo getLpr(String lprId, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 163  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 164  
             
 165  0
         LprEntity lpr = lprDao.find(lprId);
 166  
         
 167  0
         if (lpr == null)
 168  0
                 throw new DoesNotExistException("No LprEntity for id = " + lprId);
 169  
         
 170  
         // else
 171  0
         return lpr.toDto();
 172  
     }
 173  
 
 174  
     @Override
 175  
     @Transactional(readOnly=true)
 176  
     public List<LprInfo> getLprsByIds(List<String> luiPersonRelationIds, ContextInfo context) throws DoesNotExistException,
 177  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 178  0
         List<LprInfo> lprInfos = new ArrayList<LprInfo>();
 179  0
         List<LprEntity> lprEntities = lprDao.findByIds(luiPersonRelationIds);
 180  0
         for (LprEntity lprEntity : lprEntities) {
 181  0
             LprInfo lprInfo = lprEntity.toDto();
 182  0
             lprInfos.add(lprInfo);
 183  0
         }
 184  0
         return lprInfos;
 185  
     }
 186  
 
 187  
     @Override
 188  
     public List<String> getLuiIdsByPersonAndTypeAndState(String personId, String luiPersonRelationType, String relationState, ContextInfo context) throws
 189  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 190  
             PermissionDeniedException {
 191  
         // TODO Kamal - THIS METHOD NEEDS JAVADOCS
 192  0
         return null;
 193  
     }
 194  
 
 195  
     @Override
 196  
     @Transactional(readOnly=true)
 197  
     public List<String> getPersonIdsByLuiAndTypeAndState(String luiId, String luiPersonRelationType, String relationState, ContextInfo context) throws
 198  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 199  
             PermissionDeniedException {
 200  0
         List<String> returnVals = new ArrayList<String>();
 201  
 
 202  0
         returnVals.addAll(lprDao.getPersonIdsByLui(luiId, luiPersonRelationType, relationState));
 203  0
         return returnVals;
 204  
 
 205  
     }
 206  
 
 207  
     @Override
 208  
     @Transactional(readOnly=true)
 209  
     public List<LprInfo> getLprsByPersonAndLui(String personId, String luiId, ContextInfo context) throws DoesNotExistException,
 210  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 211  
 
 212  0
         List<LprEntity> entityList = lprDao.getLprByLuiAndPerson(personId, luiId);
 213  
 
 214  0
         List<LprInfo> infoList = new ArrayList<LprInfo>();
 215  
 
 216  0
         if (entityList != null && !entityList.isEmpty()) {
 217  0
             for (LprEntity entity : entityList) {
 218  0
                 infoList.add(entity.toDto());
 219  
             }
 220  
 
 221  
         }
 222  0
         return infoList;
 223  
 
 224  
     }
 225  
 
 226  
     @Override
 227  
     @Transactional(readOnly=true)
 228  
     public List<LprInfo> getLprsByPerson(String personId, ContextInfo context) throws DoesNotExistException,
 229  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 230  0
         List<LprEntity> entityList = lprDao.getLprsByPerson(personId);
 231  
 
 232  0
         List<LprInfo> infoList = new ArrayList<LprInfo>();
 233  0
         if (entityList != null && !entityList.isEmpty()) {
 234  0
             for (LprEntity entity : entityList) {
 235  0
                 infoList.add(entity.toDto());
 236  
             }
 237  
 
 238  
         }
 239  0
         return infoList;
 240  
     }
 241  
 
 242  
     @Override
 243  
     public List<String> searchForLprIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 244  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 245  0
         throw new UnsupportedOperationException("Operation not supported");
 246  
     }
 247  
 
 248  
     @Override
 249  
     @Transactional
 250  
     public LprInfo createLpr(String personId, String luiId, String lprType, LprInfo luiPersonRelationInfo, ContextInfo context)
 251  
             throws DataValidationErrorException,
 252  
             DoesNotExistException, InvalidParameterException,
 253  
             MissingParameterException, OperationFailedException,
 254  
             PermissionDeniedException, ReadOnlyException {
 255  
 
 256  
         // make sure params are consistent with lprInfo:
 257  0
         luiPersonRelationInfo.setPersonId(personId);
 258  0
         luiPersonRelationInfo.setLuiId(luiId);
 259  0
         luiPersonRelationInfo.setTypeKey(lprType);
 260  
         
 261  0
         LprEntity lpr = new LprEntity(luiPersonRelationInfo);
 262  
         
 263  0
         lpr.setEntityCreated(context);
 264  
         
 265  0
         lprDao.persist(lpr);
 266  
         
 267  0
         return lpr.toDto();
 268  
     }
 269  
 
 270  
     @Override
 271  
     @Transactional
 272  
     public LprInfo updateLpr(String lprId, LprInfo lprInfo, ContextInfo contextInfo) throws
 273  
             DoesNotExistException, InvalidParameterException, MissingParameterException, ReadOnlyException,
 274  
             OperationFailedException, PermissionDeniedException {
 275  0
         LprEntity lprEntity = lprDao.find(lprId);
 276  
 
 277  0
         if (lprEntity != null) {
 278  
                 
 279  0
             lprDao.mergeFromDto(lprEntity, lprInfo);
 280  
                 
 281  0
             if (lprInfo.getStateKey() != null) {
 282  0
                     lprEntity.setPersonRelationStateId(lprInfo.getStateKey());
 283  
             }
 284  
 
 285  0
             if (lprInfo.getTypeKey() != null) {
 286  0
                     lprEntity.setPersonRelationTypeId(lprInfo.getTypeKey());
 287  
             }
 288  
 
 289  0
             lprEntity.setEntityUpdated(contextInfo);
 290  
             
 291  0
             return lprDao.find(lprId).toDto();
 292  
         } else {
 293  0
             throw new DoesNotExistException(lprId);
 294  
         }
 295  
     }
 296  
 
 297  
     @Override
 298  
     @Transactional
 299  
     public StatusInfo deleteLpr(String lprId, ContextInfo context) throws DoesNotExistException,
 300  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 301  0
         LprEntity lprEntity = lprDao.find(lprId);
 302  
         
 303  0
         if (lprEntity == null) {
 304  0
                 throw new DoesNotExistException("No LprEntity for id = " + lprId);
 305  
         }
 306  
         
 307  0
         lprDao.remove(lprEntity);
 308  
         
 309  0
         StatusInfo status = new StatusInfo();
 310  0
         status.setSuccess(Boolean.TRUE);
 311  0
         return status;
 312  
     }
 313  
 
 314  
     @Override
 315  
     public List<LprInfo> searchForLprs(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 316  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 317  0
         throw new UnsupportedOperationException();
 318  
     }
 319  
 
 320  
    
 321  
     @Override
 322  
     @Transactional(readOnly=true)
 323  
     public LprTransactionInfo getLprTransaction(String lprTransactionId, ContextInfo context) throws DoesNotExistException,
 324  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 325  
 
 326  0
         LprTransactionEntity transactionEntity = lprTransDao.find(lprTransactionId);
 327  
 
 328  0
         if (transactionEntity == null)
 329  0
                 throw new DoesNotExistException("No LprTransactionEntity for id = " + lprTransactionId);
 330  
         
 331  0
         return transactionEntity.toDto();
 332  
     }
 333  
 
 334  
     
 335  
     @Override
 336  
     @Transactional
 337  
     public StatusInfo deleteLprTransaction(String lprTransactionId, ContextInfo context) throws DoesNotExistException,
 338  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 339  
 
 340  0
         StatusInfo status = new StatusInfo();
 341  
 
 342  0
         LprTransactionEntity lprTrans = lprTransDao.find(lprTransactionId);
 343  0
         if (null != lprTrans) {
 344  
 
 345  0
             lprTransDao.remove(lprTrans);
 346  
 
 347  0
             status.setSuccess(Boolean.TRUE);
 348  
 
 349  
         } else {
 350  0
             status.setSuccess(Boolean.FALSE);
 351  
         }
 352  
 
 353  0
         return status;
 354  
     }
 355  
 
 356  
     
 357  
     @Override
 358  
     public List<LprInfo> getLprsByPersonForAtp(String personId, String atpId, ContextInfo context) throws DoesNotExistException,
 359  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 360  
         // TODO sambitpatnaik - THIS METHOD NEEDS JAVADOCS
 361  0
         return null;
 362  
     }
 363  
 
 364  
     @Override
 365  
     @Transactional
 366  
     public LprTransactionInfo createLprTransaction(String lprTransactionType, LprTransactionInfo lprTransactionInfo, ContextInfo context)
 367  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
 368  
             OperationFailedException, PermissionDeniedException {
 369  
 
 370  0
         LprTransactionEntity lprTransactionEntity = new LprTransactionEntity(lprTransactionInfo);
 371  
         
 372  
         
 373  0
         if (lprTransactionEntity.getId() == null) {
 374  0
             lprTransactionEntity.setId(UUIDHelper.genStringUUID());
 375  
         }
 376  0
         if (null != lprTransactionInfo.getStateKey()) {
 377  0
             lprTransactionEntity.setLprTransState(lprTransactionInfo.getStateKey());
 378  
         }
 379  
 
 380  0
         if (null != lprTransactionInfo.getTypeKey()) {
 381  0
             lprTransactionEntity.setLprTransType(lprTransactionInfo.getTypeKey());
 382  
         }
 383  0
         if (null != lprTransactionInfo.getDescr()) {
 384  0
                 RichTextInfo descr = lprTransactionInfo.getDescr();
 385  
             
 386  0
                 lprTransactionEntity.setDescrFormatted(descr.getFormatted());
 387  0
                 lprTransactionEntity.setDescrPlain(descr.getPlain());
 388  
         }
 389  
 
 390  0
         List<LprTransactionItemEntity> lprTransItemEntities = new ArrayList<LprTransactionItemEntity>();
 391  
 
 392  0
         for (LprTransactionItemInfo lprTransItemInfo : lprTransactionInfo.getLprTransactionItems()) {
 393  
 
 394  0
             LprTransactionItemEntity lprTransItemEntity = createLprTransactionItem(lprTransItemInfo, lprTransactionEntity, context);
 395  
 
 396  0
             lprTransItemEntities.add(lprTransItemEntity);
 397  0
         }
 398  
 
 399  0
         lprTransactionEntity.setLprTransactionItems(lprTransItemEntities);
 400  
         
 401  0
         lprTransactionEntity.setEntityCreated(context);
 402  
 
 403  0
         lprTransDao.persist(lprTransactionEntity);
 404  
 
 405  0
         LprTransactionEntity retrived = lprTransDao.find(lprTransactionEntity.getId());
 406  
 
 407  0
         LprTransactionInfo info = null;
 408  0
         if (retrived != null) {
 409  0
             info = retrived.toDto();
 410  
         }
 411  
 
 412  0
         return info;
 413  
 
 414  
     }
 415  
 
 416  
     @Override
 417  
     @Transactional
 418  
     public LprTransactionInfo createLprTransactionFromExisting(String lprTransactionId, ContextInfo context) throws
 419  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 420  
             PermissionDeniedException {
 421  
 
 422  0
         LprTransactionEntity existingLprTransactionEntity = lprTransDao.find(lprTransactionId);
 423  0
         LprTransactionEntity newLprTransactionEntity = new LprTransactionEntity();
 424  0
         if (existingLprTransactionEntity != null) {
 425  0
             newLprTransactionEntity.setId(UUIDHelper.genStringUUID());
 426  0
             newLprTransactionEntity.setAttributes(existingLprTransactionEntity.getAttributes());
 427  0
             newLprTransactionEntity.setDescrFormatted(existingLprTransactionEntity.getDescrFormatted());
 428  0
             newLprTransactionEntity.setDescrPlain(existingLprTransactionEntity.getDescrPlain());
 429  0
             List<LprTransactionItemEntity> newItems = new ArrayList(existingLprTransactionEntity.getLprTransactionItems().size());
 430  0
             for (LprTransactionItemEntity existingItem : existingLprTransactionEntity.getLprTransactionItems()) {
 431  0
                 LprTransactionItemEntity newItem = new LprTransactionItemEntity();
 432  0
                 newItem.setId(UUIDHelper.genStringUUID());
 433  0
                 newItem.setExistingLuiId(lprTransactionId);
 434  0
                 newItem.setLprTransactionItemState(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
 435  0
                 newItem.setLprTransactionItemType(existingItem.getLprTransactionItemType());
 436  0
                 newItem.setNewLuiId(existingItem.getNewLuiId());
 437  0
                 newItem.setPersonId(existingItem.getPersonId());
 438  0
                 newItem.setDescrFormatted(existingItem.getDescrFormatted());
 439  0
                 newItem.setDescrPlain(existingItem.getDescrPlain());
 440  
 
 441  0
             }
 442  0
             newLprTransactionEntity.setLprTransactionItems(newItems);
 443  0
             newLprTransactionEntity.setLprTransState(LprServiceConstants.LPRTRANS_NEW_STATE_KEY);
 444  0
             newLprTransactionEntity.setLprTransType(existingLprTransactionEntity.getLprTransType());
 445  0
             newLprTransactionEntity.setRequestingPersonId(existingLprTransactionEntity.getRequestingPersonId());
 446  0
             lprTransDao.persist(newLprTransactionEntity);
 447  
 
 448  0
         } else {
 449  0
             throw new DoesNotExistException("Could not find any LPR Transaction for id : " + lprTransactionId);
 450  
         }
 451  0
         LprTransactionEntity retrived = lprTransDao.find(newLprTransactionEntity.getId());
 452  0
         LprTransactionInfo info = null;
 453  0
         if (retrived != null) {
 454  0
             info = retrived.toDto();
 455  
         } else {
 456  0
             throw new OperationFailedException("");
 457  
         }
 458  0
         return info;
 459  
     }
 460  
 
 461  
     @Override
 462  
     @Transactional
 463  
     public LprTransactionInfo processLprTransaction(String lprTransactionId, ContextInfo context) throws AlreadyExistsException,
 464  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 465  
             PermissionDeniedException {
 466  0
         LprTransactionInfo lprTransaction = getLprTransaction(lprTransactionId, context);
 467  
 
 468  0
         for (LprTransactionItemInfo lprTransactionItemInfo : lprTransaction.getLprTransactionItems()) {
 469  0
             LprTransactionItemResultInfo lprTransResultInfo = new LprTransactionItemResultInfo();
 470  0
             if (lprTransactionItemInfo.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY) ||
 471  
                     lprTransactionItemInfo.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TO_WAITLIST_TYPE_KEY)) {
 472  
                 /*
 473  
                 // TODO Mezba - the method createLprFromLprTransactionItem is no longer there, decide what to do
 474  
                 String lprCreated = createLprFromLprTransactionItem(lprTransactionItemInfo, context);
 475  
                 
 476  
                 lprTransResultInfo.setResultingLprId(lprCreated);
 477  
                  */
 478  0
             } else if (lprTransactionItemInfo.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)) {
 479  
                 /**
 480  
                  * TODO this needs to be implemented for drop to work, read below Be careful with the implementation here,
 481  
                  * because we DO NOT want to delete all lprs that are matched by lui, person, and state, but instead only the
 482  
                  * ones that are related to the registration group we are dropping. It is VERY possible that a student could
 483  
                  * have the same course offering on their schedule twice with different reg groups, therefore deleting every
 484  
                  * LPR that matches that course offering id would be WRONG. In addition, it is possible that 2 reg groups
 485  
                  * that point to the same activity offering could be on the same schedule (this is more unlikely however and
 486  
                  * may be prevented by the system), and deleting both of those LPRs would be incorrect. So what we actually
 487  
                  * want to do is delete only lprs that have a direct relation to the reg group being dropped. However, there
 488  
                  * is no easy way currently to link these things together, one possible route is to get the original
 489  
                  * transactions and use their group id somehow, but this route may be flawed if the there is more than one
 490  
                  * succeeded transaction for the same reg group (VERY possible). There is no way currently (that I know of)
 491  
                  * to link the lprs for courseOffering, reg group, activities, and roster in a way that would be simple to
 492  
                  * determine by retrieving them from the db. This may be a possible hole in the service/db design.
 493  
                  */
 494  
                 List<LprInfo> toBeDroppedLPRs;
 495  
                 try {
 496  0
                     toBeDroppedLPRs = getLprsByLuiPersonAndState(lprTransactionItemInfo.getPersonId(),
 497  
                             lprTransactionItemInfo.getExistingLuiId(), LprServiceConstants.REGISTERED_STATE_KEY, context);
 498  0
                 } catch (DisabledIdentifierException ex) {
 499  0
                     throw new OperationFailedException("unexpected", ex);
 500  0
                 }
 501  
 
 502  0
                 if (toBeDroppedLPRs.size() > 1) {
 503  0
                     throw new OperationFailedException("Multiple LuiPersonRelations between person:" +
 504  
                             lprTransactionItemInfo.getPersonId() + " and lui:" + lprTransactionItemInfo.getExistingLuiId() +
 505  
                             "; unimplemented functionality required to deal with this scenario is currentluy unimplemented");
 506  
                 }
 507  0
                 for (LprInfo lprInfo : toBeDroppedLPRs) {
 508  
                     // TODO - change state to LprServiceConstants.DROPPED_STATE_KEY, rather than deleting
 509  
                     /*
 510  
                      * do this instead of delete lprInfo.setStateKey(LprServiceConstants.DROPPED_STATE_KEY);
 511  
                      * try { updateLpr(lprInfo.getId(), lprInfo, context); } catch (ReadOnlyException e) { throw new
 512  
                      * OperationFailedException("updateLpr() failure in processLprTransaction()", e); }
 513  
                      */
 514  0
                     deleteLpr(lprInfo.getId(), context);
 515  0
                     lprTransResultInfo.setResultingLprId(lprInfo.getId());
 516  
                 }
 517  
 
 518  0
             } else if (lprTransactionItemInfo.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_SWAP_TYPE_KEY)) {
 519  
 
 520  
                 List<LprInfo> toBeDroppedLPRs;
 521  
                 try {
 522  0
                     toBeDroppedLPRs = getLprsByLuiPersonAndState(lprTransactionItemInfo.getPersonId(),
 523  
                             lprTransactionItemInfo.getExistingLuiId(), LprServiceConstants.REGISTERED_STATE_KEY, context);
 524  0
                 } catch (DisabledIdentifierException ex) {
 525  0
                     throw new OperationFailedException("unexpected", ex);
 526  0
                 }
 527  0
                 if (toBeDroppedLPRs.size() > 1) {
 528  0
                     throw new OperationFailedException("Multiple LuiPersonRelations between person:" +
 529  
                             lprTransactionItemInfo.getPersonId() + " and lui:" + lprTransactionItemInfo.getExistingLuiId() +
 530  
                             "; unimplemented functionality required to deal with this scenario is currentluy unimplemented");
 531  
                 }
 532  0
                 for (LprInfo lprInfo : toBeDroppedLPRs) {
 533  
                     // TODO - change state to LprServiceConstants.DROPPED_STATE_KEY, rather than deleting
 534  
                     /*
 535  
                      * do this instead of delete lprInfo.setStateKey(LprServiceConstants.DROPPED_STATE_KEY);
 536  
                      * try { updateLpr(lprInfo.getId(), lprInfo, context); } catch (ReadOnlyException e) { throw new
 537  
                      * OperationFailedException("updateLpr() failure in processLprTransaction()", e); }
 538  
                      */
 539  0
                     deleteLpr(lprInfo.getId(), context);
 540  
                     /*
 541  
                     // TODO Mezba - the method createLprFromLprTransactionItem is no longer there, decide what to do
 542  
                     
 543  
                     String lprCreated = createLprFromLprTransactionItem(lprTransactionItemInfo, context);
 544  
                     
 545  
                     lprTransResultInfo.setResultingLprId(lprCreated);
 546  
                      */
 547  
                 }
 548  0
             } else {
 549  
 
 550  0
                 throw new OperationFailedException("The LPR Transaction Item did not have one of the supported type ");
 551  
             }
 552  0
             lprTransResultInfo.setStatus(true);
 553  0
             lprTransactionItemInfo.setStateKey(LprServiceConstants.LPRTRANS_ITEM_SUCCEEDED_STATE_KEY);
 554  0
             lprTransactionItemInfo.setLprTransactionItemResult(lprTransResultInfo);
 555  
 
 556  0
         }
 557  
         try {
 558  0
             lprTransaction.setStateKey(LprServiceConstants.LPRTRANS_SUCCEEDED_STATE_KEY);
 559  0
             updateLprTransaction(lprTransactionId, lprTransaction, context);
 560  0
         } catch (DataValidationErrorException ex) {
 561  0
             throw new OperationFailedException(ex.getMessage());
 562  0
         }
 563  0
         return lprTransaction;
 564  
     }
 565  
 
 566  
     @Override
 567  
     public List<LprTransactionInfo> getLprTransactionsByIds(List<String> lprIds, ContextInfo context) throws DoesNotExistException,
 568  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 569  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 570  0
         return null;
 571  
     }
 572  
 
 573  
     @Override
 574  
     @Transactional(readOnly=true)
 575  
     public List<LprTransactionItemInfo> getLprTransactionItemsByResultingLpr(String lprId, ContextInfo context) throws
 576  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 577  
 
 578  0
         List<LprTransactionItemEntity> lprTransItems = lprTransItemDao.getLprTransactionItemsByLpr(lprId);
 579  0
         List<LprTransactionEntity> lprTrans = new ArrayList<LprTransactionEntity>();
 580  0
         for (LprTransactionItemEntity lprTransItem : lprTransItems) {
 581  
 
 582  0
             lprTrans.add(lprTransDao.getByLprTransactionItemId(lprTransItem.getId()));
 583  
         }
 584  0
         List<LprTransactionInfo> lprTransInfos = new ArrayList<LprTransactionInfo>();
 585  
 
 586  0
         for (LprTransactionEntity lprTransEntity : lprTrans) {
 587  0
             lprTransInfos.add(lprTransEntity.toDto());
 588  
         }
 589  
         // return lprTransInfos;
 590  0
         return null;
 591  
         // TODO Mezba - implement method
 592  
     }
 593  
 
 594  
     @Transactional
 595  
     @Override
 596  
     public LprTransactionInfo updateLprTransaction(String lprTransactionId, LprTransactionInfo lprTransactionInfo, ContextInfo context) throws
 597  
             DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
 598  
             OperationFailedException, PermissionDeniedException {
 599  0
         LprTransactionEntity lprTrans = lprTransDao.find(lprTransactionId);
 600  
 
 601  0
         if (null != lprTrans) {
 602  
                 
 603  0
                  lprTransDao.mergeFromDto(lprTrans, lprTransactionInfo);
 604  
                  
 605  0
             if (lprTransactionInfo.getStateKey() != null) {
 606  0
                     lprTrans.setLprTransState(lprTransactionInfo.getStateKey());
 607  
             }
 608  0
             if (lprTransactionInfo.getTypeKey() != null) {
 609  0
                     lprTrans.setLprTransType(lprTransactionInfo.getTypeKey());
 610  
             }
 611  
 
 612  
             
 613  0
             lprTrans.setEntityUpdated(context);
 614  
             
 615  0
             return lprTransDao.find(lprTransactionId).toDto();
 616  
 
 617  
         } else {
 618  0
             throw new DoesNotExistException(lprTransactionId);
 619  
         }
 620  
     }
 621  
 
 622  
     @Transactional
 623  
     private List<LprTransactionItemEntity> processLprTransactionItemsModification(LprTransactionInfo modifiedTransactionInfo, LprTransactionEntity originalLprTransEntity, ContextInfo context) {
 624  0
         List<LprTransactionItemEntity> modifiedLprTransItemEntities = new ArrayList<LprTransactionItemEntity>();
 625  0
         LprTransactionInfo originalLprTransInfo = originalLprTransEntity.toDto();
 626  0
         List<String> deletedItems = new ArrayList<String>();
 627  
         // Assume all original items are deleted until matched
 628  0
         for (LprTransactionItemInfo originalLprTransItemInfo : originalLprTransInfo.getLprTransactionItems()) {
 629  0
             deletedItems.add(originalLprTransItemInfo.getId());
 630  
         }
 631  
 
 632  0
         for (LprTransactionItemInfo modifiedTransactionItemInfo : modifiedTransactionInfo.getLprTransactionItems()) {
 633  0
             boolean existingItem = false;
 634  0
             if (modifiedTransactionItemInfo.getId() != null) {
 635  0
                 for (LprTransactionItemInfo originalLprTransItemInfo : originalLprTransInfo.getLprTransactionItems()) {
 636  0
                     if (originalLprTransItemInfo.getId().equals(modifiedTransactionItemInfo.getId())) {
 637  0
                         existingItem = true;
 638  0
                         deletedItems.remove(originalLprTransItemInfo.getId());
 639  
                     }
 640  
                 }
 641  0
                 if (existingItem) {
 642  
 
 643  0
                     modifiedLprTransItemEntities.add(updateLprTransactionItem(modifiedTransactionItemInfo, context));
 644  
                 }
 645  
             }
 646  
 
 647  0
             if (!existingItem || modifiedTransactionItemInfo.getId() == null) {
 648  0
                 modifiedLprTransItemEntities.add(createLprTransactionItem(modifiedTransactionItemInfo, originalLprTransEntity,context));
 649  
             }
 650  0
         }
 651  
 
 652  0
         for (String id : deletedItems) {
 653  0
             lprTransItemDao.remove(lprTransItemDao.find(id));
 654  
         }
 655  
 
 656  0
         return modifiedLprTransItemEntities;
 657  
 
 658  
     }
 659  
 
 660  
     private LprTransactionItemEntity updateLprTransactionItem(LprTransactionItemInfo modifiedTransactionItemInfo, ContextInfo context) {
 661  0
         LprTransactionItemEntity modifiedLprItemEntity = new LprTransactionItemEntity(modifiedTransactionItemInfo);
 662  0
         if (null != modifiedTransactionItemInfo.getStateKey()) {
 663  0
             modifiedLprItemEntity.setLprTransactionItemState(modifiedTransactionItemInfo.getStateKey());
 664  
         }
 665  0
         if (null != modifiedTransactionItemInfo.getTypeKey()) {
 666  0
             modifiedLprItemEntity.setLprTransactionItemType(modifiedTransactionItemInfo.getTypeKey());
 667  
         }
 668  0
         if (null != modifiedTransactionItemInfo.getDescr()) {
 669  0
                 RichTextInfo descr = modifiedTransactionItemInfo.getDescr();
 670  0
             modifiedLprItemEntity.setDescrFormatted(descr.getFormatted());
 671  0
             modifiedLprItemEntity.setDescrPlain(descr.getPlain());
 672  
         }
 673  0
         lprTransItemDao.merge(modifiedLprItemEntity);
 674  0
         return modifiedLprItemEntity;
 675  
     }
 676  
 
 677  
     private LprTransactionItemEntity createLprTransactionItem(LprTransactionItemInfo lprTransactionItemInfo, LprTransactionEntity owner, ContextInfo context) {
 678  
             
 679  0
         LprTransactionItemEntity lprTransItemEntity = new LprTransactionItemEntity(lprTransactionItemInfo);
 680  
         
 681  0
         if (lprTransItemEntity.getId() == null) {
 682  0
             lprTransItemEntity.setId(UUIDHelper.genStringUUID());
 683  
         }
 684  0
         if (null != lprTransactionItemInfo.getStateKey()) {
 685  0
             lprTransItemEntity.setLprTransactionItemState(lprTransactionItemInfo.getStateKey());
 686  
         }
 687  
 
 688  0
         if (null != lprTransactionItemInfo.getTypeKey()) {
 689  0
             lprTransItemEntity.setLprTransactionItemType(lprTransactionItemInfo.getTypeKey());
 690  
         }
 691  0
         if (null != lprTransactionItemInfo.getDescr()) {
 692  0
                 RichTextInfo descr = lprTransactionItemInfo.getDescr();
 693  0
                 lprTransItemEntity.setDescrFormatted(descr.getFormatted());
 694  0
                 lprTransItemEntity.setDescrPlain(descr.getPlain());
 695  
         }
 696  
         
 697  0
         lprTransItemEntity.setEntityCreated(context);
 698  
         
 699  0
         lprTransItemEntity.setOwner(owner);
 700  
 
 701  
 
 702  0
         lprTransItemDao.persist(lprTransItemEntity);
 703  
 
 704  0
         return lprTransItemDao.find(lprTransItemEntity.getId());
 705  
     }
 706  
 
 707  
     @Override
 708  
     public List<LprTransactionInfo> searchForLprTransactions(QueryByCriteria criteria, ContextInfo context) throws
 709  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 710  0
         throw new UnsupportedOperationException("Operation not implemented");
 711  
     }
 712  
 
 713  
     @Override
 714  
     public List<String> searchForLprTransactionIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException,
 715  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 716  0
         throw new UnsupportedOperationException("Operation not implemented");
 717  
     }
 718  
 
 719  
     @Override
 720  
     @Transactional(readOnly=true)
 721  
     public List<LprInfo> getLprsByPersonAndTypeForAtp(String personId, String atpId, String typeKey, ContextInfo context) throws
 722  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 723  
             PermissionDeniedException {
 724  
 
 725  0
         List<LprEntity> entityList = lprDao.getLprsByPersonAndType(personId, typeKey);
 726  0
         List<LprInfo> infoList = new ArrayList<LprInfo>();
 727  0
         for (LprEntity entity : entityList) {
 728  
             // TODO: inject this impl with a lui service impl to get the atp to check
 729  
 //            LuiEntity lui = luiDao.find(entity.getLuiId());
 730  
 //            if (StringUtils.equals(lui.getAtpId(), atpId)) {
 731  0
             infoList.add(entity.toDto());
 732  
 //            }
 733  
         }
 734  
 
 735  0
         return infoList;
 736  
     }
 737  
 
 738  
     @Override
 739  
     @Transactional(readOnly=true)
 740  
     public List<LprInfo> getLprsByPersonForAtpAndLuiType(String personId, String atpId, String luiTypeKey, ContextInfo context) throws
 741  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 742  
             PermissionDeniedException {
 743  0
         List<LprEntity> entityList = lprDao.getLprsByPerson(personId);
 744  
 
 745  0
         List<LprInfo> infoList = new ArrayList<LprInfo>();
 746  0
         for (LprEntity entity : entityList) {
 747  
 //            LuiEntity lui = luiDao.find(entity.getLuiId());
 748  
 //            if ((lui.getAtpId().equals(atpId)) && (lui.getLuiType().equals(luiTypeKey))) {
 749  0
             infoList.add(entity.toDto());
 750  
 //            }
 751  
         }
 752  
 
 753  0
         return infoList;
 754  
     }
 755  
 
 756  
     @Override
 757  
     public List<LprInfo> getLprsByLuiAndType(String luiId, String typeKey, ContextInfo context) throws DoesNotExistException,
 758  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 759  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 760  0
         return null;
 761  
     }
 762  
 
 763  
     @Override
 764  
     @Transactional(readOnly=true)
 765  
     public List<LprInfo> getLprsByPersonAndLuiType(String personId, String luiTypeKey, ContextInfo context) throws
 766  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 767  
             PermissionDeniedException {
 768  0
         List<LprEntity> entityList = lprDao.getLprsByPerson(personId);
 769  
 
 770  0
         List<LprInfo> infoList = new ArrayList<LprInfo>();
 771  0
         for (LprEntity entity : entityList) {
 772  
 //            LuiEntity lui = luiDao.find(entity.getLuiId());
 773  
 //            if ((lui.getLuiType().equals(luiTypeKey))) {
 774  0
             infoList.add(entity.toDto());
 775  
 //            }
 776  
         }
 777  
 
 778  0
         return infoList;
 779  
     }
 780  
 
 781  
     @Override
 782  
     public List<ValidationResultInfo> verifyLprTransaction(String lprTransactionId,
 783  
             ContextInfo contextInfo)
 784  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 785  
             OperationFailedException, PermissionDeniedException {
 786  0
         return null;
 787  
         // TODO Mezba - implement method
 788  
     }
 789  
 
 790  
     @Override
 791  
     public List<ValidationResultInfo> validateLpr(String validationType,
 792  
             String luiId,
 793  
             String personId,
 794  
             String lprTypeKey,
 795  
             LprInfo lprInfo,
 796  
             ContextInfo contextInfo)
 797  
             throws DoesNotExistException, InvalidParameterException,
 798  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 799  0
         return null;
 800  
         // TODO Mezba - implement method
 801  
     }
 802  
 
 803  
     @Override
 804  
     public List<LprTransactionItemInfo> getLprTransactionItemsByLui(String luiId, ContextInfo contextInfo)
 805  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 806  0
         return null;
 807  
         // TODO Mezba - implement method
 808  
     }
 809  
 
 810  
     @Override
 811  
     public List<LprTransactionInfo> getUnsubmittedLprTransactionsByRequestingPersonAndAtp(
 812  
             String requestingPersonId,
 813  
             String atpId,
 814  
             ContextInfo contextInfo) throws InvalidParameterException,
 815  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 816  0
         return null;
 817  
         // TODO Mezba - implement method
 818  
     }
 819  
 
 820  
     @Override
 821  
     public List<LprTransactionItemInfo> getLprTransactionItemsByPersonAndLui(
 822  
             String personId, String luiId, ContextInfo contextInfo)
 823  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 824  
             OperationFailedException, PermissionDeniedException {
 825  0
         return null;
 826  
         // TODO Mezba - implement method
 827  
 
 828  
     }
 829  
 
 830  
     @Override
 831  
     @Transactional
 832  
     public List<BulkStatusInfo> createLprsForLui(String luiId,
 833  
             String lprTypeKey,
 834  
             List<LprInfo> lprInfos,
 835  
             ContextInfo contextInfo)
 836  
             throws DataValidationErrorException,
 837  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 838  
             PermissionDeniedException, ReadOnlyException {
 839  
             
 840  0
         List<BulkStatusInfo> bulkStatusInfoList = new ArrayList<BulkStatusInfo>();
 841  
         
 842  
         /*
 843  
          * This is an intentionally simple implementation.
 844  
          * 
 845  
          * Later we can manage the transactions ourselves and use a paging approach.
 846  
          */
 847  
         
 848  0
         for (LprInfo lprInfo : lprInfos) {
 849  
                 
 850  0
                 BulkStatusInfo bsi = new BulkStatusInfo();
 851  
                 
 852  
                  try {
 853  0
                  LprInfo created = this.createLpr(lprInfo.getPersonId(), luiId, lprTypeKey, lprInfo, contextInfo);
 854  0
                  bsi.setSuccess(Boolean.TRUE);
 855  0
                  bsi.setId(created.getId());
 856  0
              } catch (DataValidationErrorException de) {
 857  0
                  bsi.setSuccess(Boolean.FALSE);
 858  0
                  bsi.setMessage(ValidationUtils.asString(de.getValidationResults()));
 859  0
              }
 860  
                 
 861  0
                  bulkStatusInfoList.add(bsi);
 862  0
         }
 863  
         
 864  
         
 865  0
                 return bulkStatusInfoList;
 866  
     }
 867  
 }