diff --git a/powerauth-push-model/src/main/java/io/getlime/push/model/request/UpdateDeviceStatusRequest.java b/powerauth-push-model/src/main/java/io/getlime/push/model/request/UpdateDeviceStatusRequest.java index 383fcbc2..15ed09b0 100644 --- a/powerauth-push-model/src/main/java/io/getlime/push/model/request/UpdateDeviceStatusRequest.java +++ b/powerauth-push-model/src/main/java/io/getlime/push/model/request/UpdateDeviceStatusRequest.java @@ -20,8 +20,7 @@ import com.wultra.security.powerauth.client.model.enumeration.ActivationStatus; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; -import lombok.Getter; -import lombok.Setter; +import lombok.*; /** * Class representing request object responsible for updating activation status. @@ -30,6 +29,9 @@ */ @Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode public class UpdateDeviceStatusRequest { /** diff --git a/powerauth-push-server/src/main/java/io/getlime/push/service/DeviceRegistrationService.java b/powerauth-push-server/src/main/java/io/getlime/push/service/DeviceRegistrationService.java index 52317dea..8c588e76 100644 --- a/powerauth-push-server/src/main/java/io/getlime/push/service/DeviceRegistrationService.java +++ b/powerauth-push-server/src/main/java/io/getlime/push/service/DeviceRegistrationService.java @@ -75,7 +75,7 @@ public void createOrUpdateDevice(final CreateDeviceRequest requestObject, final logger.info("Creating new device registration: app ID: {}, activation ID: {}, platform: {}", requestObject.getAppId(), requestObject.getActivationId(), platform); device = initDeviceRegistrationEntity(appCredentials, pushToken); } else { - // An existing row was found by one of the lookup methods, update this row. This means that either: + // An existing row was found by one of the lookup methods. This means that either: // 1. A row with same activation ID and push token is updated, in this case only the last registration timestamp changes. // 2. A row with same activation ID but different push token is updated. A new push token has been issued by Google or Apple for an activation. // 3. A row with different activation ID but same push token is created. The user removed an activation and created a new one, the push token remains the same, @@ -89,6 +89,10 @@ public void createOrUpdateDevice(final CreateDeviceRequest requestObject, final logger.info("Creating new device registration for a new activation: app ID: {}, activation ID: {}, platform: {}", requestObject.getAppId(), requestObject.getActivationId(), platform); // Create a new registration record for a new activation ID device = initDeviceRegistrationEntity(appCredentials, pushToken); + // Make sure that status of existing device registrations is updated in case of a deleted activation + for (PushDeviceRegistrationEntity deviceRegistration: devices) { + updateStatus(deviceRegistration.getActivationId(), null); + } } } device.setTimestampLastRegistered(new Date()); @@ -152,12 +156,10 @@ public void createOrUpdateDevices(final CreateDeviceForActivationsRequest reques } @Transactional - public void updateStatus(final UpdateDeviceStatusRequest request) throws PushServerException { - final String activationId = request.getActivationId(); - + public void updateStatus(final String activationId, final ActivationStatus status) throws PushServerException { final List device = pushDeviceRepository.findByActivationId(activationId); - final ActivationStatus activationStatus = request.getActivationStatus() == null ? fetchActivationStatus(activationId) : request.getActivationStatus(); + final ActivationStatus activationStatus = status == null ? fetchActivationStatus(activationId) : status; for (PushDeviceRegistrationEntity registration : device) { registration.setActive(activationStatus == ActivationStatus.ACTIVE); diff --git a/powerauth-push-server/src/main/java/io/getlime/push/service/PushDeviceService.java b/powerauth-push-server/src/main/java/io/getlime/push/service/PushDeviceService.java index 3a8da31c..5c9c8fd6 100644 --- a/powerauth-push-server/src/main/java/io/getlime/push/service/PushDeviceService.java +++ b/powerauth-push-server/src/main/java/io/getlime/push/service/PushDeviceService.java @@ -99,7 +99,7 @@ public Response updateDeviceStatus(final UpdateDeviceStatusRequest request) thro throw new PushServerException(errorMessage); } - deviceRegistrationService.updateStatus(request); + deviceRegistrationService.updateStatus(request.getActivationId(), request.getActivationStatus()); logger.info("The updateDeviceStatus request succeeded, activation ID: {}", request.getActivationId()); return new Response(); } diff --git a/powerauth-push-server/src/test/java/io/getlime/push/service/DeviceRegistrationServiceTest.java b/powerauth-push-server/src/test/java/io/getlime/push/service/DeviceRegistrationServiceTest.java index 408700b8..6291e967 100644 --- a/powerauth-push-server/src/test/java/io/getlime/push/service/DeviceRegistrationServiceTest.java +++ b/powerauth-push-server/src/test/java/io/getlime/push/service/DeviceRegistrationServiceTest.java @@ -215,7 +215,7 @@ void testUpdateStatus_statusInRequest() throws Exception { request.setActivationId("a1"); request.setActivationStatus(ActivationStatus.ACTIVE); - tested.updateStatus(request); + tested.updateStatus(request.getActivationId(), request.getActivationStatus()); final List entities2 = deviceRepository.findByActivationId("a1"); assertEquals(1, entities2.size()); @@ -243,7 +243,7 @@ void testUpdateStatus_missingStatusInRequest() throws Exception { final UpdateDeviceStatusRequest request = new UpdateDeviceStatusRequest(); request.setActivationId("a1"); - tested.updateStatus(request); + tested.updateStatus(request.getActivationId(), request.getActivationStatus()); verify(powerAuthClient).getActivationStatus("a1"); final List entities2 = deviceRepository.findByActivationId("a1");