Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikron committed Jun 14, 2022
2 parents 713e382 + a513a21 commit 0b62c9c
Show file tree
Hide file tree
Showing 42 changed files with 279 additions and 73 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/sflpro/notifier.svg?branch=master)](https://travis-ci.org/sflpro/notifier)
[![Build Status](https://app.travis-ci.com/sflpro/notifier.svg?branch=master)](https://app.travis-ci.com/sflpro/notifier)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=com.sflpro.notifier%3Anotifier&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.sflpro.notifier%3Anotifier)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.sflpro.notifier/notifier/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.sflpro.notifier/notifier/)
[![License: APACHE](https://img.shields.io/badge/license-Apache%20License%202.0-b)](https://opensource.org/licenses/Apache-2.0)
Expand Down Expand Up @@ -36,7 +36,7 @@ following maven dependency:
<dependency>
<groupId>com.sflpro.notifier</groupId>
<artifactId>api-client-library</artifactId>
<version>1.7.0</version>
<version>1.10.1</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions api/api-client-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>api</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<artifactId>api-client-library</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
<packaging>jar</packaging>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions api/api-facade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<artifactId>api</artifactId>
<groupId>com.sflpro.notifier</groupId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<artifactId>api-facade</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
<packaging>jar</packaging>

<description>Project is representing facade layer for outgoing gateway of SFL NMS Internal API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sflpro.notifier.services.device.UserDeviceService;
import com.sflpro.notifier.services.device.dto.UserDeviceDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationRecipientsParameters;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationSubscriptionRequestDto;
import com.sflpro.notifier.services.notification.event.push.StartPushNotificationSubscriptionRequestProcessingEvent;
import com.sflpro.notifier.services.notification.event.sms.StartSendingNotificationEvent;
Expand Down Expand Up @@ -99,7 +100,9 @@ public ResultResponseModel<CreatePushNotificationResponse> createPushNotificatio
pushNotificationDto.setProperties(request.getProperties());
pushNotificationDto.setSendingPriority(NotificationSendingPriority.valueOf(request.getSendingPriority().name()));
// Create push notifications
final List<PushNotification> pushNotifications = pushNotificationService.createNotificationsForUserActiveRecipients(user.getId(), pushNotificationDto);
final List<PushNotification> pushNotifications = pushNotificationService.createNotificationsForRecipients(
new PushNotificationRecipientsParameters(user.getId(), request.getDeviceUuId()), pushNotificationDto
);
// Publish events
pushNotifications.forEach(pushNotification -> applicationEventDistributionService.publishAsynchronousEvent(new StartSendingNotificationEvent(pushNotification.getId(), Collections.emptyMap(), pushNotification.getSendingPriority())));
// Convert to notification models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.sflpro.notifier.services.device.UserDeviceService;
import com.sflpro.notifier.services.device.dto.UserDeviceDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationRecipientsParameters;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationSubscriptionRequestDto;
import com.sflpro.notifier.services.notification.event.push.StartPushNotificationSubscriptionRequestProcessingEvent;
import com.sflpro.notifier.services.notification.event.sms.StartSendingNotificationEvent;
Expand Down Expand Up @@ -206,7 +207,7 @@ public void testCreatePushNotifications() {
resetAll();
// Expectations
expect(userService.getOrCreateUserForUuId(eq(user.getUuId()))).andReturn(user).once();
expect(pushNotificationService.createNotificationsForUserActiveRecipients(eq(user.getId()), eq(pushNotificationDto))).andReturn(pushNotifications).once();
expect(pushNotificationService.createNotificationsForRecipients(eq(new PushNotificationRecipientsParameters(user.getId())), eq(pushNotificationDto))).andReturn(pushNotifications).once();
pushNotifications.forEach(pushNotification -> {
applicationEventDistributionService.publishAsynchronousEvent(eq(new StartSendingNotificationEvent(pushNotification.getId())));
expectLastCall().once();
Expand Down
4 changes: 2 additions & 2 deletions api/api-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>api</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<artifactId>api-model</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
<packaging>jar</packaging>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class CreatePushNotificationRequest extends AbstractTemplatedCreateNotifi
@JsonProperty("subject")
private String subject;

@JsonProperty("deviceUuId")
private String deviceUuId;

public CreatePushNotificationRequest() {
}

Expand All @@ -36,6 +39,14 @@ public void setSubject(final String subject) {
this.subject = subject;
}

public String getDeviceUuId() {
return deviceUuId;
}

public void setDeviceUuId(final String deviceUuId) {
this.deviceUuId = deviceUuId;
}

@Nonnull
@Override
public List<ErrorResponseModel> validateRequiredFields() {
Expand All @@ -61,6 +72,7 @@ public boolean equals(Object obj) {
return new EqualsBuilder()
.appendSuper(super.equals(obj))
.append(this.subject, rhs.subject)
.append(this.deviceUuId, rhs.deviceUuId)
.isEquals();
}

Expand All @@ -69,6 +81,7 @@ public int hashCode() {
return new HashCodeBuilder()
.appendSuper(super.hashCode())
.append(subject)
.append(deviceUuId)
.toHashCode();
}

Expand All @@ -77,6 +90,7 @@ public String toString() {
return new ToStringBuilder(this)
.appendSuper(super.toString())
.append("subject", subject)
.append("deviceUuId", deviceUuId)
.toString();
}
}
4 changes: 2 additions & 2 deletions api/api-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>api</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<packaging>jar</packaging>
<artifactId>api-web</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>

<description>Project is representing Internal Rest API service for SFL Notifier</description>

Expand Down
4 changes: 2 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>notifier</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<packaging>pom</packaging>
<artifactId>api</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>

<description>Project acts as a root API grouping project</description>

Expand Down
2 changes: 1 addition & 1 deletion core/core-db-entities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>core</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion core/core-db-repositories/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>core</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<artifactId>core-db-repositories</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class PushNotificationRecipientSearchFilter {

private String applicationType;

private String deviceUuId;

/* Constructors */
public PushNotificationRecipientSearchFilter() {
super();
Expand Down Expand Up @@ -87,6 +89,15 @@ public PushNotificationRecipientSearchFilter setApplicationType(final String app
return this;
}

public String getDeviceUuId() {
return deviceUuId;
}

public PushNotificationRecipientSearchFilter setDeviceUuId(final String deviceUuId) {
this.deviceUuId = deviceUuId;
return this;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -102,6 +113,7 @@ public boolean equals(Object o) {
.append(providerType, that.providerType)
.append(deviceOperatingSystemType, that.deviceOperatingSystemType)
.append(applicationType, that.applicationType)
.append(deviceUuId, that.deviceUuId)
.isEquals();
}

Expand All @@ -114,6 +126,7 @@ public int hashCode() {
.append(providerType)
.append(deviceOperatingSystemType)
.append(applicationType)
.append(deviceUuId)
.toHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class PushNotificationRecipientRepositoryImpl implements PushNotification

private static final String PARAMETER_NAME_APPLICATION_TYPE = "applicationType";

private static final String PARAMETER_NAME_DEVICE_UUID = "deviceUuId";

/* Dependencies */
@PersistenceContext
private EntityManager entityManager;
Expand Down Expand Up @@ -91,6 +93,7 @@ private <T> TypedQuery<T> buildFindRecipientsForSearchParametersTypedQuery(final
typedQuery.setParameter(PARAMETER_NAME_DESTINATION_ROUTE_TOKEN, parameters.getDestinationRouteToken());
typedQuery.setParameter(PARAMETER_NAME_STATUS, parameters.getStatus());
typedQuery.setParameter(PARAMETER_NAME_APPLICATION_TYPE, parameters.getApplicationType());
typedQuery.setParameter(PARAMETER_NAME_DEVICE_UUID, parameters.getDeviceUuId());
return typedQuery;
}

Expand All @@ -103,13 +106,15 @@ private String buildFindRecipientsForSearchParametersQueryString(final boolean c
queryBuilder.append(" select pnr ");
}
queryBuilder.append(" from PushNotificationRecipient pnr ");
queryBuilder.append(" left join UserDevice ud on ud.id = pnr.lastDevice.id");
queryBuilder.append(" where ");
queryBuilder.append("( :" + PARAMETER_NAME_DESTINATION_ROUTE_TOKEN + " is null or pnr.destinationRouteToken=:" + PARAMETER_NAME_DESTINATION_ROUTE_TOKEN + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_STATUS + " is null or pnr.status=:" + PARAMETER_NAME_STATUS + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_DEVICE_OPERATING_SYSTEM + " is null or pnr.deviceOperatingSystemType=:" + PARAMETER_NAME_DEVICE_OPERATING_SYSTEM + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_PROVIDER_TYPE + " is null or pnr.type=:" + PARAMETER_NAME_PROVIDER_TYPE + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_APPLICATION_TYPE + " is null or pnr.applicationType=:" + PARAMETER_NAME_APPLICATION_TYPE + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_SUBSCRIPTION_ID + " is null or pnr.subscription.id=:" + PARAMETER_NAME_SUBSCRIPTION_ID + ") ");
queryBuilder.append(" and ( :" + PARAMETER_NAME_DEVICE_UUID + " is null or ud.uuId=:" + PARAMETER_NAME_DEVICE_UUID + ") ");
// Append order by query
if (!countQuery) {
queryBuilder.append(" order by pnr.id asc ");
Expand Down
4 changes: 2 additions & 2 deletions core/core-services-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>com.sflpro.notifier</groupId>
<artifactId>core</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
</parent>

<packaging>jar</packaging>

<artifactId>core-services-impl</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>

<description>Services implementation sub module represents implementation of services layer for Future project.</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private PushNotificationRecipientSearchFilter convertParametersToFilter(PushNoti
filter.setProviderType(parameters.getProviderType());
filter.setStatus(parameters.getStatus());
filter.setSubscriptionId(parameters.getSubscriptionId());
filter.setDeviceUuId(parameters.getDeviceUuId());
return filter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sflpro.notifier.services.notification.UserNotificationService;
import com.sflpro.notifier.services.notification.dto.UserNotificationDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationDto;
import com.sflpro.notifier.services.notification.dto.push.PushNotificationRecipientsParameters;
import com.sflpro.notifier.services.notification.impl.AbstractNotificationServiceImpl;
import com.sflpro.notifier.services.notification.push.PushNotificationRecipientSearchParameters;
import com.sflpro.notifier.services.notification.push.PushNotificationRecipientService;
Expand Down Expand Up @@ -97,24 +98,25 @@ public PushNotification createNotification(@Nonnull final Long pushNotificationR
@Transactional
@Nonnull
@Override
public List<PushNotification> createNotificationsForUserActiveRecipients(@Nonnull final Long userId, @Nonnull final PushNotificationDto pushNotificationDto) {
Assert.notNull(userId, "User id should not be null");
public List<PushNotification> createNotificationsForRecipients(@Nonnull final PushNotificationRecipientsParameters recipientsParameters, @Nonnull final PushNotificationDto pushNotificationDto) {
Assert.notNull(recipientsParameters, "Recipients parameters should not be null");
Assert.notNull(recipientsParameters.getUserId(), "User id should not be null");
assertPushNotificationDto(pushNotificationDto);
logger.debug("Creating push notifications for all active recipients of user with id - {}, push notification DTO - {}", userId, pushNotificationDto);
logger.debug("Creating push notifications for recipients with parameters - {}, push notification DTO - {}", recipientsParameters, pushNotificationDto);
// Grab user and check if subscription exists
final User user = userService.getUserById(userId);
final User user = userService.getUserById(recipientsParameters.getUserId());
// Check if subscription exists for users
final boolean subscriptionExists = pushNotificationSubscriptionService.checkIfPushNotificationSubscriptionExistsForUser(user.getId());
if (!subscriptionExists) {
logger.debug("No push notification subscription exists for user with id - {}, do not create any notifications", user.getId());
return Collections.emptyList();
}
// Grab subscription and search for recipients
final PushNotificationSubscription subscription = pushNotificationSubscriptionService.getPushNotificationSubscriptionForUser(userId);
final List<PushNotificationRecipient> recipients = getPushNotificationActiveRecipientsForSubscription(subscription);
final PushNotificationSubscription subscription = pushNotificationSubscriptionService.getPushNotificationSubscriptionForUser(recipientsParameters.getUserId());
final List<PushNotificationRecipient> recipients = getPushNotificationRecipientsForSubscription(subscription, recipientsParameters);
// Create push notifications
final List<PushNotification> pushNotifications = createPushNotificationsForRecipients(recipients, user, pushNotificationDto);
logger.debug("{} push notifications were created for user with id - {}, push notification DTO - {}", pushNotifications.size(), userId, pushNotificationDto);
logger.debug("{} push notifications were created for recipients - {}, push notification DTO - {}", pushNotifications.size(), recipientsParameters, pushNotificationDto);
return pushNotifications;
}

Expand All @@ -139,10 +141,11 @@ private List<PushNotification> createPushNotificationsForRecipients(final List<P
return pushNotifications;
}

private List<PushNotificationRecipient> getPushNotificationActiveRecipientsForSubscription(final PushNotificationSubscription subscription) {
private List<PushNotificationRecipient> getPushNotificationRecipientsForSubscription(final PushNotificationSubscription subscription, final PushNotificationRecipientsParameters recipientsParameters) {
// Build search parameters
final PushNotificationRecipientSearchParameters searchParameters = new PushNotificationRecipientSearchParameters();
searchParameters.setSubscriptionId(subscription.getId());
searchParameters.setDeviceUuId(recipientsParameters.getDeviceUuId());
searchParameters.setStatus(PushNotificationRecipientStatus.ENABLED);
// Execute search
final List<PushNotificationRecipient> recipients = pushNotificationRecipientService.getPushNotificationRecipientsForSearchParameters(searchParameters, 0L, Integer.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -271,6 +272,7 @@ private PushNotificationRecipientSearchParameters createPushNotificationRecipien
parameters.setDestinationRouteToken("GGFTF%*^D(RD*RDFXR58drS&D*");
parameters.setProviderType(PushNotificationProviderType.SNS);
parameters.setSubscriptionId(1L);
parameters.setDeviceUuId(UUID.randomUUID().toString());
return parameters;
}

Expand All @@ -281,6 +283,7 @@ private PushNotificationRecipientSearchFilter createPushNotificationRecipientSea
filter.setDestinationRouteToken(parameters.getDestinationRouteToken());
filter.setProviderType(parameters.getProviderType());
filter.setSubscriptionId(parameters.getSubscriptionId());
filter.setDeviceUuId(parameters.getDeviceUuId());
return filter;
}

Expand Down
Loading

0 comments on commit 0b62c9c

Please sign in to comment.