Skip to content
Snippets Groups Projects
Commit 2ac49ec6 authored by Lukasz Lopatowski's avatar Lukasz Lopatowski
Browse files

NMAAS-999: Dealing with more complex user data comming from the contact form (lists)

parent 08af4f3b
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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,
......
......@@ -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)
......
......@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment