Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. @Override
  2. public String importTowns(String townsFileContent) {
  3. StringBuilder output = new StringBuilder();
  4. TownJsonImportDto[] dto = this.gson.fromJson(townsFileContent, TownJsonImportDto[].class);
  5.  
  6. for (TownJsonImportDto townJsonImportDto : dto) {
  7. if (!this.validationUtil.isValid(townJsonImportDto)) {
  8. output.append(Constants.INCORRECT_DATA_MESSAGE).append(System.lineSeparator());
  9. }
  10. if (this.townRepository.findByName(townJsonImportDto.getName()) != null) {
  11. output.append(Constants.DUPLICATE_DATA_MESSAGE).append(System.lineSeparator());
  12. }
  13. Town town = this.modelMapper.map(townJsonImportDto, Town.class);
  14. this.townRepository.saveAndFlush(town);
  15. output.append(String.format(Constants.SUCCESSFUL_IMPORT_MESSAGE, "Town", town.getName()))
  16. .append(System.lineSeparator());
  17. }
  18. return output.toString().trim();
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement