Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
<material.version>17.0.57</material.version>
<notification.notify.version>17.0.1</notification.notify.version>
<referencedata.version>17.104.137</referencedata.version>
<referencedata.offences.version>17.0.38</referencedata.offences.version>
<referencedata.offences.version>17.104.52</referencedata.offences.version>
<scheduling.version>17.0.11</scheduling.version>
<authorisation.service.version>0.1.49</authorisation.service.version>
<usersgroups.version>17.104.48</usersgroups.version>
<progression.version>17.0.279</progression.version>
<progression.version>17.0.286</progression.version>
<prosecutioncasefile.version>17.0.66</prosecutioncasefile.version>
<access-control-sjp-providers.version>4.1.4-ATCM</access-control-sjp-providers.version>
<cpp.framework.action.mapping.enabled>true</cpp.framework.action.mapping.enabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,40 @@ public void handlePressTransparencyPDFReportRequest(final JsonEnvelope envelope)
public void handlePressTransparencyJSONReportRequest(final JsonEnvelope envelope) {
payloadHelper.initCache();

final List<JsonObject> 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<JsonObject> 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)
.add(REQUEST_TYPE, type)
.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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that /courtlistpublishing-service/ is already in the host @Value(key = "COURT_LIST_PUBLISHING_SERVICE_URL", defaultValue = "http://localhost:8080/courtlistpublishing-service") . Would it cause a prob?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WireMock is the server listening on localhost:8080 — it strips scheme/host/port itself and only matches on the path portion of whatever request actually arrives. The path it receives is /courtlistpublishing-service/api/court-list-publish/sjp/publishCourtList, which is exactly what PUBLISH_COURT_LIST_URL equals now:

"/courtlistpublishing-service/api/court-list-publish/sjp/publishCourtList"

private final static Logger LOGGER = LoggerFactory.getLogger(CourtListPublishingServiceStub.class);

public static void stubPublishCourtListEndpoint() {
Expand Down
Loading