-
Notifications
You must be signed in to change notification settings - Fork 2
HDPI-6510: Gen Apps supporting docs #1853
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
2
commits into
HDPI-4573_view_applications
Choose a base branch
from
HDPI-6510_applications_supporting_docs
base: HDPI-4573_view_applications
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
2 commits
Select commit
Hold shift + click to select a range
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentNameService.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,61 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.service.document; | ||
|
|
||
| import org.apache.commons.io.FilenameUtils; | ||
| import org.springframework.stereotype.Service; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.ClaimPartyEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyRole; | ||
| import uk.gov.hmcts.reform.pcs.exception.PartyNotFoundException; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Service | ||
| public class DocumentNameService { | ||
|
|
||
| public String appendGenAppPostfix(String originalFilename, | ||
| GenAppEntity genAppEntity, | ||
| ClaimEntity mainClaim, | ||
| UUID applicantPartyId) { | ||
|
|
||
| if (originalFilename == null) { | ||
| return null; | ||
| } | ||
|
|
||
| String baseName = FilenameUtils.getBaseName(originalFilename); | ||
| String extension = FilenameUtils.getExtension(originalFilename); | ||
|
|
||
| // Example label: General Application (GA2) - Defendant 1.pdf | ||
| String partyLabel = getPartyLabel(mainClaim, applicantPartyId); | ||
| String filename = "%s GA%d".formatted(baseName, genAppEntity.getRank()); | ||
| if (partyLabel != null) { | ||
| filename += " - " + partyLabel; | ||
| } | ||
|
|
||
| if (!extension.isBlank()) { | ||
| filename += "." + extension; | ||
| } | ||
|
|
||
| return filename; | ||
| } | ||
|
|
||
| private static String getPartyLabel(ClaimEntity mainClaim, UUID partyId) { | ||
| ClaimPartyEntity applicantClaimParty = getClaimParty(mainClaim, partyId); | ||
|
|
||
| if (applicantClaimParty.getRole() == PartyRole.CLAIMANT) { | ||
| return "Claimant %d".formatted(applicantClaimParty.getRank()); | ||
| } else if (applicantClaimParty.getRole() == PartyRole.DEFENDANT) { | ||
| return "Defendant %d".formatted(applicantClaimParty.getRank()); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static ClaimPartyEntity getClaimParty(ClaimEntity claim, UUID partyId) { | ||
|
tvr-hmcts marked this conversation as resolved.
|
||
| return claim.getClaimParties().stream() | ||
| .filter(claimPartyEntity -> partyId.equals(claimPartyEntity.getParty().getId())) | ||
| .findFirst() | ||
| .orElseThrow(() -> new PartyNotFoundException("Party not found")); | ||
| } | ||
|
|
||
| } | ||
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
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
82 changes: 82 additions & 0 deletions
82
src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentNameServiceTest.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,82 @@ | ||
| package uk.gov.hmcts.reform.pcs.ccd.service.document; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.ClaimEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.ClaimPartyEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity; | ||
| import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyRole; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.params.provider.Arguments.argumentSet; | ||
|
|
||
| class DocumentNameServiceTest { | ||
|
|
||
| private DocumentNameService underTest; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| underTest = new DocumentNameService(); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("genAppNamingScenarios") | ||
| void shouldAddGenAppNumberAndPartyLabelToGenAppDocument(PartyRole partyRole, | ||
| String originalFilename, | ||
| String expectedFilename) { | ||
| // Given | ||
| UUID applicantPartyId = UUID.randomUUID(); | ||
| GenAppEntity genAppEntity = GenAppEntity.builder() | ||
| .rank(5) | ||
| .build(); | ||
|
|
||
| PartyEntity party1 = PartyEntity.builder() | ||
| .id(applicantPartyId) | ||
| .build(); | ||
|
|
||
| ClaimPartyEntity claimParty1 = ClaimPartyEntity.builder() | ||
| .party(party1) | ||
| .rank(2) | ||
| .role(partyRole) | ||
| .build(); | ||
|
|
||
| ClaimEntity mainClaim = ClaimEntity.builder() | ||
| .claimParties(List.of(claimParty1)) | ||
| .build(); | ||
|
|
||
| // When | ||
| String updatedFilename | ||
| = underTest.appendGenAppPostfix(originalFilename, genAppEntity, mainClaim, applicantPartyId); | ||
|
|
||
| // Then | ||
| assertThat(updatedFilename).isEqualTo(expectedFilename); | ||
| } | ||
|
|
||
| private static Stream<Arguments> genAppNamingScenarios() { | ||
| return Stream.of( | ||
| // Party role, original filename, expected updated filename | ||
| argumentSet("null filename", | ||
| PartyRole.DEFENDANT, null, null), | ||
| argumentSet("no extension, defendant", | ||
| PartyRole.DEFENDANT, "sample", "sample GA5 - Defendant 2"), | ||
| argumentSet("with extension, defendant", | ||
| PartyRole.DEFENDANT, "sample.pdf", "sample GA5 - Defendant 2.pdf"), | ||
| argumentSet("no extension, claimant", | ||
| PartyRole.CLAIMANT, "sample", "sample GA5 - Claimant 2"), | ||
| argumentSet("with extension, claimant", | ||
| PartyRole.CLAIMANT, "sample.pdf", "sample GA5 - Claimant 2.pdf"), | ||
| argumentSet("no extension, other party type", | ||
| PartyRole.UNDERLESSEE_OR_MORTGAGEE, "sample", "sample GA5"), | ||
| argumentSet("with extension, other party type", | ||
| PartyRole.UNDERLESSEE_OR_MORTGAGEE, "sample.pdf", "sample GA5.pdf") | ||
| ); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.