@Test(expected = ValueSetNotFoundException.class) public void testUpdateConceptCode_throw_valueSetNotFoundException2() throws ConceptCodeNotFoundException, ValueSetNotFoundException { ConceptCodeDto updated = mock(ConceptCodeDto.class); when(updated.getId()).thenReturn((long) 1); when(updated.getCode()).thenReturn("code"); when(updated.getName()).thenReturn("name"); when(updated.getUserName()).thenReturn("username"); ConceptCode conceptCode = mock(ConceptCode.class); when(conceptCode.getId()).thenReturn((long) 1); when(conceptCodeRepository.findOne(anyLong())).thenReturn(conceptCode); ConceptCodeDto conceptCodeDto = mock(ConceptCodeDto.class); when(valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode)) .thenReturn(conceptCodeDto); List<Long> selVsIds = Arrays.asList((long) 1, (long) 2, (long) 3); when(updated.getValueSetIds()).thenReturn(selVsIds); when(conceptCodeValueSetRepository.findAllByPkConceptCodeId(anyLong())) .thenReturn(null); conceptCodeServiceImpl.update(updated); }
@Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) public ConceptCodeDto update(ConceptCodeDto updated) throws ConceptCodeNotFoundException, ValueSetNotFoundException { logger.debug("Updating ConceptCode with information" + updated); ConceptCode conceptCode = conceptCodeRepository .findOne(updated.getId()); if (conceptCode == null) { logger.debug("No ConceptCode found with an id: " + updated.getId()); throw new ConceptCodeNotFoundException(); } conceptCode.update(updated.getCode(), updated.getName(), updated.getUserName()); List<Long> selVsIds = updated.getValueSetIds(); if (null == selVsIds || selVsIds.size() <= 0) { throw new ValueSetNotFoundException( "Need to Associate atleast one valueset to the code: " + updated.getCode()); } List<ConceptCodeValueSet> cValueSets = conceptCodeValueSetRepository .findAllByPkConceptCodeId(conceptCode.getId()); if (cValueSets == null) { throw new ValueSetNotFoundException( "No Valusets associated to the given code" + conceptCode); } List<ConceptCodeValueSet> selCodeValueSets = new ArrayList<ConceptCodeValueSet>(); List<Long> selIds = new ArrayList<Long>(); for (ConceptCodeValueSet aCodeValueSet : cValueSets) { for (Long selId : selVsIds) { if (aCodeValueSet.getValueSet().getId().equals(selId)) { selCodeValueSets.add(aCodeValueSet); selIds.add(selId); break; } } } cValueSets.removeAll(selCodeValueSets); selVsIds.removeAll(selIds); if (null != cValueSets && cValueSets.size() > 0) conceptCodeValueSetRepository.delete(cValueSets); List<ConceptCodeValueSet> cVSets = new ArrayList<ConceptCodeValueSet>(); for (Long id : selVsIds) { ValueSet vSet = valueSetRepository.findOne(id); if (null == vSet) { throw new ValueSetNotFoundException( "No Valueset Found for the Selected Name"); } ConceptCodeValueSet cValueSet = ConceptCodeValueSet.getBuilder( conceptCode, vSet).build(); cVSets.add(cValueSet); } if (null != cVSets && cVSets.size() > 0) cVSets = conceptCodeValueSetRepository.save(cVSets); conceptCode.setValueSets(selCodeValueSets); return valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode); }
ConceptCodeServiceImpl implements ConceptCodeService { @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) public ConceptCodeDto update(ConceptCodeDto updated) throws ConceptCodeNotFoundException, ValueSetNotFoundException { logger.debug("Updating ConceptCode with information" + updated); ConceptCode conceptCode = conceptCodeRepository .findOne(updated.getId()); if (conceptCode == null) { logger.debug("No ConceptCode found with an id: " + updated.getId()); throw new ConceptCodeNotFoundException(); } conceptCode.update(updated.getCode(), updated.getName(), updated.getUserName()); List<Long> selVsIds = updated.getValueSetIds(); if (null == selVsIds || selVsIds.size() <= 0) { throw new ValueSetNotFoundException( "Need to Associate atleast one valueset to the code: " + updated.getCode()); } List<ConceptCodeValueSet> cValueSets = conceptCodeValueSetRepository .findAllByPkConceptCodeId(conceptCode.getId()); if (cValueSets == null) { throw new ValueSetNotFoundException( "No Valusets associated to the given code" + conceptCode); } List<ConceptCodeValueSet> selCodeValueSets = new ArrayList<ConceptCodeValueSet>(); List<Long> selIds = new ArrayList<Long>(); for (ConceptCodeValueSet aCodeValueSet : cValueSets) { for (Long selId : selVsIds) { if (aCodeValueSet.getValueSet().getId().equals(selId)) { selCodeValueSets.add(aCodeValueSet); selIds.add(selId); break; } } } cValueSets.removeAll(selCodeValueSets); selVsIds.removeAll(selIds); if (null != cValueSets && cValueSets.size() > 0) conceptCodeValueSetRepository.delete(cValueSets); List<ConceptCodeValueSet> cVSets = new ArrayList<ConceptCodeValueSet>(); for (Long id : selVsIds) { ValueSet vSet = valueSetRepository.findOne(id); if (null == vSet) { throw new ValueSetNotFoundException( "No Valueset Found for the Selected Name"); } ConceptCodeValueSet cValueSet = ConceptCodeValueSet.getBuilder( conceptCode, vSet).build(); cVSets.add(cValueSet); } if (null != cVSets && cVSets.size() > 0) cVSets = conceptCodeValueSetRepository.save(cVSets); conceptCode.setValueSets(selCodeValueSets); return valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode); } }
ConceptCodeServiceImpl implements ConceptCodeService { @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) public ConceptCodeDto update(ConceptCodeDto updated) throws ConceptCodeNotFoundException, ValueSetNotFoundException { logger.debug("Updating ConceptCode with information" + updated); ConceptCode conceptCode = conceptCodeRepository .findOne(updated.getId()); if (conceptCode == null) { logger.debug("No ConceptCode found with an id: " + updated.getId()); throw new ConceptCodeNotFoundException(); } conceptCode.update(updated.getCode(), updated.getName(), updated.getUserName()); List<Long> selVsIds = updated.getValueSetIds(); if (null == selVsIds || selVsIds.size() <= 0) { throw new ValueSetNotFoundException( "Need to Associate atleast one valueset to the code: " + updated.getCode()); } List<ConceptCodeValueSet> cValueSets = conceptCodeValueSetRepository .findAllByPkConceptCodeId(conceptCode.getId()); if (cValueSets == null) { throw new ValueSetNotFoundException( "No Valusets associated to the given code" + conceptCode); } List<ConceptCodeValueSet> selCodeValueSets = new ArrayList<ConceptCodeValueSet>(); List<Long> selIds = new ArrayList<Long>(); for (ConceptCodeValueSet aCodeValueSet : cValueSets) { for (Long selId : selVsIds) { if (aCodeValueSet.getValueSet().getId().equals(selId)) { selCodeValueSets.add(aCodeValueSet); selIds.add(selId); break; } } } cValueSets.removeAll(selCodeValueSets); selVsIds.removeAll(selIds); if (null != cValueSets && cValueSets.size() > 0) conceptCodeValueSetRepository.delete(cValueSets); List<ConceptCodeValueSet> cVSets = new ArrayList<ConceptCodeValueSet>(); for (Long id : selVsIds) { ValueSet vSet = valueSetRepository.findOne(id); if (null == vSet) { throw new ValueSetNotFoundException( "No Valueset Found for the Selected Name"); } ConceptCodeValueSet cValueSet = ConceptCodeValueSet.getBuilder( conceptCode, vSet).build(); cVSets.add(cValueSet); } if (null != cVSets && cVSets.size() > 0) cVSets = conceptCodeValueSetRepository.save(cVSets); conceptCode.setValueSets(selCodeValueSets); return valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode); } ConceptCodeServiceImpl(int conceptCodePageSize,
			ConceptCodeRepository conceptCodeRepository,
			ValueSetRepository valueSetRepository,
			CodeSystemRepository codeSystemRepository,
			CodeSystemVersionRepository codeSystemVersionRepository,
			ConceptCodeValueSetRepository conceptCodeValueSetRepository,
			ValueSetMgmtHelper valueSetMgmtHelper); }
ConceptCodeServiceImpl implements ConceptCodeService { @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) public ConceptCodeDto update(ConceptCodeDto updated) throws ConceptCodeNotFoundException, ValueSetNotFoundException { logger.debug("Updating ConceptCode with information" + updated); ConceptCode conceptCode = conceptCodeRepository .findOne(updated.getId()); if (conceptCode == null) { logger.debug("No ConceptCode found with an id: " + updated.getId()); throw new ConceptCodeNotFoundException(); } conceptCode.update(updated.getCode(), updated.getName(), updated.getUserName()); List<Long> selVsIds = updated.getValueSetIds(); if (null == selVsIds || selVsIds.size() <= 0) { throw new ValueSetNotFoundException( "Need to Associate atleast one valueset to the code: " + updated.getCode()); } List<ConceptCodeValueSet> cValueSets = conceptCodeValueSetRepository .findAllByPkConceptCodeId(conceptCode.getId()); if (cValueSets == null) { throw new ValueSetNotFoundException( "No Valusets associated to the given code" + conceptCode); } List<ConceptCodeValueSet> selCodeValueSets = new ArrayList<ConceptCodeValueSet>(); List<Long> selIds = new ArrayList<Long>(); for (ConceptCodeValueSet aCodeValueSet : cValueSets) { for (Long selId : selVsIds) { if (aCodeValueSet.getValueSet().getId().equals(selId)) { selCodeValueSets.add(aCodeValueSet); selIds.add(selId); break; } } } cValueSets.removeAll(selCodeValueSets); selVsIds.removeAll(selIds); if (null != cValueSets && cValueSets.size() > 0) conceptCodeValueSetRepository.delete(cValueSets); List<ConceptCodeValueSet> cVSets = new ArrayList<ConceptCodeValueSet>(); for (Long id : selVsIds) { ValueSet vSet = valueSetRepository.findOne(id); if (null == vSet) { throw new ValueSetNotFoundException( "No Valueset Found for the Selected Name"); } ConceptCodeValueSet cValueSet = ConceptCodeValueSet.getBuilder( conceptCode, vSet).build(); cVSets.add(cValueSet); } if (null != cVSets && cVSets.size() > 0) cVSets = conceptCodeValueSetRepository.save(cVSets); conceptCode.setValueSets(selCodeValueSets); return valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode); } ConceptCodeServiceImpl(int conceptCodePageSize,
			ConceptCodeRepository conceptCodeRepository,
			ValueSetRepository valueSetRepository,
			CodeSystemRepository codeSystemRepository,
			CodeSystemVersionRepository codeSystemVersionRepository,
			ConceptCodeValueSetRepository conceptCodeValueSetRepository,
			ValueSetMgmtHelper valueSetMgmtHelper); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto delete(Long conceptCodeId); @Override ConceptCodeDto findById(Long id); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto update(ConceptCodeDto updated); @Override List<ConceptCodeDto> findAll(); @Override Map<String, Object> findAll(int pageNumber); @Override Map<String, Object> findAllByCode(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override Map<String, Object> findAllByName(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override ConceptCodeVSCSDto create(); @Override @Transactional ConceptCodeDto create(ConceptCodeDto created); @Override @Transactional(rollbackFor = DataIntegrityViolationException.class) ConceptCodeDto conceptCodeBatchUpload(ConceptCodeDto conceptCodeDto,
			MultipartFile file, String codeSystemId, Long codeSystemVersionId,
			List<Long> valueSetIds); @Override List<ValueSet> findValueSetsByCodeSystem(String codeSystem,
			String codeSystemVersion); }
ConceptCodeServiceImpl implements ConceptCodeService { @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) public ConceptCodeDto update(ConceptCodeDto updated) throws ConceptCodeNotFoundException, ValueSetNotFoundException { logger.debug("Updating ConceptCode with information" + updated); ConceptCode conceptCode = conceptCodeRepository .findOne(updated.getId()); if (conceptCode == null) { logger.debug("No ConceptCode found with an id: " + updated.getId()); throw new ConceptCodeNotFoundException(); } conceptCode.update(updated.getCode(), updated.getName(), updated.getUserName()); List<Long> selVsIds = updated.getValueSetIds(); if (null == selVsIds || selVsIds.size() <= 0) { throw new ValueSetNotFoundException( "Need to Associate atleast one valueset to the code: " + updated.getCode()); } List<ConceptCodeValueSet> cValueSets = conceptCodeValueSetRepository .findAllByPkConceptCodeId(conceptCode.getId()); if (cValueSets == null) { throw new ValueSetNotFoundException( "No Valusets associated to the given code" + conceptCode); } List<ConceptCodeValueSet> selCodeValueSets = new ArrayList<ConceptCodeValueSet>(); List<Long> selIds = new ArrayList<Long>(); for (ConceptCodeValueSet aCodeValueSet : cValueSets) { for (Long selId : selVsIds) { if (aCodeValueSet.getValueSet().getId().equals(selId)) { selCodeValueSets.add(aCodeValueSet); selIds.add(selId); break; } } } cValueSets.removeAll(selCodeValueSets); selVsIds.removeAll(selIds); if (null != cValueSets && cValueSets.size() > 0) conceptCodeValueSetRepository.delete(cValueSets); List<ConceptCodeValueSet> cVSets = new ArrayList<ConceptCodeValueSet>(); for (Long id : selVsIds) { ValueSet vSet = valueSetRepository.findOne(id); if (null == vSet) { throw new ValueSetNotFoundException( "No Valueset Found for the Selected Name"); } ConceptCodeValueSet cValueSet = ConceptCodeValueSet.getBuilder( conceptCode, vSet).build(); cVSets.add(cValueSet); } if (null != cVSets && cVSets.size() > 0) cVSets = conceptCodeValueSetRepository.save(cVSets); conceptCode.setValueSets(selCodeValueSets); return valueSetMgmtHelper.createConceptCodeDtoFromEntity(conceptCode); } ConceptCodeServiceImpl(int conceptCodePageSize,
			ConceptCodeRepository conceptCodeRepository,
			ValueSetRepository valueSetRepository,
			CodeSystemRepository codeSystemRepository,
			CodeSystemVersionRepository codeSystemVersionRepository,
			ConceptCodeValueSetRepository conceptCodeValueSetRepository,
			ValueSetMgmtHelper valueSetMgmtHelper); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto delete(Long conceptCodeId); @Override ConceptCodeDto findById(Long id); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto update(ConceptCodeDto updated); @Override List<ConceptCodeDto> findAll(); @Override Map<String, Object> findAll(int pageNumber); @Override Map<String, Object> findAllByCode(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override Map<String, Object> findAllByName(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override ConceptCodeVSCSDto create(); @Override @Transactional ConceptCodeDto create(ConceptCodeDto created); @Override @Transactional(rollbackFor = DataIntegrityViolationException.class) ConceptCodeDto conceptCodeBatchUpload(ConceptCodeDto conceptCodeDto,
			MultipartFile file, String codeSystemId, Long codeSystemVersionId,
			List<Long> valueSetIds); @Override List<ValueSet> findValueSetsByCodeSystem(String codeSystem,
			String codeSystemVersion); final int CONCEPT_CODE_PAGE_SIZE; }