Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add labels for notifications #149

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import com.sflpro.notifier.api.model.email.request.EmailNotificationFileAttachmentRequest;
import com.sflpro.notifier.api.model.email.response.CreateEmailNotificationResponse;
import com.sflpro.notifier.api.model.notification.NotificationClientType;
import com.sflpro.notifier.api.model.notification.NotificationLabelModel;
import com.sflpro.notifier.api.model.notification.NotificationStateClientType;
import com.sflpro.notifier.api.model.notification.request.NotificationLabelRequest;
import com.sflpro.notifier.db.entities.notification.NotificationLabel;
import com.sflpro.notifier.db.entities.notification.NotificationProviderType;
import com.sflpro.notifier.db.entities.notification.email.EmailNotification;
import com.sflpro.notifier.db.entities.notification.email.EmailNotificationFileAttachment;
Expand Down Expand Up @@ -72,9 +75,46 @@ private EmailNotificationDto buildDto(final CreateEmailNotificationRequest reque
emailNotificationDto.setUserUuid(request.getUserUuId());
emailNotificationDto.setHasSecureProperties(!request.getSecureProperties().isEmpty());
emailNotificationDto.setFileAttachments(mapFileAttachments(request.getFileAttachments()));
emailNotificationDto.setLabels(mapLabels(request.getLabels()));
return emailNotificationDto;
}

private EmailNotificationModel buildModel(final EmailNotification emailNotification) {
final EmailNotificationModel notificationModel = new EmailNotificationModel();
notificationModel.setUuId(emailNotification.getUuId());
notificationModel.setBody(emailNotification.getContent());
notificationModel.setSubject(emailNotification.getSubject());
notificationModel.setType(NotificationClientType.valueOf(emailNotification.getType().name()));
notificationModel.setState(NotificationStateClientType.valueOf(emailNotification.getState().name()));
notificationModel.setSenderEmail(emailNotification.getSenderEmail());
notificationModel.setRecipientEmail(emailNotification.getRecipientEmail());
notificationModel.setFileAttachments(mapFileAttachmentsModel(emailNotification.getFileAttachments()));
notificationModel.setLabels(mapLabelsModel(emailNotification.getLabels()));
return notificationModel;
}

private Set<NotificationLabel> mapLabels(final Set<NotificationLabelRequest> labelsResource) {
Set<NotificationLabel> destinationLabels = new HashSet<>();

for (NotificationLabelRequest label : labelsResource) {
NotificationLabel item = new NotificationLabel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}

private Set<NotificationLabelModel> mapLabelsModel(final Set<NotificationLabel> labelsResource){
Set<NotificationLabelModel> destinationLabels = new HashSet<>();

for (NotificationLabel label : labelsResource) {
NotificationLabelModel item = new NotificationLabelModel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}

private Set<EmailNotificationFileAttachment> mapFileAttachments(final Set<EmailNotificationFileAttachmentRequest> fileAttachmentResource) {
Set<EmailNotificationFileAttachment> destinationAttachments = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.sflpro.notifier.api.facade.services.push.PushNotificationServiceFacade;
import com.sflpro.notifier.api.model.common.result.ErrorResponseModel;
import com.sflpro.notifier.api.model.common.result.ResultResponseModel;
import com.sflpro.notifier.api.model.notification.NotificationLabelModel;
import com.sflpro.notifier.api.model.notification.request.NotificationLabelRequest;
import com.sflpro.notifier.api.model.push.PushNotificationModel;
import com.sflpro.notifier.api.model.push.PushNotificationRecipientModel;
import com.sflpro.notifier.api.model.push.request.CreatePushNotificationRequest;
Expand All @@ -12,6 +14,7 @@
import com.sflpro.notifier.api.model.push.response.UpdatePushNotificationSubscriptionResponse;
import com.sflpro.notifier.db.entities.device.UserDevice;
import com.sflpro.notifier.db.entities.device.mobile.DeviceOperatingSystemType;
import com.sflpro.notifier.db.entities.notification.NotificationLabel;
import com.sflpro.notifier.db.entities.notification.NotificationProviderType;
import com.sflpro.notifier.db.entities.notification.email.NotificationProperty;
import com.sflpro.notifier.db.entities.notification.push.PushNotification;
Expand All @@ -38,6 +41,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -95,6 +100,7 @@ public ResultResponseModel<CreatePushNotificationResponse> createPushNotificatio
pushNotificationDto.setTemplateName(request.getTemplateName());
pushNotificationDto.setLocale(request.getLocale());
pushNotificationDto.setProperties(request.getProperties());
pushNotificationDto.setLabels(mapLabels(request.getLabels()));
// Create push notifications
final List<PushNotification> pushNotifications = pushNotificationService.createNotificationsForUserActiveRecipients(user.getId(), pushNotificationDto);
// Publish events
Expand Down Expand Up @@ -139,6 +145,7 @@ private static PushNotificationModel createPushNotificationModel(final PushNotif
setNotificationCommonProperties(pushNotificationModel, pushNotification);
// Create recipient model
pushNotificationModel.setRecipient(createPushNotificationRecipientModel(pushNotification.getRecipient()));
pushNotificationModel.setLabels(mapLabelsModel(pushNotification.getLabels()));
// Set properties

final Map<String, String> propertyModels = pushNotification.getProperties().stream().collect(Collectors.toMap(NotificationProperty::getPropertyKey, NotificationProperty::getPropertyValue));
Expand All @@ -153,5 +160,27 @@ private static PushNotificationRecipientModel createPushNotificationRecipientMod
return recipientModel;
}

private Set<NotificationLabel> mapLabels(final Set<NotificationLabelRequest> labelsResource) {
Set<NotificationLabel> destinationLabels = new HashSet<>();

for (NotificationLabelRequest label : labelsResource) {
NotificationLabel item = new NotificationLabel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}

private static Set<NotificationLabelModel> mapLabelsModel(final Set<NotificationLabel> labelsResource){
Set<NotificationLabelModel> destinationLabels = new HashSet<>();

for (NotificationLabel label : labelsResource) {
NotificationLabelModel item = new NotificationLabelModel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.sflpro.notifier.api.facade.services.sms.SmsNotificationServiceFacade;
import com.sflpro.notifier.api.model.common.result.ErrorResponseModel;
import com.sflpro.notifier.api.model.common.result.ResultResponseModel;
import com.sflpro.notifier.api.model.notification.NotificationLabelModel;
import com.sflpro.notifier.api.model.notification.request.NotificationLabelRequest;
import com.sflpro.notifier.api.model.sms.SmsNotificationModel;
import com.sflpro.notifier.api.model.sms.request.CreateSmsNotificationRequest;
import com.sflpro.notifier.api.model.sms.response.CreateSmsNotificationResponse;
import com.sflpro.notifier.db.entities.notification.NotificationLabel;
import com.sflpro.notifier.db.entities.notification.NotificationProviderType;
import com.sflpro.notifier.db.entities.notification.sms.SmsNotification;
import com.sflpro.notifier.services.notification.dto.sms.SmsNotificationDto;
Expand All @@ -21,7 +24,9 @@
import org.springframework.util.Assert;

import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* User: Ruben Dilanyan
Expand Down Expand Up @@ -65,6 +70,7 @@ public ResultResponseModel<CreateSmsNotificationResponse> createSmsNotification(
smsNotificationDto.setProperties(request.getProperties());
smsNotificationDto.setHasSecureProperties(!request.getSecureProperties().isEmpty());
smsNotificationDto.setLocale(request.getLocale());
smsNotificationDto.setLabels(mapLabels(request.getLabels()));
final SmsNotification smsNotification = smsNotificationService.createSmsNotification(smsNotificationDto);
associateUserWithNotificationIfRequired(request.getUserUuId(), smsNotification);
// Publish event
Expand All @@ -82,6 +88,29 @@ private SmsNotificationModel createSmsNotificationModel(final SmsNotification sm
setNotificationCommonProperties(notificationModel, smsNotification);
notificationModel.setSubject(smsNotification.getSubject());
notificationModel.setRecipientNumber(smsNotification.getRecipientMobileNumber());
notificationModel.setLabels(mapLabelsModel(smsNotification.getLabels()));
return notificationModel;
}

private Set<NotificationLabel> mapLabels(final Set<NotificationLabelRequest> labelsResource) {
Set<NotificationLabel> destinationLabels = new HashSet<>();

for (NotificationLabelRequest label : labelsResource) {
NotificationLabel item = new NotificationLabel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}

private Set<NotificationLabelModel> mapLabelsModel(final Set<NotificationLabel> labelsResource){
Set<NotificationLabelModel> destinationLabels = new HashSet<>();

for (NotificationLabel label : labelsResource) {
NotificationLabelModel item = new NotificationLabelModel();
item.setLabelName(label.getLabelName());
destinationLabels.add(item);
}
return destinationLabels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.sflpro.notifier.api.model.notification;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

public class NotificationLabelModel {

/* Properties */
@JsonProperty("labelName")
private String labelName;

/* Constructors */
public NotificationLabelModel() {
}

/* Properties Getters and Setters */
public String getLabelName() {
return labelName;
}

public void setLabelName(String labelName) {
this.labelName = labelName;
}

/* Equals, HashCode and ToString */
@Override
public boolean equals(Object o) {
if (this == o) return true;

if (o == null || getClass() != o.getClass()) return false;

NotificationLabelModel that = (NotificationLabelModel) o;

return new EqualsBuilder()
.append(labelName, that.labelName)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(labelName)
.toHashCode();
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append("labelName", labelName)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Set;

/**
* User: Ruben Dilanyan
* Company: SFL LLC
Expand Down Expand Up @@ -47,6 +49,9 @@ public abstract class NotificationModel extends AbstractApiModel {
@JsonProperty("state")
private NotificationStateClientType state;

@JsonProperty("labels")
private Set<NotificationLabelModel> labels;

/* Constructors */
public NotificationModel() {
}
Expand Down Expand Up @@ -100,6 +105,14 @@ public void setState(final NotificationStateClientType state) {
this.state = state;
}

public Set<NotificationLabelModel> getLabels() {
return labels;
}

public void setLabels(Set<NotificationLabelModel> labels) {
this.labels = labels;
}

/* Equals, HashCode and ToString */
@Override
public boolean equals(final Object o) {
Expand All @@ -117,6 +130,7 @@ public boolean equals(final Object o) {
builder.append(this.getSubject(), that.getSubject());
builder.append(this.getType(), that.getType());
builder.append(this.getState(), that.getState());
builder.append(this.getLabels(), that.getLabels());
return builder.isEquals();
}

Expand All @@ -128,6 +142,8 @@ public int hashCode() {
builder.append(this.getBody());
builder.append(this.getSubject());
builder.append(this.getType());
builder.append(this.getState());
builder.append(this.getLabels());
return builder.build();
}

Expand All @@ -140,6 +156,7 @@ public String toString() {
builder.append("subject", this.getSubject());
builder.append("type", this.getType());
builder.append("state", this.getState());
builder.append("label", this.getLabels());
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public abstract class AbstractCreateNotificationRequest extends AbstractRequestM
@JsonProperty("clientIpAddress")
private String clientIpAddress;

@JsonProperty("labels")
private Set<NotificationLabelRequest> labels = Collections.emptySet();


/* Properties getters and setters */
public String getUserUuId() {
Expand All @@ -58,6 +61,14 @@ public void setClientIpAddress(final String clientIpAddress) {
this.clientIpAddress = clientIpAddress;
}

public Set<NotificationLabelRequest> getLabels() {
return labels;
}

public void setLabels(Set<NotificationLabelRequest> labels) {
this.labels = labels;
}

/* Validation methods */
@Nonnull
@Override
Expand All @@ -84,6 +95,7 @@ public boolean equals(final Object o) {
builder.append(this.getUserUuId(), that.getUserUuId());
builder.append(this.getBody(), that.getBody());
builder.append(this.getClientIpAddress(), that.getClientIpAddress());
builder.append(this.getLabels(), that.getLabels());
return builder.isEquals();
}

Expand All @@ -94,6 +106,7 @@ public int hashCode() {
builder.append(this.getUserUuId());
builder.append(this.getBody());
builder.append(this.getClientIpAddress());
builder.append(this.getLabels());
return builder.build();
}

Expand All @@ -104,6 +117,7 @@ public String toString() {
builder.append("userUuId", this.getUserUuId());
builder.append("body", this.getBody());
builder.append("clientIpAddress", this.getClientIpAddress());
builder.append("labels", this.getLabels());
return builder.build();
}
}
Loading