diff --git a/hearing-command/hearing-command-api/pom.xml b/hearing-command/hearing-command-api/pom.xml index 732639a5c..ec49be703 100644 --- a/hearing-command/hearing-command-api/pom.xml +++ b/hearing-command/hearing-command-api/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-command - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-command-api war diff --git a/hearing-command/hearing-command-handler/pom.xml b/hearing-command/hearing-command-handler/pom.xml index 72652cf40..a7e778722 100644 --- a/hearing-command/hearing-command-handler/pom.xml +++ b/hearing-command/hearing-command-handler/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-command - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-command-handler war diff --git a/hearing-command/hearing-command-handler/src/main/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandler.java b/hearing-command/hearing-command-handler/src/main/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandler.java index cec624eef..4858e26fb 100644 --- a/hearing-command/hearing-command-handler/src/main/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandler.java +++ b/hearing-command/hearing-command-handler/src/main/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandler.java @@ -63,11 +63,12 @@ public void updateInheritPlea(final JsonEnvelope envelope) throws EventStreamExc LOGGER.debug("hearing.command.enrich-update-plea-with-associated-hearings event received {}", envelope.toObfuscatedDebugString()); } + final Set guiltyPleaTypes = referenceDataService.retrieveGuiltyPleaTypes(); final UpdateInheritedPleaCommand command = convertToObject(envelope, UpdateInheritedPleaCommand.class); for (final UUID hearingId : command.getHearingIds()) { aggregate(HearingAggregate.class, hearingId, envelope, - hearingAggregate -> hearingAggregate.inheritPlea(hearingId, command.getPlea())); + hearingAggregate -> hearingAggregate.inheritPlea(hearingId, command.getPlea(), guiltyPleaTypes)); } } diff --git a/hearing-command/hearing-command-handler/src/test/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandlerTest.java b/hearing-command/hearing-command-handler/src/test/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandlerTest.java index 8f2959eae..7b35dfb44 100644 --- a/hearing-command/hearing-command-handler/src/test/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandlerTest.java +++ b/hearing-command/hearing-command-handler/src/test/java/uk/gov/moj/cpp/hearing/command/handler/UpdatePleaCommandHandlerTest.java @@ -46,9 +46,11 @@ import uk.gov.moj.cpp.hearing.domain.event.ConvictionDateRemoved; import uk.gov.moj.cpp.hearing.domain.event.HearingInitiated; import uk.gov.moj.cpp.hearing.domain.event.IndicatedPleaUpdated; +import uk.gov.moj.cpp.hearing.domain.event.InheritedPlea; import uk.gov.moj.cpp.hearing.domain.event.OffencePleaUpdated; import uk.gov.moj.cpp.hearing.domain.event.PleaUpsert; import uk.gov.moj.cpp.hearing.domain.updatepleas.UpdateAssociatedHearingsWithIndicatedPlea; +import uk.gov.moj.cpp.hearing.domain.updatepleas.UpdateInheritedPleaCommand; import uk.gov.moj.cpp.hearing.domain.updatepleas.UpdateOffencePleaCommand; import uk.gov.moj.cpp.hearing.domain.updatepleas.UpdatePleaCommand; @@ -84,7 +86,8 @@ public class UpdatePleaCommandHandlerTest { OffencePleaUpdated.class, ConvictionDateAdded.class, ConvictionDateRemoved.class, - IndicatedPleaUpdated.class); + IndicatedPleaUpdated.class, + InheritedPlea.class); private ObjectMapper objectMapper = new ObjectMapperProducer().objectMapper(); @InjectMocks private UpdatePleaCommandHandler hearingCommandHandler; @@ -596,4 +599,166 @@ private Set createGuiltyPleaTypes() { guiltyPleaTypes.add(GUILTY); return guiltyPleaTypes; } + + @Test + public void updateInheritPleaAndSetConvictionDateWhenGuilty() throws Throwable { + final InitiateHearingCommandHelper hearingHelper = h(standardInitiateHearingTemplate()); + final UUID hearingId = hearingHelper.getHearingId(); + final UUID offenceId = hearingHelper.getFirstOffenceForFirstDefendantForFirstCase().getId(); + final LocalDate pleaDate = PAST_LOCAL_DATE.next(); + + final UpdateInheritedPleaCommand command = new UpdateInheritedPleaCommand(); + command.setHearingIds(asList(hearingId)); + command.setPlea(Plea.plea() + .withOffenceId(offenceId) + .withPleaValue(GUILTY) + .withPleaDate(pleaDate) + .withOriginatingHearingId(randomUUID()) + .build()); + + final HearingAggregate hearingAggregate = new HearingAggregate() {{ + apply(new HearingInitiated(hearingHelper.getHearing())); + }}; + + when(this.eventSource.getStreamById(hearingId)).thenReturn(this.hearingAggregateEventStream); + when(this.aggregateService.get(this.hearingAggregateEventStream, HearingAggregate.class)).thenReturn(hearingAggregate); + when(this.referenceDataService.retrieveGuiltyPleaTypes()).thenReturn(guiltyPleaTypes); + + final JsonEnvelope envelope = envelopeFrom(metadataWithRandomUUID("hearing.command.enrich-update-plea-with-associated-hearings"), + objectToJsonObjectConverter.convert(command)); + + this.hearingCommandHandler.updateInheritPlea(envelope); + + final List events = verifyAppendAndGetArgumentFrom(this.hearingAggregateEventStream).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0).metadata().name(), is("hearing.events.inherited-plea")); + assertThat(events.get(1).metadata().name(), is("hearing.conviction-date-added")); + assertThat(asPojo(events.get(1), ConvictionDateAdded.class), isBean(ConvictionDateAdded.class) + .with(ConvictionDateAdded::getOffenceId, is(offenceId)) + .with(ConvictionDateAdded::getHearingId, is(hearingId)) + .with(ConvictionDateAdded::getConvictionDate, is(pleaDate))); + } + + @Test + public void updateInheritPleaAndRemoveConvictionDateWhenNotGuilty() throws Throwable { + final InitiateHearingCommandHelper hearingHelper = h(standardInitiateHearingTemplate()); + final UUID hearingId = hearingHelper.getHearingId(); + final UUID offenceId = hearingHelper.getFirstOffenceForFirstDefendantForFirstCase().getId(); + hearingHelper.getFirstOffenceForFirstDefendantForFirstCase().setConvictionDate(PAST_LOCAL_DATE.next()); + + final UpdateInheritedPleaCommand command = new UpdateInheritedPleaCommand(); + command.setHearingIds(asList(hearingId)); + command.setPlea(Plea.plea() + .withOffenceId(offenceId) + .withPleaValue(NOT_GUILTY) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withOriginatingHearingId(randomUUID()) + .build()); + + final HearingAggregate hearingAggregate = new HearingAggregate() {{ + apply(new HearingInitiated(hearingHelper.getHearing())); + }}; + + when(this.eventSource.getStreamById(hearingId)).thenReturn(this.hearingAggregateEventStream); + when(this.aggregateService.get(this.hearingAggregateEventStream, HearingAggregate.class)).thenReturn(hearingAggregate); + when(this.referenceDataService.retrieveGuiltyPleaTypes()).thenReturn(guiltyPleaTypes); + + final JsonEnvelope envelope = envelopeFrom(metadataWithRandomUUID("hearing.command.enrich-update-plea-with-associated-hearings"), + objectToJsonObjectConverter.convert(command)); + + this.hearingCommandHandler.updateInheritPlea(envelope); + + final List events = verifyAppendAndGetArgumentFrom(this.hearingAggregateEventStream).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0).metadata().name(), is("hearing.events.inherited-plea")); + assertThat(events.get(1).metadata().name(), is("hearing.conviction-date-removed")); + assertThat(asPojo(events.get(1), ConvictionDateRemoved.class), isBean(ConvictionDateRemoved.class) + .with(ConvictionDateRemoved::getOffenceId, is(offenceId)) + .with(ConvictionDateRemoved::getHearingId, is(hearingId))); + } + + @Test + public void updateInheritPleaOnlyRaisesInheritedPleaWhenNotGuiltyWithoutConvictionDate() throws Throwable { + final InitiateHearingCommandHelper hearingHelper = h(standardInitiateHearingTemplate()); + final UUID hearingId = hearingHelper.getHearingId(); + final UUID offenceId = hearingHelper.getFirstOffenceForFirstDefendantForFirstCase().getId(); + + final UpdateInheritedPleaCommand command = new UpdateInheritedPleaCommand(); + command.setHearingIds(asList(hearingId)); + command.setPlea(Plea.plea() + .withOffenceId(offenceId) + .withPleaValue(NOT_GUILTY) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withOriginatingHearingId(randomUUID()) + .build()); + + final HearingAggregate hearingAggregate = new HearingAggregate() {{ + apply(new HearingInitiated(hearingHelper.getHearing())); + }}; + + when(this.eventSource.getStreamById(hearingId)).thenReturn(this.hearingAggregateEventStream); + when(this.aggregateService.get(this.hearingAggregateEventStream, HearingAggregate.class)).thenReturn(hearingAggregate); + when(this.referenceDataService.retrieveGuiltyPleaTypes()).thenReturn(guiltyPleaTypes); + + final JsonEnvelope envelope = envelopeFrom(metadataWithRandomUUID("hearing.command.enrich-update-plea-with-associated-hearings"), + objectToJsonObjectConverter.convert(command)); + + this.hearingCommandHandler.updateInheritPlea(envelope); + + final List events = verifyAppendAndGetArgumentFrom(this.hearingAggregateEventStream).collect(Collectors.toList()); + + assertThat(events.size(), is(1)); + assertThat(events.get(0).metadata().name(), is("hearing.events.inherited-plea")); + } + + @Test + public void updateInheritPleaAppliesConvictionDateToAllAssociatedHearings() throws Throwable { + final InitiateHearingCommandHelper firstHearingHelper = h(standardInitiateHearingTemplate()); + final InitiateHearingCommandHelper secondHearingHelper = h(standardInitiateHearingTemplate()); + final UUID firstHearingId = firstHearingHelper.getHearingId(); + final UUID secondHearingId = secondHearingHelper.getHearingId(); + final UUID offenceId = firstHearingHelper.getFirstOffenceForFirstDefendantForFirstCase().getId(); + secondHearingHelper.getFirstOffenceForFirstDefendantForFirstCase().setId(offenceId); + + final LocalDate pleaDate = PAST_LOCAL_DATE.next(); + final UpdateInheritedPleaCommand command = new UpdateInheritedPleaCommand(); + command.setHearingIds(Lists.newArrayList(firstHearingId, secondHearingId)); + command.setPlea(Plea.plea() + .withOffenceId(offenceId) + .withPleaValue(GUILTY) + .withPleaDate(pleaDate) + .withOriginatingHearingId(randomUUID()) + .build()); + + final HearingAggregate firstHearingAggregate = new HearingAggregate() {{ + apply(new HearingInitiated(firstHearingHelper.getHearing())); + }}; + final HearingAggregate secondHearingAggregate = new HearingAggregate() {{ + apply(new HearingInitiated(secondHearingHelper.getHearing())); + }}; + + when(this.eventSource.getStreamById(firstHearingId)).thenReturn(this.hearingAggregateEventStream); + when(this.eventSource.getStreamById(secondHearingId)).thenReturn(this.offenceAggregateEventStream); + when(this.aggregateService.get(this.hearingAggregateEventStream, HearingAggregate.class)).thenReturn(firstHearingAggregate); + when(this.aggregateService.get(this.offenceAggregateEventStream, HearingAggregate.class)).thenReturn(secondHearingAggregate); + when(this.referenceDataService.retrieveGuiltyPleaTypes()).thenReturn(guiltyPleaTypes); + + final JsonEnvelope envelope = envelopeFrom(metadataWithRandomUUID("hearing.command.enrich-update-plea-with-associated-hearings"), + objectToJsonObjectConverter.convert(command)); + + this.hearingCommandHandler.updateInheritPlea(envelope); + + final List firstHearingEvents = verifyAppendAndGetArgumentFrom(this.hearingAggregateEventStream).collect(Collectors.toList()); + final List secondHearingEvents = verifyAppendAndGetArgumentFrom(this.offenceAggregateEventStream).collect(Collectors.toList()); + + assertThat(firstHearingEvents.size(), is(2)); + assertThat(firstHearingEvents.get(0).metadata().name(), is("hearing.events.inherited-plea")); + assertThat(firstHearingEvents.get(1).metadata().name(), is("hearing.conviction-date-added")); + + assertThat(secondHearingEvents.size(), is(2)); + assertThat(secondHearingEvents.get(0).metadata().name(), is("hearing.events.inherited-plea")); + assertThat(secondHearingEvents.get(1).metadata().name(), is("hearing.conviction-date-added")); + } } diff --git a/hearing-command/pom.xml b/hearing-command/pom.xml index df3f3f2ea..aae5f9275 100644 --- a/hearing-command/pom.xml +++ b/hearing-command/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-command pom diff --git a/hearing-common/pom.xml b/hearing-common/pom.xml index 56b547564..fbbb3d55c 100644 --- a/hearing-common/pom.xml +++ b/hearing-common/pom.xml @@ -3,7 +3,7 @@ hearing-parent uk.gov.moj.cpp.hearing - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 diff --git a/hearing-domain/hearing-domain-aggregate/pom.xml b/hearing-domain/hearing-domain-aggregate/pom.xml index cb6ea76dc..60c6e4270 100644 --- a/hearing-domain/hearing-domain-aggregate/pom.xml +++ b/hearing-domain/hearing-domain-aggregate/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-domain - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-domain-aggregate diff --git a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregate.java b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregate.java index ca30505f4..1bebfcdb9 100644 --- a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregate.java +++ b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregate.java @@ -602,12 +602,12 @@ public Stream updatePlea(final UUID hearingId, final PleaModel plea, fin return apply(pleaDelegate.updatePlea(hearingId, plea, guiltyPleaTypes)); } - public Stream inheritPlea(final UUID hearingId, final Plea plea) { + public Stream inheritPlea(final UUID hearingId, final Plea plea, final Set guiltyPleaTypes) { if (this.momento.isDeletedOrDuplicated() || SHARED == this.hearingState || checkIfHearingDateHasPassedPleaDate(plea.getPleaDate())) { return warnEventIgnored(hearingId, "inheritPlea"); } - return apply(this.pleaDelegate.inheritPlea(hearingId, plea)); + return apply(this.pleaDelegate.inheritPlea(hearingId, plea, guiltyPleaTypes)); } public Stream updateHearingWithIndicatedPlea(final UUID hearingId, final IndicatedPlea indicatedPlea) { diff --git a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java index 83206d3f8..95517037a 100644 --- a/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java +++ b/hearing-domain/hearing-domain-aggregate/src/main/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegate.java @@ -100,10 +100,30 @@ public void handlePleaUpsert(final PleaUpsert pleaUpsert) { - public Stream inheritPlea(final UUID hearingId, final Plea plea) { - return Stream.of(InheritedPlea.inheritedPlea() + public Stream inheritPlea(final UUID hearingId, final Plea plea, final Set guiltyPleaTypes) { + final List events = new ArrayList<>(); + events.add(InheritedPlea.inheritedPlea() .setHearingId(hearingId) .setPlea(plea)); + + if (!isCivilCase() && nonNull(plea)) { + final UUID offenceId = plea.getOffenceId(); + final UUID prosecutionCaseId = ofNullable(this.momento.getHearing().getProsecutionCases()).map(Collection::stream).orElseGet(Stream::empty) + .filter(pc -> pc.getDefendants().stream() + .flatMap(de -> de.getOffences().stream()) + .anyMatch(o -> o.getId().equals(offenceId))) + .findFirst() + .map(ProsecutionCase::getId) + .orElse(null); + + final UUID courtApplicationId = findCourtApplicationByOffence(offenceId); + + if (prosecutionCaseId != null || courtApplicationId != null) { + addConvictionDateEventForPlea(hearingId, guiltyPleaTypes, offenceId, prosecutionCaseId, courtApplicationId, events, plea); + } + } + + return events.stream(); } public Stream indicatedPlea(final UUID hearingId, final IndicatedPlea indicatedPlea) { diff --git a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregateTest.java b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregateTest.java index 5bd1131fb..ca8d333bc 100644 --- a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregateTest.java +++ b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/HearingAggregateTest.java @@ -51,6 +51,7 @@ import static uk.gov.moj.cpp.hearing.test.TestTemplates.initiateDefendantCommandTemplate; import static uk.gov.moj.cpp.hearing.test.TestUtilities.asList; import static uk.gov.moj.cpp.hearing.test.TestUtilities.with; +import static uk.gov.moj.cpp.hearing.domain.aggregate.util.PleaTypeUtil.guiltyPleaTypes; import uk.gov.justice.core.courts.CourtCentre; import uk.gov.justice.core.courts.CustodyTimeLimit; @@ -98,6 +99,7 @@ import uk.gov.moj.cpp.hearing.domain.aggregate.hearing.HearingAggregateMomento; import uk.gov.moj.cpp.hearing.domain.event.BookProvisionalHearingSlots; import uk.gov.moj.cpp.hearing.domain.event.CaseDefendantsUpdatedForHearing; +import uk.gov.moj.cpp.hearing.domain.event.ConvictionDateAdded; import uk.gov.moj.cpp.hearing.domain.event.CustodyTimeLimitClockStopped; import uk.gov.moj.cpp.hearing.domain.event.DefenceCounselAdded; import uk.gov.moj.cpp.hearing.domain.event.DefenceCounselChangeIgnored; @@ -291,12 +293,17 @@ void shouldInitiateHearingWithAllResultsCleanedUp() { @Test void shouldInitiateHearingOffencePlea() { + final InitiateHearingCommand initiateHearingCommand = standardInitiateHearingTemplate(); + HEARING_AGGREGATE.apply(new HearingInitiated(initiateHearingCommand.getHearing())); + + final UUID offenceId = initiateHearingCommand.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0).getId(); + final LocalDate pleaDate = PAST_LOCAL_DATE.next(); final UpdateHearingWithInheritedPleaCommand command = new UpdateHearingWithInheritedPleaCommand( randomUUID(), Plea.plea() .withPleaValue(GUILTY) - .withPleaDate(PAST_LOCAL_DATE.next()) - .withOffenceId(randomUUID()) + .withPleaDate(pleaDate) + .withOffenceId(offenceId) .withOriginatingHearingId(randomUUID()) .withDelegatedPowers(DelegatedPowers.delegatedPowers() .withUserId(randomUUID()) @@ -304,11 +311,10 @@ void shouldInitiateHearingOffencePlea() { .withLastName(STRING.next()) .build()) .build()); - final InitiateHearingCommand initiateHearingCommand = standardInitiateHearingTemplate(); - HEARING_AGGREGATE.apply(new HearingInitiated(initiateHearingCommand.getHearing())); - final InheritedPlea event = (InheritedPlea) HEARING_AGGREGATE.inheritPlea(initiateHearingCommand.getHearing().getId(), command.getPlea()).collect(Collectors.toList()).get(0); + final List events = HEARING_AGGREGATE.inheritPlea(initiateHearingCommand.getHearing().getId(), command.getPlea(), guiltyPleaTypes()).collect(Collectors.toList()); + final InheritedPlea event = (InheritedPlea) events.get(0); assertThat(event.getHearingId(), is(initiateHearingCommand.getHearing().getId())); assertThat(event.getPlea().getOffenceId(), is(command.getPlea().getOffenceId())); assertThat(event.getPlea().getPleaDate(), is(command.getPlea().getPleaDate())); @@ -316,6 +322,61 @@ void shouldInitiateHearingOffencePlea() { assertThat(event.getPlea().getDelegatedPowers().getUserId(), is(command.getPlea().getDelegatedPowers().getUserId())); assertThat(event.getPlea().getDelegatedPowers().getFirstName(), is(command.getPlea().getDelegatedPowers().getFirstName())); assertThat(event.getPlea().getDelegatedPowers().getLastName(), is(command.getPlea().getDelegatedPowers().getLastName())); + + final ConvictionDateAdded convictionDateAdded = (ConvictionDateAdded) events.get(1); + assertThat(convictionDateAdded.getHearingId(), is(initiateHearingCommand.getHearing().getId())); + assertThat(convictionDateAdded.getOffenceId(), is(offenceId)); + assertThat(convictionDateAdded.getConvictionDate(), is(pleaDate)); + } + + @Test + void shouldRemoveConvictionDateWhenInheritingNotGuiltyPlea() { + final InitiateHearingCommand initiateHearingCommand = standardInitiateHearingTemplate(); + final UUID offenceId = initiateHearingCommand.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0).getId(); + final LocalDate existingConvictionDate = PAST_LOCAL_DATE.next(); + initiateHearingCommand.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0) + .setConvictionDate(existingConvictionDate); + + final HearingAggregate hearingAggregate = new HearingAggregate(); + hearingAggregate.apply(new HearingInitiated(initiateHearingCommand.getHearing())); + + final LocalDate pleaDate = PAST_LOCAL_DATE.next(); + final Plea plea = Plea.plea() + .withPleaValue(NOT_GUILTY) + .withPleaDate(pleaDate) + .withOffenceId(offenceId) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = hearingAggregate.inheritPlea(initiateHearingCommand.getHearing().getId(), plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0), instanceOf(InheritedPlea.class)); + assertThat(events.get(1), instanceOf(uk.gov.moj.cpp.hearing.domain.event.ConvictionDateRemoved.class)); + + final uk.gov.moj.cpp.hearing.domain.event.ConvictionDateRemoved convictionDateRemoved = + (uk.gov.moj.cpp.hearing.domain.event.ConvictionDateRemoved) events.get(1); + assertThat(convictionDateRemoved.getHearingId(), is(initiateHearingCommand.getHearing().getId())); + assertThat(convictionDateRemoved.getOffenceId(), is(offenceId)); + } + + @Test + void shouldOnlyRaiseInheritedPleaWhenInheritingNotGuiltyWithoutConvictionDate() { + final InitiateHearingCommand initiateHearingCommand = standardInitiateHearingTemplate(); + HEARING_AGGREGATE.apply(new HearingInitiated(initiateHearingCommand.getHearing())); + + final UUID offenceId = initiateHearingCommand.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0).getId(); + final Plea plea = Plea.plea() + .withPleaValue(NOT_GUILTY) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withOffenceId(offenceId) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = HEARING_AGGREGATE.inheritPlea(initiateHearingCommand.getHearing().getId(), plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(1)); + assertThat(events.get(0), instanceOf(InheritedPlea.class)); } @Test @@ -337,7 +398,7 @@ void shouldNotInitiateHearingOffencePleaWhenHearingDateHasPassedPleaDate() { final InitiateHearingCommand initiateHearingCommand = standardInitiateHearingTemplate(); HEARING_AGGREGATE.apply(new HearingInitiated(initiateHearingCommand.getHearing())); - final Stream results = HEARING_AGGREGATE.inheritPlea(initiateHearingCommand.getHearing().getId(), command.getPlea()); + final Stream results = HEARING_AGGREGATE.inheritPlea(initiateHearingCommand.getHearing().getId(), command.getPlea(), guiltyPleaTypes()); assertTrue(results.findAny().isEmpty(), "Should return empty stream for shared hearing state"); @@ -391,7 +452,7 @@ void shouldNotRaiseInheritedPleaEventWhenInheritPleaCalledWithHearingResultShare hearingAggregate.apply(ResultsShared.builder().withHearing(Hearing.hearing().withId(randomUUID()).build()).build()); - final Stream eventStream = hearingAggregate.inheritPlea(hearingId, plea); + final Stream eventStream = hearingAggregate.inheritPlea(hearingId, plea, guiltyPleaTypes()); final List events = eventStream.collect(Collectors.toList()); assertThat(events.size(), is(0)); diff --git a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java index 581734988..8e87e292a 100644 --- a/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java +++ b/hearing-domain/hearing-domain-aggregate/src/test/java/uk/gov/moj/cpp/hearing/domain/aggregate/hearing/PleaDelegateTest.java @@ -4,6 +4,7 @@ import static java.util.Collections.*; import static java.util.Optional.ofNullable; import static java.util.UUID.randomUUID; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; @@ -722,6 +723,218 @@ public void shouldRaiseIndicatedPleaUpdated() { assertThat(indicatedPleaUpdated.getHearingId(), is(HEARING_ID)); } + @Test + public void shouldAddConvictionDateWhenInheritingGuiltyPlea() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + this.hearingAggregateMomento.setHearing(hearing); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + final ConvictionDateAdded convictionDateAdded = (ConvictionDateAdded) events.get(1); + assertThat(convictionDateAdded.getOffenceId(), is(OFFENCE_ID)); + assertThat(convictionDateAdded.getHearingId(), is(HEARING_ID)); + assertThat(convictionDateAdded.getCaseId(), is(CASE_ID)); + assertThat(convictionDateAdded.getConvictionDate(), is(NEW_PLEA_DATE)); + } + + @Test + public void shouldAddConvictionDateWhenInheritingEachGuiltyPleaType() { + GUILTY_PLEA_LIST.forEach(guiltyPleaValue -> { + final UUID offenceId = randomUUID(); + final UUID hearingId = randomUUID(); + final UUID caseId = randomUUID(); + final UUID defendantId = randomUUID(); + this.hearingAggregateMomento.setHearing(getHearing(offenceId, defendantId, caseId, hearingId)); + + final Plea plea = Plea.plea() + .withOffenceId(offenceId) + .withPleaValue(guiltyPleaValue) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(hearingId, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + final ConvictionDateAdded convictionDateAdded = (ConvictionDateAdded) events.get(1); + assertThat(convictionDateAdded.getOffenceId(), is(offenceId)); + assertThat(convictionDateAdded.getHearingId(), is(hearingId)); + assertThat(convictionDateAdded.getCaseId(), is(caseId)); + assertThat(convictionDateAdded.getConvictionDate(), is(NEW_PLEA_DATE)); + }); + } + + @Test + public void shouldRemoveConvictionDateWhenInheritingNotGuiltyPlea() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID, NEW_PLEA_DATE); + this.hearingAggregateMomento.setHearing(hearing); + this.hearingAggregateMomento.getConvictionDates().put(OFFENCE_ID, NEW_PLEA_DATE); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(NOT_GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + assertThat(events.get(1), instanceOf(ConvictionDateRemoved.class)); + final ConvictionDateRemoved convictionDateRemoved = (ConvictionDateRemoved) events.get(1); + assertThat(convictionDateRemoved.getOffenceId(), is(OFFENCE_ID)); + assertThat(convictionDateRemoved.getHearingId(), is(HEARING_ID)); + assertThat(convictionDateRemoved.getCaseId(), is(CASE_ID)); + } + + @Test + public void shouldOnlyRaiseInheritedPleaWhenInheritingNotGuiltyWithoutExistingConvictionDate() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + this.hearingAggregateMomento.setHearing(hearing); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(NOT_GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(1)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + assertThat(events.stream().filter(ConvictionDateAdded.class::isInstance).count(), is(0L)); + assertThat(events.stream().filter(ConvictionDateRemoved.class::isInstance).count(), is(0L)); + } + + @Test + public void shouldNotAddConvictionDateWhenInheritingGuiltyPleaForCivilCase() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + hearing.getProsecutionCases().get(0).setIsCivil(true); + this.hearingAggregateMomento.setHearing(hearing); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(1)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + assertThat(events.stream().filter(ConvictionDateAdded.class::isInstance).count(), is(0L)); + } + + @Test + public void shouldAddConvictionDateWhenInheritingGuiltyPleaForCourtApplicationOffence() { + final Hearing hearing = getHearing(OFFENCE_ID, APPLICATION_ID, HEARING_ID); + this.hearingAggregateMomento.setHearing(hearing); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(2)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + final ConvictionDateAdded convictionDateAdded = (ConvictionDateAdded) events.get(1); + assertThat(convictionDateAdded.getOffenceId(), is(OFFENCE_ID)); + assertThat(convictionDateAdded.getHearingId(), is(HEARING_ID)); + assertThat(convictionDateAdded.getCourtApplicationId(), is(APPLICATION_ID)); + assertThat(convictionDateAdded.getConvictionDate(), is(NEW_PLEA_DATE)); + } + + @Test + public void shouldOnlyRaiseInheritedPleaWhenOffenceNotPresentOnHearing() { + final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); + this.hearingAggregateMomento.setHearing(hearing); + + final Plea plea = Plea.plea() + .withOffenceId(randomUUID()) + .withPleaValue(GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + final List events = pleaDelegate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + assertThat(events.size(), is(1)); + assertThat(events.get(0), instanceOf(uk.gov.moj.cpp.hearing.domain.event.InheritedPlea.class)); + assertThat(events.stream().filter(ConvictionDateAdded.class::isInstance).count(), is(0L)); + } + + @Test + public void shouldSyncAggregateConvictionDateWhenInheritedGuiltyPleaEventsAreApplied() throws Exception { + final Hearing hearing = hearingReadyForInherit(getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID)); + final HearingAggregate hearingAggregate = new HearingAggregate(); + hearingAggregate.initiate(hearing).forEach(hearingAggregate::apply); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + hearingAggregate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + final HearingAggregateMomento momento = getMemonto(hearingAggregate); + assertThat(momento.getPleas().get(OFFENCE_ID).getPleaValue(), is(GUILTY)); + assertThat(momento.getConvictionDates().get(OFFENCE_ID), is(NEW_PLEA_DATE)); + assertThat(hearingAggregate.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0).getConvictionDate(), + is(NEW_PLEA_DATE)); + } + + @Test + public void shouldSyncAggregateConvictionDateRemovalWhenInheritedNotGuiltyPleaEventsAreApplied() throws Exception { + final Hearing hearing = hearingReadyForInherit(getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID, NEW_PLEA_DATE)); + final HearingAggregate hearingAggregate = new HearingAggregate(); + hearingAggregate.initiate(hearing).forEach(hearingAggregate::apply); + + assertThat(getMemonto(hearingAggregate).getConvictionDates().get(OFFENCE_ID), is(NEW_PLEA_DATE)); + + final Plea plea = Plea.plea() + .withOffenceId(OFFENCE_ID) + .withPleaValue(NOT_GUILTY) + .withPleaDate(NEW_PLEA_DATE) + .withOriginatingHearingId(randomUUID()) + .build(); + + hearingAggregate.inheritPlea(HEARING_ID, plea, guiltyPleaTypes()).collect(Collectors.toList()); + + final HearingAggregateMomento momento = getMemonto(hearingAggregate); + assertThat(momento.getPleas().get(OFFENCE_ID).getPleaValue(), is(NOT_GUILTY)); + assertThat(momento.getConvictionDates().containsKey(OFFENCE_ID), is(false)); + assertThat(hearingAggregate.getHearing().getProsecutionCases().get(0).getDefendants().get(0).getOffences().get(0).getConvictionDate(), + is(nullValue())); + } + + private Hearing hearingReadyForInherit(final Hearing hearing) { + return hearing() + .withValuesFrom(hearing) + .withHearingDays(singletonList(uk.gov.justice.core.courts.HearingDay.hearingDay() + .withSittingDay(java.time.ZonedDateTime.of(NEW_PLEA_DATE.plusDays(30), java.time.LocalTime.of(10, 0), java.time.ZoneOffset.UTC)) + .build())) + .build(); + } + private void shouldAddConvictionDateAddedWhenPleaIsGuiltyType(String guiltyPleaValue) { final Hearing hearing = getHearing(OFFENCE_ID, DEFENDANT_ID, CASE_ID, HEARING_ID); shouldAddConvictionDateAddedWhenPleaIsGuiltyType(hearing, guiltyPleaValue); diff --git a/hearing-domain/hearing-domain-common/pom.xml b/hearing-domain/hearing-domain-common/pom.xml index 5eab8cbcc..b4f6d3de3 100644 --- a/hearing-domain/hearing-domain-common/pom.xml +++ b/hearing-domain/hearing-domain-common/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-domain - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-domain-common diff --git a/hearing-domain/hearing-domain-event/pom.xml b/hearing-domain/hearing-domain-event/pom.xml index c51d0da67..d2c1ae216 100644 --- a/hearing-domain/hearing-domain-event/pom.xml +++ b/hearing-domain/hearing-domain-event/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-domain - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-domain-event diff --git a/hearing-domain/hearing-domain-xhibit/pom.xml b/hearing-domain/hearing-domain-xhibit/pom.xml index 70cf313bf..cfd786910 100644 --- a/hearing-domain/hearing-domain-xhibit/pom.xml +++ b/hearing-domain/hearing-domain-xhibit/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-domain - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 diff --git a/hearing-domain/pom.xml b/hearing-domain/pom.xml index f1898d079..119ec1cfb 100644 --- a/hearing-domain/pom.xml +++ b/hearing-domain/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-domain pom diff --git a/hearing-event-sources/pom.xml b/hearing-event-sources/pom.xml index caeaa7b18..6c9462fb7 100644 --- a/hearing-event-sources/pom.xml +++ b/hearing-event-sources/pom.xml @@ -3,7 +3,7 @@ hearing-parent uk.gov.moj.cpp.hearing - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT ../pom.xml 4.0.0 diff --git a/hearing-event/hearing-event-listener/pom.xml b/hearing-event/hearing-event-listener/pom.xml index 1fbababc9..49b6ff092 100644 --- a/hearing-event/hearing-event-listener/pom.xml +++ b/hearing-event/hearing-event-listener/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-event - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-event-listener war diff --git a/hearing-event/hearing-event-listener/src/main/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListener.java b/hearing-event/hearing-event-listener/src/main/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListener.java index 558853fac..bc789a9f2 100644 --- a/hearing-event/hearing-event-listener/src/main/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListener.java +++ b/hearing-event/hearing-event-listener/src/main/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListener.java @@ -64,10 +64,6 @@ @SuppressWarnings({"squid:S2201", "squid:S134"}) @ServiceComponent(EVENT_LISTENER) public class InitiateHearingEventListener { - private static final String GUILTY = "GUILTY"; - - private static final String CHANGE_TO_GUILTY_MAGISTRATES_COURT = "CHANGE_TO_GUILTY_MAGISTRATES_COURT"; - private static final Logger LOGGER = LoggerFactory.getLogger(InitiateHearingEventListener.class.getName()); @Inject @@ -356,8 +352,6 @@ public void hearingInitiatedPleaData(final JsonEnvelope envelop) { if (shouldSetPlea) { offence.setPlea(pleaJPAMapper.toJPA(event.getPlea())); - final boolean IS_GUILTY_PLEA = GUILTY.equals(event.getPlea().getPleaValue()) || CHANGE_TO_GUILTY_MAGISTRATES_COURT.equals(event.getPlea().getPleaValue()); - offence.setConvictionDate(IS_GUILTY_PLEA ? event.getPlea().getPleaDate() : null); offenceRepository.save(offence); } } diff --git a/hearing-event/hearing-event-listener/src/test/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListenerTest.java b/hearing-event/hearing-event-listener/src/test/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListenerTest.java index ac37b4b3c..f5adc438c 100644 --- a/hearing-event/hearing-event-listener/src/test/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListenerTest.java +++ b/hearing-event/hearing-event-listener/src/test/java/uk/gov/moj/cpp/hearing/event/listener/InitiateHearingEventListenerTest.java @@ -1138,7 +1138,7 @@ public void testHearingInitiatedPleaData() { assertThat(offence, isBean(Offence.class) .with(Offence::getId, is(snapshotKey)) - .with(Offence::getConvictionDate, is(pleaPojo.getPleaDate())) + .with(Offence::getConvictionDate, is(convictionDate)) .with(Offence::getPlea, isBean(Plea.class) .with(Plea::getOriginatingHearingId, is(event.getPlea().getOriginatingHearingId())) .with(Plea::getPleaDate, is(event.getPlea().getPleaDate())) @@ -1153,7 +1153,7 @@ public void testHearingInitiatedPleaData() { } @Test - public void convictionDateIsSetForChangeToGuiltyMagistrateCourt() { + public void convictionDateIsUnchangedForChangeToGuiltyMagistrateCourtOnInheritedPlea() { final uk.gov.justice.core.courts.DelegatedPowers delegatedPowersPojo = uk.gov.justice.core.courts.DelegatedPowers.delegatedPowers() .withUserId(randomUUID()) @@ -1200,7 +1200,7 @@ public void convictionDateIsSetForChangeToGuiltyMagistrateCourt() { assertThat(offence, isBean(Offence.class) .with(Offence::getId, is(snapshotKey)) - .with(Offence::getConvictionDate, is(pleaPojo.getPleaDate())) + .with(Offence::getConvictionDate, is(convictionDate)) .with(Offence::getPlea, isBean(Plea.class) .with(Plea::getOriginatingHearingId, is(event.getPlea().getOriginatingHearingId())) .with(Plea::getPleaDate, is(event.getPlea().getPleaDate())) @@ -1214,6 +1214,89 @@ public void convictionDateIsSetForChangeToGuiltyMagistrateCourt() { ); } + @Test + public void inheritedPleaListenerDoesNotSetConvictionDateWhenOffenceHasNoConvictionDate() { + + final uk.gov.justice.core.courts.DelegatedPowers delegatedPowersPojo = uk.gov.justice.core.courts.DelegatedPowers.delegatedPowers() + .withUserId(randomUUID()) + .withFirstName(STRING.next()) + .withLastName(STRING.next()) + .build(); + final uk.gov.justice.core.courts.Plea pleaPojo = uk.gov.justice.core.courts.Plea.plea() + .withOffenceId(randomUUID()) + .withOriginatingHearingId(randomUUID()) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withPleaValue(GUILTY) + .withDelegatedPowers(delegatedPowersPojo) + .build(); + + final InheritedPlea event = new InheritedPlea() + .setHearingId(randomUUID()) + .setPlea(pleaPojo); + + final HearingSnapshotKey snapshotKey = new HearingSnapshotKey(event.getPlea().getOffenceId(), event.getHearingId()); + + final Offence offence = new Offence(); + offence.setId(snapshotKey); + offence.setConvictionDate(null); + when(offenceRepository.findBy(snapshotKey)).thenReturn(offence); + + final Plea plea = new Plea(); + plea.setPleaValue(pleaPojo.getPleaValue()); + plea.setPleaDate(pleaPojo.getPleaDate()); + plea.setOriginatingHearingId(pleaPojo.getOriginatingHearingId()); + when(pleaJPAMapper.toJPA(Mockito.any())).thenReturn(plea); + + initiateHearingEventListener.hearingInitiatedPleaData(envelopeFrom(metadataWithRandomUUID("hearing.events.inherited-plea"), + objectToJsonObjectConverter.convert(event))); + + verify(this.offenceRepository).save(offence); + assertThat(offence.getConvictionDate(), is(nullValue())); + assertThat(offence.getPlea().getPleaValue(), is(GUILTY)); + } + + @Test + public void inheritedPleaListenerDoesNotClearConvictionDateForNotGuiltyPlea() { + + final uk.gov.justice.core.courts.DelegatedPowers delegatedPowersPojo = uk.gov.justice.core.courts.DelegatedPowers.delegatedPowers() + .withUserId(randomUUID()) + .withFirstName(STRING.next()) + .withLastName(STRING.next()) + .build(); + final uk.gov.justice.core.courts.Plea pleaPojo = uk.gov.justice.core.courts.Plea.plea() + .withOffenceId(randomUUID()) + .withOriginatingHearingId(randomUUID()) + .withPleaDate(PAST_LOCAL_DATE.next()) + .withPleaValue("NOT_GUILTY") + .withDelegatedPowers(delegatedPowersPojo) + .build(); + + final InheritedPlea event = new InheritedPlea() + .setHearingId(randomUUID()) + .setPlea(pleaPojo); + + final HearingSnapshotKey snapshotKey = new HearingSnapshotKey(event.getPlea().getOffenceId(), event.getHearingId()); + + final Offence offence = new Offence(); + offence.setId(snapshotKey); + final LocalDate existingConvictionDate = PAST_LOCAL_DATE.next(); + offence.setConvictionDate(existingConvictionDate); + when(offenceRepository.findBy(snapshotKey)).thenReturn(offence); + + final Plea plea = new Plea(); + plea.setPleaValue(pleaPojo.getPleaValue()); + plea.setPleaDate(pleaPojo.getPleaDate()); + plea.setOriginatingHearingId(pleaPojo.getOriginatingHearingId()); + when(pleaJPAMapper.toJPA(Mockito.any())).thenReturn(plea); + + initiateHearingEventListener.hearingInitiatedPleaData(envelopeFrom(metadataWithRandomUUID("hearing.events.inherited-plea"), + objectToJsonObjectConverter.convert(event))); + + verify(this.offenceRepository).save(offence); + assertThat(offence.getConvictionDate(), is(existingConvictionDate)); + assertThat(offence.getPlea().getPleaValue(), is("NOT_GUILTY")); + } + private JsonEnvelope getInitiateHearingJsonEnvelope(final uk.gov.justice.core.courts.Hearing hearing) { final InitiateHearingCommand document = new InitiateHearingCommand(hearing); diff --git a/hearing-event/hearing-event-processor/pom.xml b/hearing-event/hearing-event-processor/pom.xml index 825149152..564e3a7f2 100644 --- a/hearing-event/hearing-event-processor/pom.xml +++ b/hearing-event/hearing-event-processor/pom.xml @@ -3,7 +3,7 @@ hearing-event uk.gov.moj.cpp.hearing - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 war diff --git a/hearing-event/pom.xml b/hearing-event/pom.xml index f1f59f6b6..ae291ca4c 100644 --- a/hearing-event/pom.xml +++ b/hearing-event/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-event pom diff --git a/hearing-healthchecks/pom.xml b/hearing-healthchecks/pom.xml index 885f66251..2beb32ca4 100644 --- a/hearing-healthchecks/pom.xml +++ b/hearing-healthchecks/pom.xml @@ -3,7 +3,7 @@ hearing-parent uk.gov.moj.cpp.hearing - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 diff --git a/hearing-integration-test/pom.xml b/hearing-integration-test/pom.xml index bbcbc3e7c..a9cbf37a8 100644 --- a/hearing-integration-test/pom.xml +++ b/hearing-integration-test/pom.xml @@ -5,7 +5,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-integration-test diff --git a/hearing-json/pom.xml b/hearing-json/pom.xml index 537d42a7d..daf4352dd 100644 --- a/hearing-json/pom.xml +++ b/hearing-json/pom.xml @@ -3,7 +3,7 @@ hearing-parent uk.gov.moj.cpp.hearing - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 diff --git a/hearing-query/hearing-query-api/pom.xml b/hearing-query/hearing-query-api/pom.xml index 83c4a6d30..09f536524 100644 --- a/hearing-query/hearing-query-api/pom.xml +++ b/hearing-query/hearing-query-api/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-query - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-query-api war diff --git a/hearing-query/hearing-query-view/pom.xml b/hearing-query/hearing-query-view/pom.xml index e9a61480e..664003bf6 100644 --- a/hearing-query/hearing-query-view/pom.xml +++ b/hearing-query/hearing-query-view/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-query - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-query-view jar diff --git a/hearing-query/pom.xml b/hearing-query/pom.xml index fb789a75c..9db735ff8 100644 --- a/hearing-query/pom.xml +++ b/hearing-query/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-query pom diff --git a/hearing-service/pom.xml b/hearing-service/pom.xml index d2e54c2d4..e3cd66bbc 100644 --- a/hearing-service/pom.xml +++ b/hearing-service/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT 4.0.0 diff --git a/hearing-viewstore/hearing-viewstore-liquibase/pom.xml b/hearing-viewstore/hearing-viewstore-liquibase/pom.xml index aa2f55031..5a8d3cb75 100644 --- a/hearing-viewstore/hearing-viewstore-liquibase/pom.xml +++ b/hearing-viewstore/hearing-viewstore-liquibase/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-viewstore - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-viewstore-liquibase diff --git a/hearing-viewstore/hearing-viewstore-persistence/pom.xml b/hearing-viewstore/hearing-viewstore-persistence/pom.xml index 7ed6c1edd..9747bc6d5 100644 --- a/hearing-viewstore/hearing-viewstore-persistence/pom.xml +++ b/hearing-viewstore/hearing-viewstore-persistence/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-viewstore - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-viewstore-persistence diff --git a/hearing-viewstore/pom.xml b/hearing-viewstore/pom.xml index 930cb1e5a..b3904270c 100644 --- a/hearing-viewstore/pom.xml +++ b/hearing-viewstore/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT hearing-viewstore pom diff --git a/pojo-plugin/pom.xml b/pojo-plugin/pom.xml index 41c87235e..9d202281f 100644 --- a/pojo-plugin/pom.xml +++ b/pojo-plugin/pom.xml @@ -3,7 +3,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT pojo-plugin diff --git a/pom.xml b/pom.xml index 545b2bd61..f85cfb831 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT pom Hearing Context - Parent Module @@ -31,7 +31,7 @@ 17.103.95 17.0.1 17.104.81 - 17.0.275 + 17.0.279 2.2.11 2.6.3 5.7 diff --git a/test-utilities/pom.xml b/test-utilities/pom.xml index d7767b753..935a330a1 100644 --- a/test-utilities/pom.xml +++ b/test-utilities/pom.xml @@ -7,7 +7,7 @@ uk.gov.moj.cpp.hearing hearing-parent - 17.104.180-SNAPSHOT + 17.104.180-SNI-9204-SNAPSHOT