generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 2
HDPI-5180: Persist basic citizen General Application #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scottstewart-sl
wants to merge
13
commits into
master
Choose a base branch
from
HDPI-5180_gen_app_skeleton
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
060c9d5
HDPI-5180: Create basic event to persist a citizen General Application
scottstewart-sl 1b24de7
Merge branch 'master' into HDPI-5180_gen_app_skeleton
scottstewart-sl b1ea5fd
Merge remote-tracking branch 'origin/master' into HDPI-5180_gen_app_s…
scottstewart-sl 61c00ac
Merge remote-tracking branch 'origin/master' into HDPI-5180_gen_app_s…
scottstewart-sl a714589
Merge remote-tracking branch 'origin/master' into HDPI-5180_gen_app_s…
scottstewart-sl be62c02
HDPI-5180: Fix applicable states for citizen gen app event
scottstewart-sl 32ec663
HDPI-5180: Add initial state to gen app
scottstewart-sl 6f6a932
Merge branch 'master' into HDPI-5180_gen_app_skeleton
scottstewart-sl be34f62
Merge remote-tracking branch 'origin/master' into HDPI-5180_gen_app_s…
scottstewart-sl acb1e76
Merge branch 'HDPI-5180_gen_app_skeleton' of github.com:hmcts/pcs-api…
scottstewart-sl 94bb818
HDPI-5180: Update DB migration number
scottstewart-sl 707aae8
Merge remote-tracking branch 'origin/master' into HDPI-5180_gen_app_s…
scottstewart-sl f0b788f
HDPI-5180: Move GenAppType to genapp package
scottstewart-sl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/CitizenGenAppRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.domain.genapp; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Builder | ||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class CitizenGenAppRequest { | ||
|
|
||
| private GenAppType applicationType; | ||
|
|
||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/GenAppState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.domain.genapp; | ||
|
|
||
| public enum GenAppState { | ||
|
|
||
| PENDING_SUBMISSION, | ||
| SUBMITTED | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/genapp/GenAppType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.domain.genapp; | ||
|
|
||
| public enum GenAppType { | ||
|
|
||
| SUSPEND, | ||
| ADJOURN, | ||
| SET_ASIDE, | ||
| SOMETHING_ELSE | ||
|
|
||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/uk/gov/hmcts/reform/pcs/ccd/entity/GenAppEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.entity; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonBackReference; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.JoinColumn; | ||
| import jakarta.persistence.ManyToOne; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppType; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppState; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static jakarta.persistence.FetchType.EAGER; | ||
| import static jakarta.persistence.FetchType.LAZY; | ||
|
|
||
| @Entity | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Table(name = "general_application") | ||
| public class GenAppEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| private UUID id; | ||
|
|
||
| @ManyToOne(fetch = LAZY) | ||
| @JoinColumn(name = "case_id") | ||
| @JsonBackReference | ||
| private PcsCaseEntity pcsCase; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private GenAppType type; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private GenAppState state; | ||
|
|
||
| @ManyToOne(fetch = EAGER) | ||
| @JoinColumn(name = "party_id") | ||
| @JsonBackReference | ||
| private PartyEntity party; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/citizen/CitizenCreateGenApp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.event.citizen; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Component; | ||
| import uk.gov.hmcts.ccd.sdk.api.CCDConfig; | ||
| import uk.gov.hmcts.ccd.sdk.api.DecentralisedConfigBuilder; | ||
| import uk.gov.hmcts.ccd.sdk.api.EventPayload; | ||
| import uk.gov.hmcts.ccd.sdk.api.Permission; | ||
| import uk.gov.hmcts.ccd.sdk.api.callback.SubmitResponse; | ||
| import uk.gov.hmcts.reform.pcs.ccd.ShowConditions; | ||
| import uk.gov.hmcts.reform.pcs.ccd.accesscontrol.UserRole; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.State; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppState; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.repository.GenAppRepository; | ||
| import uk.gov.hmcts.reform.pcs.ccd.service.PcsCaseService; | ||
| import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService; | ||
| import uk.gov.hmcts.reform.pcs.security.SecurityContextService; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static uk.gov.hmcts.reform.pcs.ccd.event.EventId.citizenCreateGenApp; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @AllArgsConstructor | ||
| public class CitizenCreateGenApp implements CCDConfig<PCSCase, State, UserRole> { | ||
|
|
||
| private final PcsCaseService pcsCaseService; | ||
| private final PartyService partyService; | ||
| private final SecurityContextService securityContextService; | ||
| private final GenAppRepository genAppRepository; | ||
|
|
||
| @Override | ||
| public void configureDecentralised(DecentralisedConfigBuilder<PCSCase, State, UserRole> configBuilder) { | ||
| configBuilder | ||
| .decentralisedEvent(citizenCreateGenApp.name(), this::submit) | ||
| .forAllStates() // TODO: Adjust once target states are known and available | ||
| .name("Create a General Application") | ||
| .showCondition(ShowConditions.NEVER_SHOW) | ||
| .grant(Permission.CRUD, UserRole.DEFENDANT) | ||
| .showSummary(); | ||
| } | ||
|
|
||
| private SubmitResponse<State> submit(EventPayload<PCSCase, State> eventPayload) { | ||
| long caseReference = eventPayload.caseReference(); | ||
| PCSCase caseData = eventPayload.caseData(); | ||
|
|
||
| PcsCaseEntity pcsCaseEntity = pcsCaseService.loadCase(caseReference); | ||
|
|
||
| UUID currentUserId = securityContextService.getCurrentUserId(); | ||
| PartyEntity applicantParty = partyService.getPartyEntityByIdamId(currentUserId, caseReference); | ||
|
|
||
| CitizenGenAppRequest citizenCreateGenApp = caseData.getCitizenGenAppRequest(); | ||
|
|
||
| GenAppEntity genAppEntity = GenAppEntity.builder() | ||
| .type(citizenCreateGenApp.getApplicationType()) | ||
| .party(applicantParty) | ||
| .state(GenAppState.SUBMITTED) | ||
| .build(); | ||
|
|
||
| genAppRepository.save(genAppEntity); | ||
|
|
||
| pcsCaseEntity.addGenApp(genAppEntity); | ||
libanAbdirahman1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return SubmitResponse.<State>builder() | ||
| .build(); | ||
| } | ||
|
|
||
| } | ||
12 changes: 12 additions & 0 deletions
12
src/main/java/uk/gov/hmcts/reform/pcs/ccd/repository/GenAppRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Repository | ||
| public interface GenAppRepository extends JpaRepository<GenAppEntity, UUID> { | ||
|
|
||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/resources/db/migration/V072__general_application.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| CREATE TABLE general_application ( | ||
| id UUID PRIMARY KEY, | ||
| case_id UUID REFERENCES public.pcs_case (id), | ||
| type VARCHAR(50), | ||
| state VARCHAR(30), | ||
| party_id UUID REFERENCES public.party (id) | ||
| ) |
153 changes: 153 additions & 0 deletions
153
src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/citizen/CitizenCreateGenAppTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.event.citizen; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppType; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest; | ||
| import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppState; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.event.BaseEventTest; | ||
| import uk.gov.hmcts.reform.pcs.ccd.repository.GenAppRepository; | ||
| import uk.gov.hmcts.reform.pcs.ccd.service.PcsCaseService; | ||
| import uk.gov.hmcts.reform.pcs.ccd.service.party.PartyService; | ||
| import uk.gov.hmcts.reform.pcs.security.SecurityContextService; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.ArgumentMatchers.same; | ||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| @ExtendWith(MockitoExtension.class) | ||
| class CitizenCreateGenAppTest extends BaseEventTest { | ||
|
|
||
| @Mock | ||
| private PcsCaseService pcsCaseService; | ||
| @Mock | ||
| private PartyService partyService; | ||
| @Mock | ||
| private SecurityContextService securityContextService; | ||
| @Mock | ||
| private GenAppRepository genAppRepository; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| CitizenCreateGenApp underTest = new CitizenCreateGenApp(pcsCaseService, partyService, | ||
| securityContextService, genAppRepository); | ||
|
|
||
| setEventUnderTest(underTest); | ||
| } | ||
|
|
||
| @Nested | ||
| @DisplayName("Submit event tests") | ||
| class SubmitTests { | ||
|
|
||
| @Mock | ||
| private PcsCaseEntity pcsCaseEntity; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| given(pcsCaseService.loadCase(TEST_CASE_REFERENCE)).willReturn(pcsCaseEntity); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource(value = GenAppType.class) | ||
| void shouldSetGeneralApplicationType(GenAppType genAppType) { | ||
| // Given | ||
| CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder() | ||
| .applicationType(genAppType) | ||
| .build(); | ||
|
|
||
| PCSCase caseData = PCSCase.builder() | ||
| .citizenGenAppRequest(genAppRequest) | ||
| .build(); | ||
|
|
||
| // When | ||
| callSubmitHandler(caseData); | ||
|
|
||
| // Then | ||
| ArgumentCaptor<GenAppEntity> genAppEntityCaptor = ArgumentCaptor.forClass(GenAppEntity.class); | ||
| verify(genAppRepository).save(genAppEntityCaptor.capture()); | ||
|
|
||
| assertThat(genAppEntityCaptor.getValue().getType()).isEqualTo(genAppType); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSetInitialState() { | ||
| // Given | ||
| CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder() | ||
| .build(); | ||
|
|
||
| PCSCase caseData = PCSCase.builder() | ||
| .citizenGenAppRequest(genAppRequest) | ||
| .build(); | ||
|
|
||
| // When | ||
| callSubmitHandler(caseData); | ||
|
|
||
| // Then | ||
| ArgumentCaptor<GenAppEntity> genAppEntityCaptor = ArgumentCaptor.forClass(GenAppEntity.class); | ||
| verify(genAppRepository).save(genAppEntityCaptor.capture()); | ||
|
|
||
| assertThat(genAppEntityCaptor.getValue().getState()).isEqualTo(GenAppState.SUBMITTED); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSetApplicantParty() { | ||
| // Given | ||
| final PartyEntity applicantParty = mock(PartyEntity.class); | ||
|
|
||
| CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder() | ||
| .applicationType(GenAppType.SUSPEND) | ||
| .build(); | ||
|
|
||
| PCSCase caseData = PCSCase.builder() | ||
| .citizenGenAppRequest(genAppRequest) | ||
| .build(); | ||
|
|
||
| UUID currentUserId = UUID.randomUUID(); | ||
| given(securityContextService.getCurrentUserId()).willReturn(currentUserId); | ||
| given(partyService.getPartyEntityByIdamId(currentUserId, TEST_CASE_REFERENCE)).willReturn(applicantParty); | ||
|
|
||
| // When | ||
| callSubmitHandler(caseData); | ||
|
|
||
| // Then | ||
| ArgumentCaptor<GenAppEntity> genAppEntityCaptor = ArgumentCaptor.forClass(GenAppEntity.class); | ||
| verify(genAppRepository).save(genAppEntityCaptor.capture()); | ||
|
|
||
| assertThat(genAppEntityCaptor.getValue().getParty()).isEqualTo(applicantParty); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldCreateGenAppAndAddToCaseEntity() { | ||
| // Given | ||
| PCSCase caseData = PCSCase.builder() | ||
| .citizenGenAppRequest(CitizenGenAppRequest.builder().build()) | ||
| .build(); | ||
|
|
||
| // When | ||
| callSubmitHandler(caseData); | ||
|
|
||
| // Then | ||
| ArgumentCaptor<GenAppEntity> genAppEntityCaptor = ArgumentCaptor.forClass(GenAppEntity.class); | ||
| verify(genAppRepository).save(genAppEntityCaptor.capture()); | ||
|
|
||
| verify(pcsCaseEntity).addGenApp(same(genAppEntityCaptor.getValue())); | ||
| } | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.