diff --git a/src/main/java/net/geant/nmaas/notifications/MailAttributes.java b/src/main/java/net/geant/nmaas/notifications/MailAttributes.java index f1b75485d408c9176f40947ec008639750c35fa7..c4bb34d20a870f9cc54e119051f78800d766a287 100644 --- a/src/main/java/net/geant/nmaas/notifications/MailAttributes.java +++ b/src/main/java/net/geant/nmaas/notifications/MailAttributes.java @@ -24,11 +24,11 @@ public class MailAttributes implements Serializable { private MailType mailType; @Builder.Default - private Map<String, String> otherAttributes = new HashMap<>(); + private Map<String, Object> otherAttributes = new HashMap<>(); @Builder @SuppressWarnings("unused") - private MailAttributes(List<UserView> addressees, MailType mailType, Map<String, String> otherAttributes){ + private MailAttributes(List<UserView> addressees, MailType mailType, Map<String, Object> otherAttributes){ this.addressees = addressees; this.mailType = mailType; this.otherAttributes = Optional.ofNullable(otherAttributes).orElse(this.otherAttributes); diff --git a/src/main/java/net/geant/nmaas/notifications/NotificationManager.java b/src/main/java/net/geant/nmaas/notifications/NotificationManager.java index e90dbe1ecc16faaa02a03474038ee21db857d584..08237b437663e5036971776a92129edc27e395ef 100644 --- a/src/main/java/net/geant/nmaas/notifications/NotificationManager.java +++ b/src/main/java/net/geant/nmaas/notifications/NotificationManager.java @@ -142,9 +142,9 @@ public class NotificationManager { mailAttributes.setAddressees(userService.findAllUsersWithAdminRole()); } if (mailAttributes.getMailType().equals(MailType.APP_DEPLOYED)) { - mailAttributes.setAddressees(domainService.findUsersWithDomainAdminRole(mailAttributes.getOtherAttributes().get("domainName"))); + mailAttributes.setAddressees(domainService.findUsersWithDomainAdminRole((String)mailAttributes.getOtherAttributes().get("domainName"))); if (mailAttributes.getAddressees().stream().noneMatch(user -> user.getUsername().equals(mailAttributes.getOtherAttributes().get("owner")))) { - userService.findByUsername(mailAttributes.getOtherAttributes().get("owner")) + userService.findByUsername((String)mailAttributes.getOtherAttributes().get("owner")) .ifPresent(user -> mailAttributes.getAddressees().add(modelMapper.map(user, UserView.class))); } } @@ -156,7 +156,7 @@ public class NotificationManager { } if (Arrays.asList(MailType.CONTACT_FORM, MailType.ISSUE_REPORT, MailType.NEW_DOMAIN_REQUEST).contains(mailAttributes.getMailType())) { List<UserView> base = userService.findAllUsersWithAdminRole(); - Optional<String> contactFormKey = Optional.ofNullable(mailAttributes.getOtherAttributes().get("subType")); + Optional<String> contactFormKey = Optional.ofNullable((String)mailAttributes.getOtherAttributes().get("subType")); if (!contactFormKey.isPresent()) { log.error("Invalid contact form request, subType is null"); } else { @@ -188,10 +188,10 @@ public class NotificationManager { */ private void customizeMessage(LanguageMailContentView mailContent, MailAttributes mailAttributes) { if (mailAttributes.getMailType().equals(MailType.BROADCAST)) { - mailContent.setSubject(mailAttributes.getOtherAttributes().getOrDefault(MailTemplateElements.TITLE, "NMAAS: Broadcast message")); //set subject from other params + mailContent.setSubject((String)mailAttributes.getOtherAttributes().getOrDefault(MailTemplateElements.TITLE, "NMAAS: Broadcast message")); //set subject from other params } if (mailAttributes.getMailType().equals(MailType.CONTACT_FORM)) { - Optional<String> contactFormKey = Optional.ofNullable(mailAttributes.getOtherAttributes().get("subType")); + Optional<String> contactFormKey = Optional.ofNullable((String)mailAttributes.getOtherAttributes().get("subType")); Optional<FormType> formType = this.formTypeService.findOne( contactFormKey.orElseThrow(() -> new ProcessingException("Contact form subType not found")) ); @@ -221,7 +221,7 @@ public class NotificationManager { ImmutableMap.of("username", user.getFirstname() == null || user.getFirstname().isEmpty() ? user.getUsername() : user.getFirstname())); } - private String getContent(String content, Map<String, String> otherAttributes) throws IOException, TemplateException { + private String getContent(String content, Map<String, Object> otherAttributes) throws IOException, TemplateException { return FreeMarkerTemplateUtils.processTemplateIntoString( new Template( MailTemplateElements.CONTENT, diff --git a/src/main/java/net/geant/nmaas/portal/api/market/UsersController.java b/src/main/java/net/geant/nmaas/portal/api/market/UsersController.java index fae315f468dbbde452a45239d591760119a6545f..6b670618092ba900ac01b853f1c22c15d995c088 100644 --- a/src/main/java/net/geant/nmaas/portal/api/market/UsersController.java +++ b/src/main/java/net/geant/nmaas/portal/api/market/UsersController.java @@ -635,7 +635,7 @@ public class UsersController { return requestRoleList.containsAll(userRoleList) && userRoleList.containsAll(requestRoleList); } - private void sendMail(UserView user, MailType mailType, Map<String, String> other) { + private void sendMail(UserView user, MailType mailType, Map<String, Object> other) { MailAttributes mailAttributes = MailAttributes.builder() .mailType(mailType) .otherAttributes(other) diff --git a/src/test/java/net/geant/nmaas/notifications/NotificationManagerTest.java b/src/test/java/net/geant/nmaas/notifications/NotificationManagerTest.java index 87fb4dcef46c48997407c52069fb6646c735e4fd..c78ec5eba9c99cf8386d9bdbee92bb5876038713 100644 --- a/src/test/java/net/geant/nmaas/notifications/NotificationManagerTest.java +++ b/src/test/java/net/geant/nmaas/notifications/NotificationManagerTest.java @@ -122,7 +122,7 @@ public class NotificationManagerTest { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.BROADCAST); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "some text"); put(MailTemplateElements.TITLE, "Some Title"); put("username", "MyUser"); @@ -140,7 +140,7 @@ public class NotificationManagerTest { public void shouldSendHealthCheckEmail() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.EXTERNAL_SERVICE_HEALTH_CHECK); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); }}); @@ -156,7 +156,7 @@ public class NotificationManagerTest { public void shouldSendAppDeployedEmailToAdminWhenOwnerIsAdmin() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.APP_DEPLOYED); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); put("owner", "admin"); @@ -173,7 +173,7 @@ public class NotificationManagerTest { public void shouldSendAppDeployedEmailToAdminAndOrdinaryWhenOwnerIsOrdinary() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.APP_DEPLOYED); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); put("owner", "ordinary"); @@ -192,7 +192,7 @@ public class NotificationManagerTest { public void shouldThrowExceptionWhenCannotFindTemplateWithMatchingLanguage() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.REGISTRATION); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); }}); @@ -210,7 +210,7 @@ public class NotificationManagerTest { public void shouldSendContactForm() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.CONTACT_FORM); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("subType", "CONTACT"); }}); @@ -235,7 +235,7 @@ public class NotificationManagerTest { public void shouldSendAppDeploymentFailedEmail() { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.APP_DEPLOYMENT_FAILED); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); put("owner", "ordinary"); @@ -265,7 +265,7 @@ public class NotificationManagerTest { public void shouldThrowExceptionWhenTemplateServiceThrowsException() throws IOException { MailAttributes ma = new MailAttributes(); ma.setMailType(MailType.APP_DEPLOYED); - ma.setOtherAttributes(new HashMap<String, String>() {{ + ma.setOtherAttributes(new HashMap<String, Object>() {{ put("text", "text"); put("username", "MyUser"); put("owner", "ordinary");