diff --git a/pom.xml b/pom.xml index 82989d52e..b2bcaa271 100644 --- a/pom.xml +++ b/pom.xml @@ -43,11 +43,11 @@ 17.0.57 17.0.1 17.104.137 - 17.0.38 + 17.104.52 17.0.11 0.1.49 17.104.48 - 17.0.279 + 17.0.286 17.0.66 4.1.4-ATCM true diff --git a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/PressTransparencyReportRequestedProcessor.java b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/PressTransparencyReportRequestedProcessor.java index 49b42e0af..2b67788bb 100644 --- a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/PressTransparencyReportRequestedProcessor.java +++ b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/PressTransparencyReportRequestedProcessor.java @@ -148,18 +148,27 @@ public void handlePressTransparencyPDFReportRequest(final JsonEnvelope envelope) public void handlePressTransparencyJSONReportRequest(final JsonEnvelope envelope) { payloadHelper.initCache(); - final List pendingCasesFromViewStore = getPendingCasesFromViewStore(envelope); final JsonObject eventPayload = envelope.payloadAsJsonObject(); final UUID reportId = fromString(eventPayload.getString(PRESS_TRANSPARENCY_REPORT_ID)); - final boolean isWelsh = WELSH.name().equalsIgnoreCase(eventPayload.getString(LANGUAGE)); + final String requestType = eventPayload.getString(REQUEST_TYPE); + final String language = eventPayload.getString(LANGUAGE); + LOGGER.info("handling press transparency JSON report request for press report {}, requestType {}, language {}", + reportId, requestType, language); + + final List pendingCasesFromViewStore = getPendingCasesFromViewStore(envelope); + LOGGER.info("fetched {} pending case(s) from view store for press report {}", pendingCasesFromViewStore.size(), reportId); + + final boolean isWelsh = WELSH.name().equalsIgnoreCase(language); LOGGER.info("generating press transparency JSON report for press report {}", reportId); publishCourtList(envelope, buildPayload(pendingCasesFromViewStore, true, envelope, isWelsh)); + LOGGER.info("completed handling press transparency JSON report request for press report {}", reportId); } private void publishCourtList(final JsonEnvelope envelope, final JsonObject payloadForDocumentGeneration) { - LOGGER.info("publishing sjp press pending cases list to court list publishing service"); final String type = envelope.payloadAsJsonObject().getString(REQUEST_TYPE); final String language = envelope.payloadAsJsonObject().getString(LANGUAGE); + LOGGER.info("building sjp press court list publish request, listType {}, requestType {}, language {}", + SJP_PRESS_LIST, type, language); final JsonObject courtListPublishRequest = createObjectBuilder() .add(LIST_TYPE, SJP_PRESS_LIST) .add(LANGUAGE, language) @@ -167,9 +176,12 @@ private void publishCourtList(final JsonEnvelope envelope, final JsonObject payl .add("listPayload", payloadForDocumentGeneration) .build(); + LOGGER.info("publishing sjp press pending cases list to court list publishing service"); try { courtListPublishingService.publishCourtList(courtListPublishRequest.toString()); + LOGGER.info("publishing sjp press pending cases list to court list publishing service called successfully"); } catch (IOException e) { + LOGGER.error("IO Exception happened while publishing sjp press court list", e); throw new RuntimeException("IO Exception happened while publishing sjp press court list", e); } } diff --git a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/helper/HttpConnectionHelper.java b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/helper/HttpConnectionHelper.java index a4aa12c62..84294f1b6 100644 --- a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/helper/HttpConnectionHelper.java +++ b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/helper/HttpConnectionHelper.java @@ -10,21 +10,35 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class HttpConnectionHelper { + private static final Logger LOGGER = LoggerFactory.getLogger(HttpConnectionHelper.class); + private static final String CONTENT_TYPE = "content-type"; - private static final String APPLICATION_JSON_CONTENT_TYPE = "application/json"; + private static final String APPLICATION_JSON_CONTENT_TYPE = "application/vnd.courtlistpublishing-service.sjp.post+json"; public Integer getResponseCode(final String url, final String payload) throws IOException { + return getResponseCode(url, payload, UUID.randomUUID().toString()); + } + + public Integer getResponseCode(final String url, final String payload, final String userId) throws IOException { final HttpPost post = new HttpPost(url); post.addHeader(CONTENT_TYPE, APPLICATION_JSON_CONTENT_TYPE); - post.addHeader(HeaderConstants.USER_ID, UUID.randomUUID().toString()); + post.addHeader(HeaderConstants.USER_ID, userId); post.setEntity(new StringEntity(payload)); + LOGGER.info("sending POST request to url {}", url); try (CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = httpClient.execute(post)) { - return response.getStatusLine().getStatusCode(); + final int statusCode = response.getStatusLine().getStatusCode(); + LOGGER.info("received response from url {}, statusCode {}", url, statusCode); + return statusCode; + } catch (final IOException e) { + LOGGER.error("failed to send POST request to url {}", url, e); + throw e; } } } diff --git a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/ApplicationParameters.java b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/ApplicationParameters.java index b65dab8e0..62a5bb4fa 100644 --- a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/ApplicationParameters.java +++ b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/ApplicationParameters.java @@ -16,7 +16,7 @@ public class ApplicationParameters { private String relayCaseOnCppFunctionPath; @Inject - @Value(key = "COURT_LIST_PUBLISHING_SERVICE_URL", defaultValue = "http://localhost:8080") + @Value(key = "COURT_LIST_PUBLISHING_SERVICE_URL", defaultValue = "http://localhost:8080/courtlistpublishing-service") private String courtListPublishingServiceUrl; diff --git a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/CourtListPublishingService.java b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/CourtListPublishingService.java index 98ff71495..95c12b745 100644 --- a/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/CourtListPublishingService.java +++ b/sjp-event/sjp-event-processor/src/main/java/uk/gov/moj/cpp/sjp/event/processor/service/CourtListPublishingService.java @@ -1,5 +1,7 @@ package uk.gov.moj.cpp.sjp.event.processor.service; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import uk.gov.moj.cpp.sjp.event.processor.helper.HttpConnectionHelper; import java.io.IOException; @@ -8,24 +10,32 @@ public class CourtListPublishingService { + private static final Logger LOGGER = LoggerFactory.getLogger(CourtListPublishingService.class); private static final String PUBLISH_SJP_COURT_LIST_PATH = "/api/court-list-publish/sjp/publishCourtList"; - private HttpConnectionHelper httpConnectionHelper; + private final HttpConnectionHelper httpConnectionHelper; @Inject private ApplicationParameters applicationParameters; + @Inject + private SystemIdMapperService systemIdMapperService; + public CourtListPublishingService() { this.httpConnectionHelper = new HttpConnectionHelper(); } - public CourtListPublishingService(final HttpConnectionHelper httpConnectionHelper, final ApplicationParameters applicationParameters) { - this.httpConnectionHelper = httpConnectionHelper; - this.applicationParameters = applicationParameters; - } - public Integer publishCourtList(final String payload) throws IOException { - return httpConnectionHelper.getResponseCode( - applicationParameters.getCourtListPublishingServiceUrl() + PUBLISH_SJP_COURT_LIST_PATH, payload); + final String url = applicationParameters.getCourtListPublishingServiceUrl() + PUBLISH_SJP_COURT_LIST_PATH; + final String systemUserId = systemIdMapperService.getSystemUserId().toString(); + LOGGER.info("publishing court list to url {}, payload size {} bytes", url, payload.length()); + try { + final Integer responseCode = httpConnectionHelper.getResponseCode(url, payload, systemUserId); + LOGGER.info("publish court list response from url {}, responseCode {}", url, responseCode); + return responseCode; + } catch (final IOException e) { + LOGGER.error("failed to publish court list to url {}", url, e); + throw e; + } } } diff --git a/sjp-integration-test/src/test/java/uk/gov/moj/sjp/it/stub/CourtListPublishingServiceStub.java b/sjp-integration-test/src/test/java/uk/gov/moj/sjp/it/stub/CourtListPublishingServiceStub.java index 49ef8ac36..b65724b54 100644 --- a/sjp-integration-test/src/test/java/uk/gov/moj/sjp/it/stub/CourtListPublishingServiceStub.java +++ b/sjp-integration-test/src/test/java/uk/gov/moj/sjp/it/stub/CourtListPublishingServiceStub.java @@ -26,7 +26,7 @@ public class CourtListPublishingServiceStub { - private static final String PUBLISH_COURT_LIST_URL = "/api/court-list-publish/sjp/publishCourtList"; + private static final String PUBLISH_COURT_LIST_URL = "/courtlistpublishing-service/api/court-list-publish/sjp/publishCourtList"; private final static Logger LOGGER = LoggerFactory.getLogger(CourtListPublishingServiceStub.class); public static void stubPublishCourtListEndpoint() {