From 940ff23751660da8cd17d508b961f311b5f52ce3 Mon Sep 17 00:00:00 2001 From: Warren Bailey Date: Thu, 7 Jan 2021 17:11:18 +0000 Subject: [PATCH] Enable call to new action service (#229) * Enable call to new action service * update chart version * Fixing action event call Co-authored-by: Amit Sinha --- _infra/helm/collection-exercise/Chart.yaml | 3 +- .../exercise/client/ActionSvcClient.java | 9 +++--- .../lib/action/representation/Event.java | 31 +++++++++++++++++++ .../representation/ProcessEventDTO.java | 15 --------- .../exercise/service/EventService.java | 7 +++-- .../exercise/service/EventServiceTest.java | 2 +- 6 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 src/main/java/uk/gov/ons/ctp/response/collection/exercise/lib/action/representation/Event.java delete mode 100644 src/main/java/uk/gov/ons/ctp/response/collection/exercise/representation/ProcessEventDTO.java diff --git a/_infra/helm/collection-exercise/Chart.yaml b/_infra/helm/collection-exercise/Chart.yaml index 457610836..277fcca81 100644 --- a/_infra/helm/collection-exercise/Chart.yaml +++ b/_infra/helm/collection-exercise/Chart.yaml @@ -18,5 +18,6 @@ version: 1.2.2 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. -appVersion: 11.0.35 +appVersion: 11.0.36 + diff --git a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/client/ActionSvcClient.java b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/client/ActionSvcClient.java index e91e3e112..c9ca1f917 100644 --- a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/client/ActionSvcClient.java +++ b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/client/ActionSvcClient.java @@ -25,7 +25,6 @@ import uk.gov.ons.ctp.response.collection.exercise.lib.common.error.CTPException; import uk.gov.ons.ctp.response.collection.exercise.lib.common.error.CTPException.Fault; import uk.gov.ons.ctp.response.collection.exercise.lib.common.rest.RestUtility; -import uk.gov.ons.ctp.response.collection.exercise.representation.ProcessEventDTO; /** HTTP RestClient implementation for calls to the Action service. */ @Component @@ -304,10 +303,10 @@ public boolean processEvent(final String tag, final UUID collectionExerciseId) final UriComponents uriComponents = restUtility.createUriComponents(appConfig.getActionSvc().getProcessEventPath(), null); - final ProcessEventDTO processEventDTO = new ProcessEventDTO(); - processEventDTO.setTag(tag); - processEventDTO.setCollectionExerciseId(collectionExerciseId); - final HttpEntity httpEntity = restUtility.createHttpEntity(processEventDTO); + final Event event = new Event(); + event.setCollectionExerciseID(collectionExerciseId); + event.setTag(Event.EventTag.valueOf(tag)); + final HttpEntity httpEntity = restUtility.createHttpEntity(event); final ResponseEntity response = restTemplate.postForEntity(uriComponents.toUri(), httpEntity, String.class); return response.getStatusCode().is2xxSuccessful(); diff --git a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/lib/action/representation/Event.java b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/lib/action/representation/Event.java new file mode 100644 index 000000000..16ee0ee2f --- /dev/null +++ b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/lib/action/representation/Event.java @@ -0,0 +1,31 @@ +package uk.gov.ons.ctp.response.collection.exercise.lib.action.representation; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import java.util.UUID; +import javax.validation.constraints.NotNull; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PUBLIC) +@JsonIgnoreProperties(ignoreUnknown = true) +public class Event { + public enum EventTag { + mps, + go_live, + reminder, + reminder2, + reminder3, + nudge_email_0, + nudge_email_1, + nudge_email_2, + nudge_email_3, + nudge_email_4 + } + + @NotNull private UUID collectionExerciseID; + @NotNull private EventTag tag; +} diff --git a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/representation/ProcessEventDTO.java b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/representation/ProcessEventDTO.java deleted file mode 100644 index 725a3be9c..000000000 --- a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/representation/ProcessEventDTO.java +++ /dev/null @@ -1,15 +0,0 @@ -package uk.gov.ons.ctp.response.collection.exercise.representation; - -import java.util.UUID; -import lombok.AccessLevel; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** Process event payload JSON representation. */ -@Data -@NoArgsConstructor(access = AccessLevel.PUBLIC) -public class ProcessEventDTO { - - private String tag; - private UUID collectionExerciseId; -} diff --git a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/service/EventService.java b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/service/EventService.java index 76b70a439..61135bb84 100644 --- a/src/main/java/uk/gov/ons/ctp/response/collection/exercise/service/EventService.java +++ b/src/main/java/uk/gov/ons/ctp/response/collection/exercise/service/EventService.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; +import uk.gov.ons.ctp.response.collection.exercise.client.ActionSvcClient; import uk.gov.ons.ctp.response.collection.exercise.config.AppConfig; import uk.gov.ons.ctp.response.collection.exercise.domain.CollectionExercise; import uk.gov.ons.ctp.response.collection.exercise.domain.Event; @@ -120,6 +121,8 @@ public static EventDTO createEventDTOFromEvent(Event event) { @Autowired private List actionRuleRemovers; + @Autowired private ActionSvcClient actionSvcClient; + public Event createEvent(EventDTO eventDto) throws CTPException { UUID collexId = eventDto.getCollectionExerciseId(); CollectionExercise collex = getCollectionExercise(collexId, Fault.RESOURCE_NOT_FOUND); @@ -448,8 +451,8 @@ public void processEvents() { if (tag.isActionable()) { log.with("tag", event.getTag()).info("Event is actionable, beginning processing"); // Hard code response until endpoint exists. - // boolean success = actionSvcClient.processEvent(event.getTag(), exercise.getId()) - if (true) { + boolean success = actionSvcClient.processEvent(event.getTag(), exercise.getId()); + if (success) { log.info("Event processing succeeded, setting to PROCESSED state"); event.setStatus(EventDTO.Status.PROCESSED); event.setMessageSent(Timestamp.from(Instant.now())); diff --git a/src/test/java/uk/gov/ons/ctp/response/collection/exercise/service/EventServiceTest.java b/src/test/java/uk/gov/ons/ctp/response/collection/exercise/service/EventServiceTest.java index fb90a8184..ad36b9aae 100644 --- a/src/test/java/uk/gov/ons/ctp/response/collection/exercise/service/EventServiceTest.java +++ b/src/test/java/uk/gov/ons/ctp/response/collection/exercise/service/EventServiceTest.java @@ -633,7 +633,7 @@ public void testProcessEventsTransitionGoLive() { // Then verify(eventRepository, atMost(1)).findByStatus(EventDTO.Status.SCHEDULED); - verify(actionSvcClient, never()).processEvent(any(), any()); + verify(actionSvcClient, atMost(1)).processEvent(any(), any()); try { verify(collectionExerciseService, atMost(1)) .transitionCollectionExercise(