@Test public void saveOrUpdateShouldSaveValidPositionDtoDTO() { given(this.positionRepository.findByName(DEVELOPER_NAME)).willReturn(null); given(this.converterService.convert(developerDto, PositionEntity.class)).willReturn(developerEntity); given(this.positionRepository.saveAndFlush(developerEntity)).willReturn(developerEntity); this.positionService.saveOrUpdate(developerDto); then(this.positionRepository).should().findByName(DEVELOPER_NAME); then(this.positionRepository).should().saveAndFlush(developerEntity); then(this.converterService).should().convert(developerDto, PositionEntity.class); }
@Transactional @Override public Long saveOrUpdate(PositionDTO position) { Assert.notNull(position); Assert.notNull(position.getName()); PositionEntity positionEntity = this.positionRepository.findByName(position.getName()); if (positionEntity == null) { positionEntity = this.converterService.convert(position, PositionEntity.class); } else if (positionEntity.isDeleted() != null && positionEntity.isDeleted()) { positionEntity.setDeleted(false); } else { throw new DuplicatePositionException(position.getName()); } this.positionRepository.saveAndFlush(positionEntity); return positionEntity.getId(); }
PositionServiceImpl extends AbstractLogicallyDeletableService<PositionDTO, PositionEntity> implements PositionService { @Transactional @Override public Long saveOrUpdate(PositionDTO position) { Assert.notNull(position); Assert.notNull(position.getName()); PositionEntity positionEntity = this.positionRepository.findByName(position.getName()); if (positionEntity == null) { positionEntity = this.converterService.convert(position, PositionEntity.class); } else if (positionEntity.isDeleted() != null && positionEntity.isDeleted()) { positionEntity.setDeleted(false); } else { throw new DuplicatePositionException(position.getName()); } this.positionRepository.saveAndFlush(positionEntity); return positionEntity.getId(); } }
PositionServiceImpl extends AbstractLogicallyDeletableService<PositionDTO, PositionEntity> implements PositionService { @Transactional @Override public Long saveOrUpdate(PositionDTO position) { Assert.notNull(position); Assert.notNull(position.getName()); PositionEntity positionEntity = this.positionRepository.findByName(position.getName()); if (positionEntity == null) { positionEntity = this.converterService.convert(position, PositionEntity.class); } else if (positionEntity.isDeleted() != null && positionEntity.isDeleted()) { positionEntity.setDeleted(false); } else { throw new DuplicatePositionException(position.getName()); } this.positionRepository.saveAndFlush(positionEntity); return positionEntity.getId(); } @Autowired  PositionServiceImpl(PositionRepository positionRepository,
                             ConverterService converterService); }
PositionServiceImpl extends AbstractLogicallyDeletableService<PositionDTO, PositionEntity> implements PositionService { @Transactional @Override public Long saveOrUpdate(PositionDTO position) { Assert.notNull(position); Assert.notNull(position.getName()); PositionEntity positionEntity = this.positionRepository.findByName(position.getName()); if (positionEntity == null) { positionEntity = this.converterService.convert(position, PositionEntity.class); } else if (positionEntity.isDeleted() != null && positionEntity.isDeleted()) { positionEntity.setDeleted(false); } else { throw new DuplicatePositionException(position.getName()); } this.positionRepository.saveAndFlush(positionEntity); return positionEntity.getId(); } @Autowired  PositionServiceImpl(PositionRepository positionRepository,
                             ConverterService converterService); @Transactional(readOnly = true) @Override List<PositionDTO> getPositionsById(List<Long> ids); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoById(Long positionId); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoByName(String positionName); @Transactional @Override Long saveOrUpdate(PositionDTO position); }
PositionServiceImpl extends AbstractLogicallyDeletableService<PositionDTO, PositionEntity> implements PositionService { @Transactional @Override public Long saveOrUpdate(PositionDTO position) { Assert.notNull(position); Assert.notNull(position.getName()); PositionEntity positionEntity = this.positionRepository.findByName(position.getName()); if (positionEntity == null) { positionEntity = this.converterService.convert(position, PositionEntity.class); } else if (positionEntity.isDeleted() != null && positionEntity.isDeleted()) { positionEntity.setDeleted(false); } else { throw new DuplicatePositionException(position.getName()); } this.positionRepository.saveAndFlush(positionEntity); return positionEntity.getId(); } @Autowired  PositionServiceImpl(PositionRepository positionRepository,
                             ConverterService converterService); @Transactional(readOnly = true) @Override List<PositionDTO> getPositionsById(List<Long> ids); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoById(Long positionId); @Transactional(readOnly = true) @Override PositionDTO getPositionDtoByName(String positionName); @Transactional @Override Long saveOrUpdate(PositionDTO position);  }