Coverage Report - org.kuali.student.r2.core.class1.atp.service.impl.AtpServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
AtpServiceImpl
0%
0/264
0%
0/114
2.636
 
 1  
 package org.kuali.student.r2.core.class1.atp.service.impl;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.Date;
 5  
 import java.util.List;
 6  
 
 7  
 
 8  
 import org.kuali.rice.core.api.criteria.GenericQueryResults;
 9  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 10  
 import org.kuali.student.r2.common.criteria.CriteriaLookupService;
 11  
 import org.kuali.student.r2.common.dto.ContextInfo;
 12  
 import org.kuali.student.r2.common.dto.StatusInfo;
 13  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 14  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 15  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 16  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 17  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 18  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 19  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 20  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 21  
 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
 22  
 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
 23  
 import org.kuali.student.r2.core.atp.dto.AtpAtpRelationInfo;
 24  
 import org.kuali.student.r2.core.atp.dto.AtpInfo;
 25  
 import org.kuali.student.r2.core.atp.dto.MilestoneInfo;
 26  
 import org.kuali.student.r2.core.atp.service.AtpService;
 27  
 import org.kuali.student.r2.core.class1.atp.dao.AtpAtpRelationDao;
 28  
 import org.kuali.student.r2.core.class1.atp.dao.AtpDao;
 29  
 import org.kuali.student.r2.core.class1.atp.dao.AtpMilestoneRelationDao;
 30  
 import org.kuali.student.r2.core.class1.atp.dao.MilestoneDao;
 31  
 import org.kuali.student.r2.core.class1.atp.model.AtpAtpRelationEntity;
 32  
 import org.kuali.student.r2.core.class1.atp.model.AtpEntity;
 33  
 import org.kuali.student.r2.core.class1.atp.model.AtpMilestoneRelationEntity;
 34  
 import org.kuali.student.r2.core.class1.atp.model.MilestoneEntity;
 35  
 import org.springframework.transaction.annotation.Transactional;
 36  
 
 37  
 @Transactional(readOnly = true, noRollbackFor = {DoesNotExistException.class}, rollbackFor = {Throwable.class})
 38  0
 public class AtpServiceImpl implements AtpService {
 39  
 
 40  
     private AtpDao atpDao;
 41  
     private AtpAtpRelationDao atpRelDao;
 42  
     private MilestoneDao milestoneDao;
 43  
     private AtpMilestoneRelationDao atpMilestoneRelationDao;
 44  
     private CriteriaLookupService criteriaLookupService;
 45  
 
 46  
     public AtpDao getAtpDao() {
 47  0
         return atpDao;
 48  
     }
 49  
 
 50  
     public void setAtpDao(AtpDao atpDao) {
 51  0
         this.atpDao = atpDao;
 52  0
     }
 53  
 
 54  
     public AtpAtpRelationDao getAtpRelDao() {
 55  0
         return atpRelDao;
 56  
     }
 57  
 
 58  
     public void setAtpRelDao(AtpAtpRelationDao atpRelDao) {
 59  0
         this.atpRelDao = atpRelDao;
 60  0
     }
 61  
 
 62  
     public MilestoneDao getMilestoneDao() {
 63  0
         return milestoneDao;
 64  
     }
 65  
 
 66  
     public void setMilestoneDao(MilestoneDao milestoneDao) {
 67  0
         this.milestoneDao = milestoneDao;
 68  0
     }
 69  
 
 70  
     public AtpMilestoneRelationDao getAtpMilestoneRelationDao() {
 71  0
         return atpMilestoneRelationDao;
 72  
     }
 73  
 
 74  
     public void setAtpMilestoneRelationDao(AtpMilestoneRelationDao atpMilestoneRelationDao) {
 75  0
         this.atpMilestoneRelationDao = atpMilestoneRelationDao;
 76  0
     }
 77  
 
 78  
     public void setCriteriaLookupService(CriteriaLookupService criteriaLookupService) {
 79  0
         this.criteriaLookupService = criteriaLookupService;
 80  0
     }
 81  
 
 82  
     public CriteriaLookupService getCriteriaLookupService() {
 83  0
         return criteriaLookupService;
 84  
     }
 85  
 
 86  
     @Override
 87  
     public AtpInfo getAtp(String atpId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 88  0
         AtpEntity atp = atpDao.find(atpId);
 89  0
         if (null == atp) {
 90  0
             throw new DoesNotExistException(atpId);
 91  
         }
 92  0
         return atp.toDto();
 93  
     }
 94  
 
 95  
     @Override
 96  
     public List<AtpInfo> getAtpsByDate(Date searchDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 97  0
         List<AtpEntity> atps = atpDao.getByDate(searchDate);
 98  
 
 99  0
         List<AtpInfo> result = new ArrayList<AtpInfo>(atps.size());
 100  0
         if (null != atps) {
 101  0
             for (AtpEntity entity : atps) {
 102  0
                 result.add(entity.toDto());
 103  
             }
 104  
         }
 105  0
         return result;
 106  
     }
 107  
 
 108  
     @Override
 109  
     public List<AtpInfo> getAtpsByDates(Date startDate, Date endDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 110  
             PermissionDeniedException {
 111  0
         List<AtpEntity> atps = atpDao.getByDates(startDate, endDate);
 112  
 
 113  0
         List<AtpInfo> result = new ArrayList<AtpInfo>(atps.size());
 114  0
         if (null != atps) {
 115  0
             for (AtpEntity entity : atps) {
 116  0
                 result.add(entity.toDto());
 117  
             }
 118  
         }
 119  0
         return result;
 120  
     }
 121  
 
 122  
     @Override
 123  
     @Transactional
 124  
     public List<AtpInfo> getAtpsByDateAndType(Date searchDate, String searchTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 125  
             PermissionDeniedException {
 126  0
         throw new UnsupportedOperationException("Not supported yet.");
 127  
     }
 128  
 
 129  
     @Override
 130  
     public List<AtpInfo> getAtpsByDatesAndType(Date startDate, Date endDate, String searchTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException,
 131  
             OperationFailedException, PermissionDeniedException {
 132  0
         throw new UnsupportedOperationException("Not supported yet.");
 133  
     }
 134  
 
 135  
     @Override
 136  
     public List<AtpInfo> getAtpsByStartDateRange(Date searchDateRangeStart, Date searchDateRangeEnd, ContextInfo context) throws InvalidParameterException, MissingParameterException,
 137  
             OperationFailedException, PermissionDeniedException {
 138  0
         List<AtpEntity> atps = atpDao.getByStartDateRange(searchDateRangeStart, searchDateRangeEnd);
 139  
 
 140  0
         List<AtpInfo> result = new ArrayList<AtpInfo>(atps.size());
 141  0
         if (null != atps) {
 142  0
             for (AtpEntity entity : atps) {
 143  0
                 result.add(entity.toDto());
 144  
             }
 145  
         }
 146  0
         return result;
 147  
     }
 148  
 
 149  
     @Override
 150  
     public List<AtpInfo> getAtpsByStartDateRangeAndType(Date searchDateRangeStart, Date searchDateRangeEnd, String searchTypeKey, ContextInfo context) throws InvalidParameterException,
 151  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 152  0
         List<AtpEntity> atps = atpDao.getByStartDateRangeAndType(searchDateRangeStart, searchDateRangeEnd, searchTypeKey);
 153  
 
 154  0
         List<AtpInfo> result = new ArrayList<AtpInfo>(atps.size());
 155  0
         if (null != atps) {
 156  0
             for (AtpEntity entity : atps) {
 157  0
                 result.add(entity.toDto());
 158  
             }
 159  
         }
 160  0
         return result;
 161  
     }
 162  
 
 163  
     @Override
 164  
     public List<AtpInfo> getAtpsByCode(String code, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 165  
         // TODO
 166  0
         return new ArrayList<AtpInfo>();
 167  
     }
 168  
 
 169  
     @Override
 170  
     public List<AtpInfo> getAtpsByIds(List<String> atpIds, ContextInfo contextInfo)
 171  
             throws DoesNotExistException, InvalidParameterException,
 172  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 173  0
         List<AtpEntity> atps = atpDao.findByIds(atpIds);
 174  
 
 175  0
         if (atps == null) {
 176  0
             throw new DoesNotExistException();
 177  
         }
 178  
 
 179  0
         List<AtpInfo> result = new ArrayList<AtpInfo>(atps.size());
 180  0
         for (AtpEntity entity : atps) {
 181  0
             if (entity == null) {
 182  
                 // if one of the entities from "findByIds" is returned as null,
 183  
                 // then one of the keys in the list was not found
 184  0
                 throw new DoesNotExistException();
 185  
             }
 186  0
             result.add(entity.toDto());
 187  
         }
 188  
 
 189  0
         return result;
 190  
     }
 191  
 
 192  
     @Override
 193  
     public List<String> getAtpIdsByType(String atpTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 194  
 
 195  0
         List<AtpEntity> results = atpDao.getByAtpTypeId(atpTypeKey);
 196  
 
 197  0
         List<String> keys = new ArrayList<String>(results.size());
 198  
 
 199  0
         for (AtpEntity atp : results) {
 200  0
             keys.add(atp.getId());
 201  
         }
 202  
 
 203  0
         return keys;
 204  
     }
 205  
 
 206  
     @Override
 207  
     public MilestoneInfo getMilestone(String milestoneId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 208  
             PermissionDeniedException {
 209  0
         MilestoneEntity entity = milestoneDao.find(milestoneId);
 210  
 
 211  0
         if (entity != null) {
 212  0
             return entity.toDto();
 213  
         } else {
 214  0
             throw new DoesNotExistException(milestoneId);
 215  
         }
 216  
 
 217  
     }
 218  
 
 219  
     @Override
 220  
     public List<MilestoneInfo> getMilestonesByIds(List<String> milestoneIds, ContextInfo contextInfo) throws DoesNotExistException,
 221  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 222  0
         List<MilestoneEntity> milestones = milestoneDao.findByIds(milestoneIds);
 223  
 
 224  0
         if (milestones == null) {
 225  0
             throw new DoesNotExistException();
 226  
         }
 227  
 
 228  0
         List<MilestoneInfo> result = new ArrayList<MilestoneInfo>(milestones.size());
 229  0
         for (MilestoneEntity entity : milestones) {
 230  0
             if (entity == null) {
 231  
                 // if one of the entities from "findByIds" is returned as null,
 232  
                 // then one of the keys in the list was not found
 233  0
                 throw new DoesNotExistException();
 234  
             }
 235  0
             result.add(entity.toDto());
 236  
         }
 237  
 
 238  0
         return result;
 239  
     }
 240  
 
 241  
     @Override
 242  
     public List<String> getMilestoneIdsByType(String milestoneTypeKey, ContextInfo contextInfo) throws InvalidParameterException,
 243  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 244  0
         List<MilestoneEntity> entities = milestoneDao.getByMilestoneTypeId(milestoneTypeKey);
 245  0
         List<String> results = new ArrayList<String>(entities.size());
 246  0
         for (MilestoneEntity entity : entities) {
 247  0
             results.add(entity.getId());
 248  
         }
 249  0
         return results;
 250  
     }
 251  
 
 252  
     @Override
 253  
     public List<MilestoneInfo> getMilestonesForAtp(String atpId, ContextInfo contextInfo) throws InvalidParameterException,
 254  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 255  0
         AtpEntity atp = atpDao.find(atpId);
 256  0
         if (atp == null) {
 257  0
             throw new InvalidParameterException(atpId);
 258  
         }
 259  0
         List<String> ids = milestoneDao.getIdsByAtp(atpId);
 260  
         try {
 261  0
             return this.getMilestonesByIds(ids, contextInfo);
 262  0
         } catch (DoesNotExistException ex) {
 263  0
             throw new OperationFailedException("Atp to Milestone relation exists to a milestone that has been deleted", ex);
 264  
         }
 265  
     }
 266  
 
 267  
     @Override
 268  
     public List<MilestoneInfo> getMilestonesByDates(Date startDate, Date endDate, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 269  
             PermissionDeniedException {
 270  0
         List<MilestoneEntity> entities = milestoneDao.getByDateRange(startDate, endDate);
 271  0
         List<MilestoneInfo> results = new ArrayList<MilestoneInfo>(entities.size());
 272  0
         for (MilestoneEntity entity : entities) {
 273  0
             results.add(entity.toDto());
 274  
         }
 275  0
         return results;
 276  
     }
 277  
 
 278  
     @Override
 279  
     public List<MilestoneInfo> getMilestonesByDatesForAtp(String atpId, Date startDate, Date endDate,
 280  
             ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 281  0
         List<MilestoneEntity> entities = milestoneDao.getByDatesForAtp(atpId, startDate, endDate);
 282  0
         List<MilestoneInfo> results = new ArrayList<MilestoneInfo>(entities.size());
 283  0
         for (MilestoneEntity entity : entities) {
 284  0
             results.add(entity.toDto());
 285  
         }
 286  0
         return results;
 287  
     }
 288  
 
 289  
     @Override
 290  
     public List<MilestoneInfo> getMilestonesByTypeForAtp(String atpId,
 291  
             String milestoneTypeKey,
 292  
             ContextInfo contextInfo)
 293  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 294  0
         List<MilestoneInfo> list = this.getMilestonesForAtp(atpId, contextInfo);
 295  0
         List<MilestoneInfo> results = new ArrayList<MilestoneInfo>(list.size());
 296  0
         for (MilestoneInfo info : list) {
 297  0
             results.add(info);
 298  
         }
 299  0
         return results;
 300  
     }
 301  
 
 302  
     @Override
 303  
     public List<String> searchForAtpIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 304  
 
 305  0
         return new ArrayList<String>();
 306  
     }
 307  
 
 308  
     @Override
 309  
     public List<AtpInfo> searchForAtps(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 310  
 
 311  0
         List<AtpInfo> atpInfos = new ArrayList<AtpInfo>();
 312  0
         GenericQueryResults<AtpEntity> results = criteriaLookupService.lookup(AtpEntity.class, criteria);
 313  
 
 314  0
         if (null != results && results.getResults().size() > 0) {
 315  0
             for (AtpEntity atp : results.getResults()) {
 316  0
                 atpInfos.add(atp.toDto());
 317  
             }
 318  
         }
 319  
 
 320  0
         return atpInfos;
 321  
     }
 322  
 
 323  
     @Override
 324  
     public List<ValidationResultInfo> validateAtp(String validationTypeKey, 
 325  
     String atpTypeKey,
 326  
             AtpInfo atpInfo, ContextInfo contextInfo) 
 327  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 328  
             OperationFailedException, PermissionDeniedException {
 329  0
         return new ArrayList<ValidationResultInfo>();
 330  
     }
 331  
 
 332  
     @Override
 333  
     @Transactional(readOnly = false)
 334  
     public AtpInfo createAtp(String atpTypeKey, AtpInfo atpInfo, ContextInfo contextInfo)
 335  
             throws DataValidationErrorException, InvalidParameterException,
 336  
             MissingParameterException, OperationFailedException,
 337  
             PermissionDeniedException, ReadOnlyException {
 338  
 
 339  0
         AtpEntity entity = new AtpEntity(atpInfo);
 340  0
         entity.setId(atpInfo.getId());
 341  0
         entity.setAtpType(atpTypeKey);
 342  
        
 343  0
         entity.setEntityCreated(contextInfo);
 344  
         
 345  
 //        System.out.println ("AtpEntity: before persist ATP " + entity.getId());
 346  0
         atpDao.persist(entity);
 347  
 //        System.out.println ("AtpEntity: after persist ATP " + entity.getId());
 348  
 //        System.out.println ("AtpEntity: flushmode=" + atpDao.getEm().getFlushMode());
 349  
 //        atpDao.getEm().flush ();
 350  
 //        System.out.println ("AtpEntity: after flush ATP " + entity.getId());
 351  0
         return entity.toDto();
 352  
     }
 353  
 
 354  
     @Override
 355  
     @Transactional(readOnly = false)
 356  
     public AtpInfo updateAtp(String atpId, AtpInfo atpInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException,
 357  
             OperationFailedException, PermissionDeniedException, VersionMismatchException {
 358  0
         AtpEntity entity = atpDao.find(atpId);
 359  0
         if (entity == null) {
 360  0
             throw new DoesNotExistException(atpId);
 361  
         }
 362  0
         entity.fromDTO(atpInfo);
 363  
         
 364  0
         entity.setEntityUpdated(context);
 365  
         
 366  0
         atpDao.merge(entity);
 367  0
         return entity.toDto();
 368  
     }
 369  
 
 370  
     @Override
 371  
     @Transactional(readOnly = false)
 372  
     public StatusInfo deleteAtp(String atpId, ContextInfo context) throws DoesNotExistException,
 373  
             InvalidParameterException, MissingParameterException, OperationFailedException,
 374  
             PermissionDeniedException {
 375  0
         AtpEntity entity = atpDao.find(atpId);
 376  0
         if (null == entity) {
 377  0
             throw new DoesNotExistException(atpId);
 378  
         }
 379  0
         List<AtpAtpRelationEntity> aarEntities = atpRelDao.getAtpAtpRelationsByAtp(atpId);
 380  0
         if (null != aarEntities) {
 381  0
             for (AtpAtpRelationEntity aarEntity : aarEntities) {
 382  0
                 atpRelDao.remove(aarEntity);
 383  
             }
 384  
         }
 385  0
         List<AtpMilestoneRelationEntity> amrEntities = atpMilestoneRelationDao.getByAtpId(atpId);
 386  0
         if (null != amrEntities) {
 387  0
             for (AtpMilestoneRelationEntity amrEntity : amrEntities) {
 388  0
                 atpMilestoneRelationDao.remove(amrEntity);
 389  
             }
 390  
         }
 391  0
         atpDao.remove(entity);
 392  0
         StatusInfo status = new StatusInfo();
 393  0
         status.setSuccess(Boolean.TRUE);
 394  0
         return status;
 395  
     }
 396  
 
 397  
     @Override
 398  
     public List<MilestoneInfo> getImpactedMilestones(String milestoneId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 399  
             OperationFailedException, PermissionDeniedException {
 400  0
         List<MilestoneInfo> impactedMilestones = new ArrayList<MilestoneInfo>();
 401  0
         for (MilestoneEntity impactedMilestone : milestoneDao.getImpactedMilestones(milestoneId)) {
 402  0
             impactedMilestones.add(impactedMilestone.toDto());
 403  
         }
 404  0
         return impactedMilestones;
 405  
     }
 406  
 
 407  
     @Override
 408  
     public List<String> searchForMilestoneIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException,
 409  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 410  0
         return null; // To change body of implemented methods use File |
 411  
         // Settings | File Templates.
 412  
     }
 413  
 
 414  
     @Override
 415  
     public List<MilestoneInfo> searchForMilestones(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 416  
             PermissionDeniedException {
 417  
 
 418  0
         List<MilestoneInfo> milestoneInfos = new ArrayList<MilestoneInfo>();
 419  0
         GenericQueryResults<MilestoneEntity> results = criteriaLookupService.lookup(MilestoneEntity.class, criteria);
 420  
 
 421  0
         if (null != results && results.getResults().size() > 0) {
 422  0
             for (MilestoneEntity milestone : results.getResults()) {
 423  0
                 milestoneInfos.add(milestone.toDto());
 424  
             }
 425  
         }
 426  
 
 427  0
         return milestoneInfos;
 428  
     }
 429  
 
 430  
     @Override
 431  
     public List<ValidationResultInfo> validateMilestone(String validationType, MilestoneInfo milestoneInfo, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 432  
             MissingParameterException, OperationFailedException {
 433  
 
 434  0
         return null;
 435  
     }
 436  
 
 437  
     @Override
 438  
     @Transactional(readOnly = false)
 439  
     public MilestoneInfo createMilestone(String milestoneTypeKey, MilestoneInfo milestoneInfo, ContextInfo contextInfo)
 440  
             throws DataValidationErrorException,
 441  
             InvalidParameterException, MissingParameterException, OperationFailedException,
 442  
             PermissionDeniedException, ReadOnlyException {
 443  
 
 444  0
         if (!milestoneTypeKey.equals(milestoneInfo.getTypeKey())) {
 445  0
             throw new InvalidParameterException(milestoneTypeKey + " does not match " + milestoneInfo.getTypeKey());
 446  
         }
 447  0
         MilestoneEntity entity = new MilestoneEntity(milestoneInfo);
 448  0
         entity.setId(milestoneInfo.getId());
 449  0
         entity.setAtpType(milestoneTypeKey);
 450  
         
 451  0
         entity.setEntityCreated(contextInfo);
 452  
         
 453  0
         milestoneDao.persist(entity);
 454  0
         MilestoneInfo result = entity.toDto();
 455  0
         return result;
 456  
     }
 457  
 
 458  
     @Override
 459  
     @Transactional(readOnly = false)
 460  
     public MilestoneInfo updateMilestone(String milestoneId, MilestoneInfo milestoneInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 461  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 462  
 
 463  0
         MilestoneEntity entity = milestoneDao.find(milestoneId);
 464  0
         if (entity == null) {
 465  0
             throw new DoesNotExistException(milestoneId);
 466  
         }
 467  0
         entity.fromDto(milestoneInfo);
 468  
         
 469  0
         entity.setEntityUpdated(context);
 470  
         
 471  0
         milestoneDao.merge(entity);
 472  0
         return entity.toDto();
 473  
     }
 474  
 
 475  
     @Override
 476  
     @Transactional(readOnly = false)
 477  
     public StatusInfo deleteMilestone(String milestoneId, ContextInfo context)
 478  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 479  
             OperationFailedException,
 480  
             PermissionDeniedException {
 481  
 
 482  0
         MilestoneEntity existingEntity = milestoneDao.find(milestoneId);
 483  0
         if (existingEntity == null) {
 484  0
             throw new DoesNotExistException(milestoneId);
 485  
         }
 486  0
         List<AtpMilestoneRelationEntity> amrEntities = atpMilestoneRelationDao.getByMilestoneId(milestoneId);
 487  0
         if (null != amrEntities) {
 488  0
             for (AtpMilestoneRelationEntity amrEntity : amrEntities) {
 489  0
                 atpMilestoneRelationDao.remove(amrEntity);
 490  
             }
 491  
         }
 492  0
         milestoneDao.remove(existingEntity);
 493  0
         StatusInfo status = new StatusInfo();
 494  0
         status.setSuccess(Boolean.TRUE);
 495  0
         return status;
 496  
     }
 497  
 
 498  
     @Override
 499  
     @Transactional(readOnly = false)
 500  
     public MilestoneInfo calculateMilestone(String milestoneId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 501  
             PermissionDeniedException {
 502  0
         throw new OperationFailedException("Method implemented in calculation decorator.");
 503  
     }
 504  
 
 505  
     @Override
 506  
     @Transactional(readOnly = false)
 507  
     public StatusInfo addMilestoneToAtp(String milestoneId, String atpId, ContextInfo contextInfo)
 508  
             throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 509  
 
 510  0
         AtpEntity atp = atpDao.find(atpId);
 511  0
         if (atp == null) {
 512  0
             throw new DoesNotExistException(atpId);
 513  
         }
 514  0
         MilestoneEntity milestone = milestoneDao.find(milestoneId);
 515  0
         if (milestone == null) {
 516  0
             throw new DoesNotExistException(milestoneId);
 517  
         }
 518  0
         List<String> ids = atpMilestoneRelationDao.getIdsByAtpAndMilestone(atpId, milestoneId);
 519  0
         if (!ids.isEmpty()) {
 520  0
             throw new AlreadyExistsException("Milestone " + milestoneId + " already exists for ATP " + atpId);
 521  
         }
 522  
 
 523  0
         AtpMilestoneRelationEntity entity = new AtpMilestoneRelationEntity();
 524  0
         entity.setAtpId(atpId);
 525  0
         entity.setMilestoneId(milestoneId);
 526  
       
 527  0
         entity.setEntityCreated(contextInfo);
 528  
 
 529  0
         atpMilestoneRelationDao.persist(entity);
 530  0
         StatusInfo info = new StatusInfo();
 531  0
         info.setSuccess(true);
 532  
 
 533  0
         return info;
 534  
     }
 535  
 
 536  
     @Override
 537  
     @Transactional(readOnly = false)
 538  
     public StatusInfo removeMilestoneFromAtp(String milestoneId, String atpId, ContextInfo contextInfo)
 539  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 540  0
         List<String> ids = atpMilestoneRelationDao.getIdsByAtpAndMilestone(atpId, milestoneId);
 541  0
         if (ids.isEmpty()) {
 542  0
             throw new DoesNotExistException("No relationship exists between the atp " + atpId + " and milestone " + milestoneId);
 543  
         }
 544  0
         if (ids.size() > 1) {
 545  0
             throw new OperationFailedException("Database error there should only be one relationship record found " + ids.size());
 546  
         }
 547  0
         AtpMilestoneRelationEntity entity = atpMilestoneRelationDao.find(ids.get(0));
 548  0
         if (entity == null) {
 549  0
             throw new OperationFailedException("rror there should only be one relationship record found " + ids.size());
 550  
         }
 551  0
         atpMilestoneRelationDao.remove(entity);
 552  0
         StatusInfo status = new StatusInfo();
 553  0
         status.setSuccess(true);
 554  0
         return status;
 555  
 
 556  
     }
 557  
 
 558  
     @Override
 559  
     public AtpAtpRelationInfo getAtpAtpRelation(String atpAtpRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 560  
             OperationFailedException, PermissionDeniedException {
 561  0
         AtpAtpRelationEntity atpRel = atpRelDao.find(atpAtpRelationId);
 562  0
         if (null == atpRel) {
 563  0
             throw new DoesNotExistException(atpAtpRelationId);
 564  
         }
 565  0
         return atpRel.toDto();
 566  
     }
 567  
 
 568  
     @Override
 569  
     public List<AtpAtpRelationInfo> getAtpAtpRelationsByIds(List<String> atpAtpRelationIds,
 570  
             ContextInfo contextInfo)
 571  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 572  0
         return new ArrayList<AtpAtpRelationInfo>();
 573  
     }
 574  
 
 575  
     @Override
 576  
     public List<String> getAtpAtpRelationIdsByType(String atpAtpRelationTypeKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 577  
             PermissionDeniedException {
 578  0
         return new ArrayList<String>();
 579  
     }
 580  
 
 581  
     @Override
 582  
     public List<AtpAtpRelationInfo> getAtpAtpRelationsByAtp(String atpId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 583  
             PermissionDeniedException {
 584  
 
 585  0
         List<AtpAtpRelationEntity> relEntities = atpRelDao.getAtpAtpRelationsByAtp(atpId);
 586  0
         List<AtpAtpRelationInfo> relInfos = new ArrayList<AtpAtpRelationInfo>();
 587  0
         for (AtpAtpRelationEntity relEntity : relEntities) {
 588  0
             AtpAtpRelationInfo relInfo = relEntity.toDto();
 589  0
             relInfos.add(relInfo);
 590  0
         }
 591  
 
 592  0
         return relInfos;
 593  
     }
 594  
 
 595  
     @Override
 596  
     public List<AtpAtpRelationInfo> getAtpAtpRelationsByAtps(String atpId,
 597  
            ContextInfo contextInfo) throws InvalidParameterException,
 598  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 599  0
         List<AtpAtpRelationEntity> relations = atpRelDao.getAtpAtpRelationsByAtp(atpId);
 600  0
         List<AtpAtpRelationInfo> relationsDTO = new ArrayList();
 601  0
         for (AtpAtpRelationEntity relation : relations) {
 602  0
             relationsDTO.add(relation.toDto());
 603  
         }
 604  0
         return relationsDTO;
 605  
     }
 606  
 
 607  
     @Override
 608  
     public List<AtpAtpRelationInfo> getAtpAtpRelationsByTypeAndAtp(String atpId,
 609  
            String atpRelationTypeKey,
 610  
             ContextInfo contextInfo) 
 611  
             throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 612  0
         List<AtpAtpRelationEntity> rels = atpRelDao.getAtpAtpRelationsByAtpAndRelationType(atpId, atpRelationTypeKey);
 613  0
         List<AtpAtpRelationInfo> atpRelation = new ArrayList<AtpAtpRelationInfo>();
 614  0
         for (AtpAtpRelationEntity rel : rels) {
 615  0
             atpRelation.add(rel.toDto());
 616  
         }
 617  0
         return atpRelation;
 618  
     }
 619  
 
 620  
     @Override
 621  
     public List<String> searchForAtpAtpRelationIds(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 622  
             PermissionDeniedException {
 623  
 
 624  0
         return new ArrayList<String>();
 625  
     }
 626  
 
 627  
     @Override
 628  
     public List<AtpAtpRelationInfo> searchForAtpAtpRelations(QueryByCriteria criteria, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 629  
             PermissionDeniedException {
 630  
 
 631  0
         return new ArrayList<AtpAtpRelationInfo>();
 632  
     }
 633  
 
 634  
     @Override
 635  
     public List<ValidationResultInfo> validateAtpAtpRelation(String validationTypeKey,
 636  
             String atpId,
 637  
             String atpPeerKey,
 638  
             String atpAtpRelationTypeKey,
 639  
             AtpAtpRelationInfo atpAtpRelationInfo,
 640  
             ContextInfo contextInfo) throws DoesNotExistException,
 641  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 642  0
         return new ArrayList<ValidationResultInfo>();
 643  
     }
 644  
 
 645  
 //    private boolean checkRelationExistence(AtpAtpRelationInfo atpAtpRelationInfo) {
 646  
 //        boolean exist = false;
 647  
 //
 648  
 //        List<AtpAtpRelationEntity> rels = atpRelDao.getAtpAtpRelationsByAtpAndRelationType(atpAtpRelationInfo.getAtpId(), atpAtpRelationInfo.getTypeKey());
 649  
 //        if (rels != null && !rels.isEmpty()) {
 650  
 //            for (AtpAtpRelationEntity rel : rels) {
 651  
 //                if (rel.getRelatedAtp().getId().equals(atpAtpRelationInfo.getRelatedAtpId())) {
 652  
 //                    exist = true;
 653  
 //                    break;
 654  
 //                }
 655  
 //            }
 656  
 //        }
 657  
 //        return exist;
 658  
 //    }
 659  
     @Override
 660  
     @Transactional(readOnly = false)
 661  
     public AtpAtpRelationInfo createAtpAtpRelation(String atpId,
 662  
             String relatedAtpId,
 663  
             String atpAtpRelationTypeKey,
 664  
             AtpAtpRelationInfo atpAtpRelationInfo,
 665  
             ContextInfo contextInfo)
 666  
             throws DoesNotExistException,
 667  
             DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 668  
 
 669  0
         if (!atpId.equals(atpAtpRelationInfo.getAtpId())) {
 670  0
             throw new InvalidParameterException(atpId + " does not match the " + atpAtpRelationInfo.getAtpId());
 671  
         }
 672  0
         if (!relatedAtpId.equals(atpAtpRelationInfo.getRelatedAtpId())) {
 673  0
             throw new InvalidParameterException(relatedAtpId + " does not match the " + atpAtpRelationInfo.getRelatedAtpId());
 674  
         }
 675  0
         if (!atpAtpRelationTypeKey.equals(atpAtpRelationInfo.getTypeKey())) {
 676  0
             throw new InvalidParameterException(atpAtpRelationTypeKey + " does not match the " + atpAtpRelationInfo.getTypeKey());
 677  
         }
 678  
         // TODO: Why is this check here?  Is there such a restriction? the model allos there to be many such relations over time
 679  
 //        if (checkRelationExistence(atpAtpRelationInfo)) {
 680  
 //            throw new DataValidationErrorException("The Atp-Atp relation already exists. atp=" + atpAtpRelationInfo.getAtpId() + ", relatedAtp=" + atpAtpRelationInfo.getRelatedAtpId());
 681  
 //        }
 682  0
         AtpAtpRelationEntity entity = new AtpAtpRelationEntity(atpAtpRelationInfo);
 683  0
         entity.setId(atpAtpRelationInfo.getId());
 684  0
         entity.setAtpType(atpAtpRelationTypeKey);
 685  0
         entity.setAtp(atpDao.find(atpId));
 686  0
         if (entity.getAtp() == null) {
 687  0
             throw new DoesNotExistException(atpId);
 688  
         }
 689  0
         entity.setRelatedAtp(atpDao.find(relatedAtpId));
 690  0
         if (entity.getRelatedAtp() == null) {
 691  0
             throw new DoesNotExistException(relatedAtpId);
 692  
         }
 693  
         
 694  0
         entity.setEntityCreated(contextInfo);
 695  
         
 696  0
         atpRelDao.persist(entity);
 697  0
         return entity.toDto();
 698  
     }
 699  
 
 700  
     @Override
 701  
     @Transactional(readOnly = false)
 702  
     public AtpAtpRelationInfo updateAtpAtpRelation(String atpAtpRelationId,
 703  
             AtpAtpRelationInfo atpAtpRelationInfo,
 704  
             ContextInfo context)
 705  
             throws DataValidationErrorException, DoesNotExistException,
 706  
             InvalidParameterException, MissingParameterException,
 707  
             OperationFailedException, PermissionDeniedException, VersionMismatchException {
 708  0
         AtpAtpRelationEntity entity = atpRelDao.find(atpAtpRelationId);
 709  0
         if (null == entity) {
 710  0
             throw new DoesNotExistException(atpAtpRelationId);
 711  
         }
 712  0
         entity.fromDTO(atpAtpRelationInfo);
 713  
         
 714  0
         entity.setEntityUpdated(context);
 715  
         
 716  0
         atpRelDao.merge(entity);
 717  0
         return entity.toDto();
 718  
     }
 719  
 
 720  
     @Override
 721  
     @Transactional(readOnly = false)
 722  
     public StatusInfo deleteAtpAtpRelation(String atpAtpRelationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 723  
             PermissionDeniedException {
 724  0
         AtpAtpRelationEntity atpRel = atpRelDao.find(atpAtpRelationId);
 725  0
         if (atpRel == null) {
 726  0
             throw new DoesNotExistException(atpAtpRelationId);
 727  
         }
 728  0
         atpRelDao.remove(atpRel);
 729  0
         StatusInfo status = new StatusInfo();
 730  0
         status.setSuccess(Boolean.TRUE);
 731  0
         return status;
 732  
     }
 733  
 }