| | |
| | | import org.stringtemplate.v4.ST; |
| | | import org.stringtemplate.v4.STRawGroupDir; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | if (!CollectionUtils.isEmpty(matchingNotificationCriteria)) { |
| | | final Map<String, Email> templatesToEmail = matchingNotificationCriteria.stream() |
| | | .collect(Collectors.toMap(AnimalNotificationRequestCriteria::getEmail, criteria -> new Email(renderTemplate(criteria, animal), NOTIFICATION_REQUEST_SUBJECT))); |
| | | final ResponseEntity<ResponseEntity> response = restTemplate.postForEntity(notificationServiceUrl + "/notifications/sendEmails", templatesToEmail, ResponseEntity.class); |
| | | final ResponseEntity response = restTemplate.postForEntity(notificationServiceUrl + "/notifications/sendEmails", templatesToEmail, ResponseEntity.class); |
| | | if (HttpStatus.OK.equals(response.getStatusCode())) { |
| | | animalNotificationSubscriptionRepository.deleteAll(matchingNotificationCriteria); |
| | | } else { |
| | | // retry |
| | | } |
| | | |
| | | } |
| | |
| | | throw new ResponseStatusException(HttpStatus.NOT_FOUND, "animal not found for animal ID " + animalId); |
| | | } |
| | | return animal.get(); |
| | | } |
| | | |
| | | public List<String> createAnimalsBulk(List<Animal> animals, String shelterId) { |
| | | final List<String> animalIds = new ArrayList<>(); |
| | | for (Animal animal : animals) { |
| | | animal.setShelterId(shelterId); |
| | | animalIds.add(createAnimal(animal)); |
| | | } |
| | | return animalIds; |
| | | } |
| | | |
| | | public void createNotificationSubscription(AnimalNotificationRequestCriteria criteria) { |
| | |
| | | final ResponseEntity response = restTemplate.postForEntity(notificationServiceUrl + "/notifications/sendEmails", new EmailNotificationRequest(notificationRequest), ResponseEntity.class); |
| | | if (HttpStatus.OK.equals(response.getStatusCode())) { |
| | | animalNotificationSubscriptionRepository.delete(criteria); |
| | | } else { |
| | | // retry |
| | | } |
| | | } |
| | | |