Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public String importTowns(String townsFileContent) {
- StringBuilder output = new StringBuilder();
- TownJsonImportDto[] dto = this.gson.fromJson(townsFileContent, TownJsonImportDto[].class);
- for (TownJsonImportDto townJsonImportDto : dto) {
- if (!this.validationUtil.isValid(townJsonImportDto)) {
- output.append(Constants.INCORRECT_DATA_MESSAGE).append(System.lineSeparator());
- }
- if (this.townRepository.findByName(townJsonImportDto.getName()) != null) {
- output.append(Constants.DUPLICATE_DATA_MESSAGE).append(System.lineSeparator());
- }
- Town town = this.modelMapper.map(townJsonImportDto, Town.class);
- this.townRepository.saveAndFlush(town);
- output.append(String.format(Constants.SUCCESSFUL_IMPORT_MESSAGE, "Town", town.getName()))
- .append(System.lineSeparator());
- }
- return output.toString().trim();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement