Skip to content
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-parent</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Progression services application</name>
Expand Down
2 changes: 1 addition & 1 deletion progression-command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-parent</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-command</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-command/progression-command-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-command</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-command-api</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-command/progression-command-handler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-command</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-command-handler</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-parent</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-domain</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-domain/progression-datatypes-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>progression-domain</artifactId>
<groupId>uk.gov.moj.cpp.progression</groupId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion progression-domain/progression-domain-aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>progression-domain</artifactId>
<groupId>uk.gov.moj.cpp.progression</groupId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>progression-domain-aggregate</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion progression-domain/progression-domain-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-domain</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-domain-common</artifactId>
<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion progression-domain/progression-domain-message/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-domain</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-domain-message</artifactId>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion progression-event-sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>progression-parent</artifactId>
<groupId>uk.gov.moj.cpp.progression</groupId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion progression-event/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-parent</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-event</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-event/progression-event-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-event</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-event-indexer</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-event/progression-event-listener/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-event</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-event-listener</artifactId>
<packaging>war</packaging>
Expand Down
2 changes: 1 addition & 1 deletion progression-event/progression-event-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>uk.gov.moj.cpp.progression</groupId>
<artifactId>progression-event</artifactId>
<version>17.0.276-SNAPSHOT</version>
<version>17.0.276-CIMD-3986-SNAPSHOT</version>
</parent>
<artifactId>progression-event-processor</artifactId>
<packaging>war</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class CourtApplicationService {
private static final Logger LOGGER = LoggerFactory.getLogger(CourtApplicationService.class);

private static final String PROSECUTOR_CONTACT_EMAIL_ADDRESS_KEY = "contactEmailAddress";
private static final String PROSECUTOR_CPS_CC_EMAIL_ADDRESS_KEY = "cpsCcEmailAddress";
private static final String PROSECUTOR_OUCODE_KEY = "oucode";
private static final String PROSECUTOR_MAJOR_CREDITOR_CODE_KEY = "majorCreditorCode";

Expand All @@ -41,8 +42,12 @@ public class CourtApplicationService {



public ProsecutingAuthority getProsecutingAuthority(final UUID prosecutionAuthorityId, final JsonEnvelope jsonEnvelope) {
return getProsecutingAuthority(prosecutionAuthorityId, jsonEnvelope, false);
}

@SuppressWarnings("pmd:NullAssignment")
public ProsecutingAuthority getProsecutingAuthority(UUID prosecutionAuthorityId, final JsonEnvelope jsonEnvelope) {
public ProsecutingAuthority getProsecutingAuthority(final UUID prosecutionAuthorityId, final JsonEnvelope jsonEnvelope, final boolean isCps) {

final ProsecutingAuthority.Builder prosecutingAuthorityBuilder = prosecutingAuthority().withProsecutionAuthorityId(prosecutionAuthorityId);

Expand All @@ -53,9 +58,11 @@ public ProsecutingAuthority getProsecutingAuthority(UUID prosecutionAuthorityId,
.withWelshName(jsonObject.getString("nameWelsh", null))
.withAddress(isNull(jsonObject.getJsonObject("address")) ? null : jsonObjectToObjectConverter.convert(jsonObject.getJsonObject("address"), Address.class));

if (jsonObject.containsKey(PROSECUTOR_CONTACT_EMAIL_ADDRESS_KEY)) {
// CPS prosecutors are notified on their CPS CC email address rather than the contact email address
final String emailAddressKey = isCps ? PROSECUTOR_CPS_CC_EMAIL_ADDRESS_KEY : PROSECUTOR_CONTACT_EMAIL_ADDRESS_KEY;
if (jsonObject.containsKey(emailAddressKey) && !jsonObject.isNull(emailAddressKey)) {
prosecutingAuthorityBuilder.withContact(contactNumber()
.withPrimaryEmail(jsonObject.getString(PROSECUTOR_CONTACT_EMAIL_ADDRESS_KEY))
.withPrimaryEmail(jsonObject.getString(emailAddressKey))
.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public class NotificationService {
private static final String EMPTY = "";
private static final String CONTENT_TYPE = "application/pdf";
private static final String MATERIAL_TYPE = "Court Final orders";
private static final String PROGRESSION_QUERY_PROSECUTION_CASE = "progression.query.prosecutioncase";
private static final String PROSECUTION_CASE = "prosecutionCase";
private static final String PROSECUTOR = "prosecutor";
private static final String PROSECUTOR_ID = "prosecutorId";
private static final String IS_CPS = "isCps";
@Inject
private Enveloper enveloper;
@Inject
Expand Down Expand Up @@ -623,11 +628,67 @@ private static boolean isMatchingProsecutionAuthority(
.orElse(false);
}

private void sendNotificationToInformant(final JsonEnvelope event, final CourtApplication courtApplication, final Boolean isWelshTranslationRequired, final CourtCentre courtCentre, final String hearingDate, final String hearingTime, final JurisdictionType jurisdictionType, final Boolean isAmended, final LocalDate issueDate, final InformantNotificationTracker informantNotificationTracker) {
private void sendNotificationToInformantAndProsecutor(final JsonEnvelope event, final CourtApplication courtApplication, final Boolean isWelshTranslationRequired, final CourtCentre courtCentre, final String hearingDate, final String hearingTime,
final JurisdictionType jurisdictionType, final Boolean isAmended, final LocalDate issueDate, final InformantNotificationTracker informantNotificationTracker) {
sendNotificationToInformant(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, issueDate);
sendNotificationToProsecutor(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, issueDate, informantNotificationTracker);
}

private void sendNotificationToInformant(final JsonEnvelope event, final CourtApplication courtApplication, final Boolean isWelshTranslationRequired, final CourtCentre courtCentre, final String hearingDate, final String hearingTime,
final JurisdictionType jurisdictionType, final Boolean isAmended, final LocalDate issueDate) {
final UUID informantAuthorityId = courtApplication.getCourtApplicationCases().get(0).getProsecutionCaseIdentifier().getProsecutionAuthorityId();
final ProsecutingAuthority prosecutingAuthority = courtApplicationService.getProsecutingAuthority(informantAuthorityId, event);
final PostalNotificationDetails postalNotificationDetails = buildPostalNotificationDetails(courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, null, jurisdictionType, isAmended, issueDate);
sendNotificationToProsecutor(event, prosecutingAuthority, postalNotificationDetails);
sendNotificationToProsecutingAuthority(event, prosecutingAuthority, postalNotificationDetails);
}

private void sendNotificationToProsecutor(final JsonEnvelope event, final CourtApplication courtApplication, final Boolean isWelshTranslationRequired, final CourtCentre courtCentre, final String hearingDate, final String hearingTime,
final JurisdictionType jurisdictionType, final Boolean isAmended, final LocalDate issueDate, final InformantNotificationTracker informantNotificationTracker) {

final UUID caseId = courtApplication.getCourtApplicationCases().get(0).getProsecutionCaseId();
if (isNull(caseId)) {
LOGGER.info("No prosecution case id on court application {}; skipping prosecutor notification.", courtApplication.getId());
return;
}

final Optional<JsonObject> currentProsecutor = getCurrentProsecutor(event, caseId);
if (!currentProsecutor.isPresent()) {
LOGGER.info("No current prosecutor found for case {}; skipping prosecutor notification.", caseId);
return;
}

final JsonObject prosecutorJson = currentProsecutor.get();
final UUID prosecutorId = UUID.fromString(prosecutorJson.getString(PROSECUTOR_ID));
final boolean isCps = prosecutorJson.getBoolean(IS_CPS, false);

// Reuse the informant tracker so we don't email the same prosecuting authority twice
if (prosecutorId.equals(informantNotificationTracker.getProsecutionAuthorityId())) {
LOGGER.info("Prosecutor {} already notified as informant; skipping prosecutor notification.", prosecutorId);
return;
}

final ProsecutingAuthority prosecutingAuthority = courtApplicationService.getProsecutingAuthority(prosecutorId, event, isCps);
final PostalNotificationDetails postalNotificationDetails = buildPostalNotificationDetails(courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, null, jurisdictionType, isAmended, issueDate);
sendNotificationToProsecutingAuthority(event, prosecutingAuthority, postalNotificationDetails);
}

private Optional<JsonObject> getCurrentProsecutor(final JsonEnvelope event, final UUID caseId) {
final JsonObject requestParameter = createObjectBuilder().add(CASE_ID, caseId.toString()).build();

final JsonEnvelope response = requester.requestAsAdmin(enveloper
.withMetadataFrom(event, PROGRESSION_QUERY_PROSECUTION_CASE)
.apply(requestParameter));

final JsonObject payload = response.payloadAsJsonObject();
if (payload.isEmpty() || !payload.containsKey(PROSECUTION_CASE)) {
return Optional.empty();
}

final JsonObject prosecutionCase = payload.getJsonObject(PROSECUTION_CASE);
if (prosecutionCase.containsKey(PROSECUTOR) && prosecutionCase.getJsonObject(PROSECUTOR).containsKey(PROSECUTOR_ID)) {
return Optional.of(prosecutionCase.getJsonObject(PROSECUTOR));
}
return Optional.empty();
}

private void sendNotification(JsonEnvelope event, CourtApplication courtApplication, Boolean isWelshTranslationRequired, CourtCentre courtCentre, String hearingDate, String hearingTime, JurisdictionType jurisdictionType, CourtApplicationParty courtApplicationParty, Optional<AssociatedDefenceOrganisation> associatedDefenceOrganisation, Boolean isAmended, LocalDate issueDate) {
Expand Down Expand Up @@ -711,9 +772,9 @@ private void sendNotification(final JsonEnvelope event, final UUID notificationI

}

private void sendNotificationToProsecutor(final JsonEnvelope event,
final ProsecutingAuthority prosecutingAuthority,
final PostalNotificationDetails postalNotificationDetails) {
private void sendNotificationToProsecutingAuthority(final JsonEnvelope event,
final ProsecutingAuthority prosecutingAuthority,
final PostalNotificationDetails postalNotificationDetails) {

final UUID notificationId = UUID.randomUUID();

Expand Down Expand Up @@ -1040,7 +1101,7 @@ public void sendNotification(final JsonEnvelope event, final CourtApplication co
sendNotificationToThirdParties(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, LocalDate.now(), informantNotificationTracker);
LOGGER.info("InformantNotificationTracker= {}", informantNotificationTracker);
if (shouldSendInformantNotification(courtApplication, informantNotificationTracker)) {
sendNotificationToInformant(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, LocalDate.now(), informantNotificationTracker);
sendNotificationToInformantAndProsecutor(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, LocalDate.now(), informantNotificationTracker);
}
}
}
Expand Down Expand Up @@ -1076,7 +1137,7 @@ public void sendNotificationForAutoApplication(final JsonEnvelope event, final S

LOGGER.info("InformantNotificationTracker= {}", informantNotificationTracker);
if (shouldSendInformantNotification(courtApplication, informantNotificationTracker)) {
sendNotificationToInformant(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, LocalDate.now(), informantNotificationTracker);
sendNotificationToInformantAndProsecutor(event, courtApplication, isWelshTranslationRequired, courtCentre, hearingDate, hearingTime, jurisdictionType, isAmended, LocalDate.now(), informantNotificationTracker);
}

if(nonNull(isWelshTranslationRequired) && isWelshTranslationRequired) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,69 @@ public void shouldReturnCourtApplicationPartyWhenProsecutingAuthorityDataExists(
assertThat(result.getAddress().getPostcode(), is("SW1A 1AA"));
}

@Test
public void shouldUseCpsCcEmailAddressWhenProsecutorIsCps() {
JsonObject prosecutorJson = Json.createObjectBuilder()
.add("fullName", "CPS West Midlands")
.add("contactEmailAddress", "contact@cps.gov.uk")
.add("cpsCcEmailAddress", "cc@cps.gov.uk")
.add("cpsFlag", true)
.add("address", Json.createObjectBuilder()
.add("line1", "123 Main St")
.add("postcode", "SW1A 1AA")
.build())
.build();

var address = Address.address()
.withAddress1("123 Main St")
.withPostcode("SW1A 1AA").build();

when(referenceDataService.getProsecutor(any(JsonEnvelope.class), any(UUID.class), any(Requester.class)))
.thenReturn(Optional.of(prosecutorJson));
when(jsonObjectToObjectConverter.convert(prosecutorJson.getJsonObject("address"), Address.class))
.thenReturn(address);

ProsecutingAuthority result = courtApplicationService.getProsecutingAuthority(prosecutionAuthorityId, jsonEnvelope, true);

// For a CPS prosecutor the CPS CC email address is used instead of the contact email address
assertThat(result.getContact().getPrimaryEmail(), is("cc@cps.gov.uk"));
// The reference data is only queried once (no second getProsecutorV2 call)
verify(referenceDataService, times(1)).getProsecutor(jsonEnvelope, prosecutionAuthorityId, requester);
}

@Test
public void shouldUseContactEmailAddressWhenProsecutorIsNotCps() {
JsonObject prosecutorJson = Json.createObjectBuilder()
.add("fullName", "Transport for London")
.add("contactEmailAddress", "contact@tfl.gov.uk")
.add("cpsCcEmailAddress", "cc@cps.gov.uk")
.build();

when(referenceDataService.getProsecutor(any(JsonEnvelope.class), any(UUID.class), any(Requester.class)))
.thenReturn(Optional.of(prosecutorJson));

ProsecutingAuthority result = courtApplicationService.getProsecutingAuthority(prosecutionAuthorityId, jsonEnvelope, false);

assertThat(result.getContact().getPrimaryEmail(), is("contact@tfl.gov.uk"));
}

@Test
public void shouldNotSetContactWhenCpsProsecutorHasNoCpsCcEmailAddress() {
JsonObject prosecutorJson = Json.createObjectBuilder()
.add("fullName", "CPS West Midlands")
.add("contactEmailAddress", "contact@cps.gov.uk")
.add("cpsFlag", true)
.build();

when(referenceDataService.getProsecutor(any(JsonEnvelope.class), any(UUID.class), any(Requester.class)))
.thenReturn(Optional.of(prosecutorJson));

ProsecutingAuthority result = courtApplicationService.getProsecutingAuthority(prosecutionAuthorityId, jsonEnvelope, true);

// No CPS CC email address means no contact - a postal notification will be sent downstream
assertThat(result.getContact(), is(nullValue()));
}

@Test
public void shouldReturnEmptyCourtApplicationPartyWhenNoProsecutingAuthorityDataExists() {
when(referenceDataService.getProsecutor(any(JsonEnvelope.class), any(UUID.class), any(Requester.class)))
Expand Down
Loading
Loading