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

<groupId>uk.gov.moj.cpp.sjp</groupId>
<artifactId>sjp-parent</artifactId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion sjp-command/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sjp-parent</artifactId>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sjp-command/sjp-command-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sjp-command</artifactId>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public void endSession(final JsonEnvelope envelope) {
sender.send(enveloper.withMetadataFrom(envelope, "sjp.command.end-session").apply(envelope.payloadAsJsonObject()));
}

@Handles("sjp.update-session-bdf")
public void updateSessionBdf(final JsonEnvelope updateSessionCommand) {
validateSessionId(updateSessionCommand);
sender.send(enveloper.withMetadataFrom(updateSessionCommand, "sjp.command.update-session-bdf").apply(updateSessionCommand.payloadAsJsonObject()));
}

@Handles("sjp.assign-next-case")
public void assignNextCase(final JsonEnvelope assignCaseCommand) {
sender.send(enveloper.withMetadataFrom(assignCaseCommand, "sjp.command.assign-next-case").apply(assignCaseCommand.payloadAsJsonObject()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ rule "Command - Rule for end session"
$outcome.setSuccess(true);
end

rule "Command - Rule for update session"
when
$outcome: Outcome();
$action: Action(name == "sjp.update-session-bdf");
eval(userAndGroupProvider.isMemberOfAnyOfTheSuppliedGroups($action, RuleConstants.getSystemUsers()));
then
$outcome.setSuccess(true);
end

rule "Command - Rule for assigning case"
when
$outcome: Outcome();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"magistrate": {
"type": "string"
},
"courtHouseCode": {
"type": "string"
},
"courtHouseName": {
"type": "string"
},
"localJusticeAreaNationalCourtCode": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["MAGISTRATE", "DELEGATED_POWERS", "AOCP"]
},
"legalAdviserUserId": {
"$ref": "http://justice.gov.uk/domain/core/common/definitions.json#/definitions/uuid"
}
},
"minProperties": 1,
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"magistrate": "Alan Smith",
"courtHouseCode": "B01LY",
"courtHouseName": "Coventry Magistrates' Court",
"localJusticeAreaNationalCourtCode": "2924",
"type": "MAGISTRATE",
"legalAdviserUserId": "31ec3a16-8721-498c-8da5-f099390ee254"
}
8 changes: 8 additions & 0 deletions sjp-command/sjp-command-api/src/raml/sjp-command-api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ baseUri: http://localhost:8080/sjp-command-api/command/api/rest/sjp
(mapping):
requestType: application/vnd.sjp.assign-next-case+json
name: sjp.assign-next-case
(mapping):
requestType: application/vnd.sjp.update-session-bdf+json
name: sjp.update-session-bdf
...
body:
application/vnd.sjp.start-session+json:
Expand All @@ -511,6 +514,11 @@ baseUri: http://localhost:8080/sjp-command-api/command/api/rest/sjp
!include json/schema/sjp.start-session.json
application/vnd.sjp.end-session+json: !!null
application/vnd.sjp.assign-next-case+json: !!null
application/vnd.sjp.update-session-bdf+json:
example:
!include json/sjp.update-session-bdf.json
schema:
!include json/schema/sjp.update-session-bdf.json
responses:
202:
description: Accepted
Expand Down
2 changes: 1 addition & 1 deletion sjp-command/sjp-command-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sjp-command</artifactId>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void endSession(final JsonEnvelope envelope) {
send(envelope);
}

@Handles("sjp.command.update-session-bdf")
public void updateSessionBdf(final JsonEnvelope envelope) {
send(envelope);
}

@Handles("sjp.command.reset-aocp-session")
public void resetAocpSession(final JsonEnvelope envelope) {
send(envelope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ rule "Command - Rule for end session"
$outcome.setSuccess(true);
end

rule "Command - Rule for update session"
when
$outcome: Outcome();
$action: Action(name == "sjp.command.update-session-bdf");
then
$outcome.setSuccess(true);
end

rule "Command - Rule for reset aocp session request"
when
$outcome: Outcome();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/json/schemas/domains/sjp/command/sjp.update-session-bdf.json",
"$ref": "http://justice.gov.uk/json/schemas/domains/sjp/commands/sjp.update-session-bdf.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sessionId": "c70867c0-3d9b-4cd4-978d-056a2915bb75",
"magistrate": "Alan Smith",
"courtHouseCode": "B01LY",
"courtHouseName": "Coventry Magistrates' Court",
"localJusticeAreaNationalCourtCode": "2924",
"type": "MAGISTRATE",
"legalAdviserUserId": "31ec3a16-8721-498c-8da5-f099390ee254"
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ version: v1
example: !include json/sjp.command.end-session.json
schema: !include json/schema/sjp.command.end-session.json

application/vnd.sjp.command.update-session-bdf+json:
example: !include json/sjp.command.update-session-bdf.json
schema: !include json/schema/sjp.command.update-session-bdf.json

application/vnd.sjp.command.reset-aocp-session+json: !!null

application/vnd.sjp.command.assign-next-case+json:
Expand Down
2 changes: 1 addition & 1 deletion sjp-command/sjp-command-handler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>sjp-command</artifactId>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import uk.gov.justice.services.eventsourcing.source.core.exception.EventStreamException;
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.messaging.JsonObjects;
import uk.gov.moj.cpp.sjp.domain.SessionType;
import uk.gov.moj.cpp.sjp.domain.aggregate.Session;
import uk.gov.moj.cpp.sjp.event.session.ResetAocpSession;

Expand Down Expand Up @@ -94,6 +95,21 @@ public void endSession(final JsonEnvelope endSessionCommand) throws EventStreamE
applyToSessionAggregate(endSessionCommand, session -> session.endSession(sessionId, clock.now()));
}

@Handles("sjp.command.update-session-bdf")
public void updateSessionBdf(final JsonEnvelope updateSessionCommand) throws EventStreamException {
final JsonObject updateSession = updateSessionCommand.payloadAsJsonObject();
final UUID sessionId = UUID.fromString(updateSession.getString(SESSION_ID));
final Optional<String> magistrate = JsonObjects.getString(updateSession, MAGISTRATE);
final Optional<String> courtHouseCode = JsonObjects.getString(updateSession, COURT_HOUSE_CODE);
final Optional<String> courtHouseName = JsonObjects.getString(updateSession, COURT_HOUSE_NAME);
final Optional<String> localJusticeAreaNationalCourtCode = JsonObjects.getString(updateSession, LOCAL_JUSTICE_AREA_NATIONAL_COURT_CODE);
final Optional<SessionType> type = JsonObjects.getString(updateSession, "type").map(SessionType::valueOf);
final Optional<UUID> legalAdviserUserId = JsonObjects.getString(updateSession, "legalAdviserUserId").map(UUID::fromString);

applyToSessionAggregate(updateSessionCommand, session ->
session.updateSessionBdf(sessionId, magistrate, courtHouseCode, courtHouseName, localJusticeAreaNationalCourtCode, type, legalAdviserUserId));
}

@Handles("sjp.command.reset-aocp-session")
public void resetAocpSessionRequest(final JsonEnvelope command) throws EventStreamException {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/json/schemas/domains/sjp/command/sjp.update-session-bdf.json",
"$ref": "http://justice.gov.uk/json/schemas/domains/sjp/commands/sjp.update-session-bdf.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sessionId": "c70867c0-3d9b-4cd4-978d-056a2915bb75",
"magistrate": "Alan Smith",
"courtHouseCode": "B01LY",
"courtHouseName": "Coventry Magistrates' Court",
"localJusticeAreaNationalCourtCode": "2924",
"type": "MAGISTRATE",
"legalAdviserUserId": "31ec3a16-8721-498c-8da5-f099390ee254"
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ version: v1
schema: !include json/schema/sjp.command.end-session.json
example: !include json/sjp.command.end-session.json

application/vnd.sjp.command.update-session-bdf+json:
schema: !include json/schema/sjp.command.update-session-bdf.json
example: !include json/sjp.command.update-session-bdf.json

application/vnd.sjp.command.assign-next-case+json:
schema: !include json/schema/sjp.command.assign-next-case.json
example: !include json/sjp.command.assign-next-case.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
import uk.gov.justice.services.messaging.JsonEnvelope;
import uk.gov.justice.services.messaging.MetadataBuilder;
import uk.gov.justice.services.test.utils.common.helper.StoppedClock;
import uk.gov.moj.cpp.sjp.domain.SessionType;
import uk.gov.moj.cpp.sjp.domain.aggregate.Session;
import uk.gov.moj.cpp.sjp.event.session.DelegatedPowersSessionEnded;
import uk.gov.moj.cpp.sjp.event.session.DelegatedPowersSessionStarted;
import uk.gov.moj.cpp.sjp.event.session.MagistrateSessionEnded;
import uk.gov.moj.cpp.sjp.event.session.MagistrateSessionStarted;
import uk.gov.moj.cpp.sjp.event.session.ResetAocpSession;
import uk.gov.moj.cpp.sjp.event.session.SessionEnded;
import uk.gov.moj.cpp.sjp.event.session.SessionUpdatedBdf;

import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -73,6 +75,7 @@ public class SessionHandlerTest {
private static final String START_SESSION_COMMAND = "sjp.command.start-session";
private static final String END_SESSION_COMMAND = "sjp.command.end-session";
private static final String RESET_SESSION_COMMAND = "sjp.command.reset-aocp-session";
private static final String UPDATE_SESSION_BDF_COMMAND = "sjp.command.update-session-bdf";
@Mock
private EventSource eventSource;

Expand All @@ -98,7 +101,8 @@ public class SessionHandlerTest {
MagistrateSessionEnded.class,
DelegatedPowersSessionStarted.class,
DelegatedPowersSessionEnded.class,
ResetAocpSession.class);
ResetAocpSession.class,
SessionUpdatedBdf.class);

@Spy
private Clock clock = new StoppedClock(ZonedDateTime.now(UTC));
Expand Down Expand Up @@ -131,7 +135,8 @@ public void shouldHandleSessionCommands() {
.with(allOf(
method("startSession").thatHandles(START_SESSION_COMMAND),
method("endSession").thatHandles(END_SESSION_COMMAND),
method("resetAocpSessionRequest").thatHandles(RESET_SESSION_COMMAND)
method("resetAocpSessionRequest").thatHandles(RESET_SESSION_COMMAND),
method("updateSessionBdf").thatHandles(UPDATE_SESSION_BDF_COMMAND)
)));
}

Expand Down Expand Up @@ -249,6 +254,88 @@ public void shouldResetSession() throws EventStreamException {
}


@Test
public void shouldUpdateSessionBdfWithAllFields() throws EventStreamException {

final String magistrate = randomAlphanumeric(20);
final UUID legalAdviserUserId = randomUUID();

final JsonEnvelope updateSessionCommand = envelopeFrom(metadataWithRandomUUID(UPDATE_SESSION_BDF_COMMAND),
createObjectBuilder()
.add("sessionId", sessionId.toString())
.add("magistrate", magistrate)
.add("courtHouseCode", courtHouseCode)
.add("courtHouseName", courtHouseName)
.add("localJusticeAreaNationalCourtCode", localJusticeAreaNationalCourtCode)
.add("type", SessionType.MAGISTRATE.name())
.add("legalAdviserUserId", legalAdviserUserId.toString())
.build());

final SessionUpdatedBdf sessionUpdatedBdf = new SessionUpdatedBdf(sessionId, Optional.of(magistrate), Optional.of(courtHouseCode), Optional.of(courtHouseName),
Optional.of(localJusticeAreaNationalCourtCode), Optional.of(SessionType.MAGISTRATE), Optional.of(legalAdviserUserId));

when(eventSource.getStreamById(sessionId)).thenReturn(sessionEventStream);
when(aggregateService.get(sessionEventStream, Session.class)).thenReturn(session);
when(session.updateSessionBdf(sessionId, Optional.of(magistrate), Optional.of(courtHouseCode), Optional.of(courtHouseName),
Optional.of(localJusticeAreaNationalCourtCode), Optional.of(SessionType.MAGISTRATE), Optional.of(legalAdviserUserId)))
.thenReturn(Stream.of(sessionUpdatedBdf));

sessionHandler.updateSessionBdf(updateSessionCommand);

assertThat(sessionEventStream, eventStreamAppendedWith(
streamContaining(
jsonEnvelope(
withMetadataEnvelopedFrom(updateSessionCommand)
.withName(SessionUpdatedBdf.EVENT_NAME),
payloadIsJson(allOf(
withJsonPath("$.sessionId", equalTo(sessionId.toString())),
withJsonPath("$.magistrate", equalTo(magistrate)),
withJsonPath("$.courtHouseCode", equalTo(courtHouseCode)),
withJsonPath("$.courtHouseName", equalTo(courtHouseName)),
withJsonPath("$.localJusticeAreaNationalCourtCode", equalTo(localJusticeAreaNationalCourtCode)),
withJsonPath("$.type", equalTo(SessionType.MAGISTRATE.name())),
withJsonPath("$.legalAdviserUserId", equalTo(legalAdviserUserId.toString()))
))))));
}

@Test
public void shouldUpdateSessionBdfWithOnlyMagistrate() throws EventStreamException {

final String magistrate = randomAlphanumeric(20);

final JsonEnvelope updateSessionCommand = envelopeFrom(metadataWithRandomUUID(UPDATE_SESSION_BDF_COMMAND),
createObjectBuilder()
.add("sessionId", sessionId.toString())
.add("magistrate", magistrate)
.build());

final SessionUpdatedBdf sessionUpdatedBdf = new SessionUpdatedBdf(sessionId, Optional.of(magistrate), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty());

when(eventSource.getStreamById(sessionId)).thenReturn(sessionEventStream);
when(aggregateService.get(sessionEventStream, Session.class)).thenReturn(session);
when(session.updateSessionBdf(sessionId, Optional.of(magistrate), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty()))
.thenReturn(Stream.of(sessionUpdatedBdf));

sessionHandler.updateSessionBdf(updateSessionCommand);

assertThat(sessionEventStream, eventStreamAppendedWith(
streamContaining(
jsonEnvelope(
withMetadataEnvelopedFrom(updateSessionCommand)
.withName(SessionUpdatedBdf.EVENT_NAME),
payloadIsJson(allOf(
withJsonPath("$.sessionId", equalTo(sessionId.toString())),
withJsonPath("$.magistrate", equalTo(magistrate)),
withoutJsonPath("$.courtHouseCode"),
withoutJsonPath("$.courtHouseName"),
withoutJsonPath("$.localJusticeAreaNationalCourtCode"),
withoutJsonPath("$.type"),
withoutJsonPath("$.legalAdviserUserId")
))))));
}

private void shouldEndSession(final SessionEnded sessionEnded) throws EventStreamException {
final JsonEnvelope endSessionCommand = envelopeFrom(metadataWithRandomUUID(END_SESSION_COMMAND),
createObjectBuilder().add("sessionId", sessionEnded.getSessionId().toString()).build());
Expand Down
2 changes: 1 addition & 1 deletion sjp-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<artifactId>sjp-parent</artifactId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>

<artifactId>sjp-domain</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion sjp-domain/sjp-domain-aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>uk.gov.moj.cpp.sjp</groupId>
<artifactId>sjp-domain</artifactId>
<version>17.104.194-SNAPSHOT</version>
<version>17.104.194-REL-3RD-LINE-2627-SNAPSHOT</version>
</parent>

<artifactId>sjp-domain-aggregate</artifactId>
Expand Down
Loading
Loading