Skip to content

Commit cff9d83

Browse files
HDPI-6099: Hide gen app documents that are Without Notice
1 parent 175fc63 commit cff9d83

17 files changed

Lines changed: 798 additions & 100 deletions

src/main/java/uk/gov/hmcts/reform/pcs/ccd/PCSCaseView.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import uk.gov.hmcts.ccd.sdk.CaseView;
77
import uk.gov.hmcts.ccd.sdk.CaseViewRequest;
88
import uk.gov.hmcts.ccd.sdk.type.AddressUK;
9-
import uk.gov.hmcts.ccd.sdk.type.Document;
109
import uk.gov.hmcts.ccd.sdk.type.ListValue;
1110
import uk.gov.hmcts.ccd.sdk.type.SearchCriteria;
1211
import uk.gov.hmcts.ccd.sdk.type.YesOrNo;
@@ -23,10 +22,11 @@
2322
import uk.gov.hmcts.reform.pcs.ccd.util.ListValueUtils;
2423
import uk.gov.hmcts.reform.pcs.ccd.view.AlternativesToPossessionView;
2524
import uk.gov.hmcts.reform.pcs.ccd.view.AsbProhibitedConductView;
26-
import uk.gov.hmcts.reform.pcs.ccd.view.CaseTabView;
2725
import uk.gov.hmcts.reform.pcs.ccd.view.CaseLinkView;
26+
import uk.gov.hmcts.reform.pcs.ccd.view.CaseTabView;
2827
import uk.gov.hmcts.reform.pcs.ccd.view.ClaimGroundsView;
2928
import uk.gov.hmcts.reform.pcs.ccd.view.ClaimView;
29+
import uk.gov.hmcts.reform.pcs.ccd.view.DocumentsView;
3030
import uk.gov.hmcts.reform.pcs.ccd.view.NoticeOfPossessionView;
3131
import uk.gov.hmcts.reform.pcs.ccd.view.PartiesView;
3232
import uk.gov.hmcts.reform.pcs.ccd.view.RentArrearsView;
@@ -58,6 +58,7 @@ public class PCSCaseView implements CaseView<PCSCase, State> {
5858
private final DraftCaseDataService draftCaseDataService;
5959
private final CaseTitleService caseTitleService;
6060
private final ClaimView claimView;
61+
private final DocumentsView documentsView;
6162
private final TenancyLicenceView tenancyLicenceView;
6263
private final ClaimGroundsView claimGroundsView;
6364
private final RentDetailsView rentDetailsView;
@@ -109,13 +110,13 @@ private PCSCase getSubmittedCase(long caseReference) {
109110
.propertyAddress(convertAddress(pcsCaseEntity.getPropertyAddress()))
110111
.legislativeCountry(pcsCaseEntity.getLegislativeCountry())
111112
.caseManagementLocationNumber(pcsCaseEntity.getCaseManagementLocation())
112-
.allDocuments(mapAndWrapDocuments(pcsCaseEntity))
113113
.build();
114114

115115
setDerivedProperties(pcsCase, pcsCaseEntity);
116116

117117
partiesView.setCaseFields(pcsCase, pcsCaseEntity);
118118
claimView.setCaseFields(pcsCase, pcsCaseEntity);
119+
documentsView.setCaseFields(pcsCase, pcsCaseEntity);
119120
tenancyLicenceView.setCaseFields(pcsCase, pcsCaseEntity);
120121
claimGroundsView.setCaseFields(pcsCase, pcsCaseEntity);
121122
rentDetailsView.setCaseFields(pcsCase, pcsCaseEntity);
@@ -209,26 +210,4 @@ private List<ListValue<Party>> mapAndWrapParties(Set<PartyEntity> partyEntities)
209210
.collect(Collectors.collectingAndThen(Collectors.toList(), ListValueUtils::wrapListItems));
210211
}
211212

212-
private List<ListValue<Document>> mapAndWrapDocuments(PcsCaseEntity pcsCaseEntity) {
213-
214-
if (pcsCaseEntity.getDocuments().isEmpty()) {
215-
return List.of();
216-
}
217-
218-
return pcsCaseEntity.getDocuments().stream()
219-
.map(entity -> ListValue.<Document>builder()
220-
.id(entity.getId().toString())
221-
.value(Document.builder()
222-
.filename(entity.getFileName())
223-
.url(entity.getUrl())
224-
.binaryUrl(entity.getBinaryUrl())
225-
.categoryId(entity.getCategoryId())
226-
.uploadTimestamp(entity.getSubmittedDate() == null
227-
? null
228-
: entity.getSubmittedDate()
229-
.atZone(java.time.ZoneOffset.UTC).toLocalDateTime())
230-
.build())
231-
.build())
232-
.collect(Collectors.toList());
233-
}
234213
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package uk.gov.hmcts.reform.pcs.ccd.domain;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import uk.gov.hmcts.ccd.sdk.type.Document;
8+
9+
@Builder
10+
@Data
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class DocumentWithId {
14+
15+
private String id;
16+
private Document document;
17+
18+
}

src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/PCSCase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
import uk.gov.hmcts.reform.pcs.ccd.domain.dashboard.DashboardData;
2828
import uk.gov.hmcts.reform.pcs.ccd.domain.enforcetheorder.EnforcementOrder;
2929
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest;
30+
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GeneralApplication;
3031
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest;
3132
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredNoArrearsPossessionGrounds;
3233
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.AssuredRentArrearsPossessionGrounds;
3334
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.ClaimGroundSummary;
3435
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOtherGroundReason;
3536
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.IntroductoryDemotedOtherGroundsForPossession;
37+
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.NoRentArrearsGroundsReasons;
3638
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.RentArrearsGroundsReasons;
3739
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.SecureOrFlexibleGroundsReasons;
3840
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.SecureOrFlexiblePossessionGrounds;
39-
import uk.gov.hmcts.reform.pcs.ccd.domain.grounds.NoRentArrearsGroundsReasons;
4041
import uk.gov.hmcts.reform.pcs.ccd.domain.respondpossessionclaim.PossessionClaimResponse;
4142
import uk.gov.hmcts.reform.pcs.ccd.domain.statementoftruth.StatementOfTruthDetails;
4243
import uk.gov.hmcts.reform.pcs.ccd.domain.tabs.CasePartiesTab;
@@ -620,6 +621,9 @@ public class PCSCase {
620621
@CCD(searchable = false, access = {ClaimantAccess.class})
621622
private YesOrNo showConfirmEvictionJourney;
622623

624+
@CCD(access = {CitizenAccess.class})
625+
private List<ListValue<GeneralApplication>> genApps;
626+
623627
@JsonUnwrapped(prefix = "casePartiesTab_")
624628
@CCD
625629
private CasePartiesTab casePartiesTab;

src/main/java/uk/gov/hmcts/reform/pcs/ccd/domain/Party.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
@AllArgsConstructor
1515
public class Party {
1616

17+
private String id;
18+
19+
private String idamId;
20+
1721
private String firstName;
1822

1923
private String lastName;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package uk.gov.hmcts.reform.pcs.ccd.domain.genapp;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import uk.gov.hmcts.ccd.sdk.type.Document;
8+
import uk.gov.hmcts.ccd.sdk.type.ListValue;
9+
import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentWithId;
10+
import uk.gov.hmcts.reform.pcs.ccd.domain.Party;
11+
12+
import java.time.LocalDateTime;
13+
import java.util.List;
14+
15+
@Builder
16+
@Data
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
public class GeneralApplication {
20+
21+
private GenAppType applicationType;
22+
23+
private Party party;
24+
25+
private LocalDateTime submittedOn;
26+
27+
private DocumentWithId submissionDocument;
28+
29+
private List<ListValue<Document>> supportingDocuments;
30+
31+
}

src/main/java/uk/gov/hmcts/reform/pcs/ccd/entity/GenAppEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,8 @@ public class GenAppEntity {
118118
private StatementOfTruthEntity statementOfTruth;
119119

120120
private LocalDateTime applicationSubmittedDate;
121+
122+
@OneToOne(cascade = ALL, orphanRemoval = true)
123+
@JoinColumn(name = "submission_document_id")
124+
private DocumentEntity submissionDocument;
121125
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package uk.gov.hmcts.reform.pcs.ccd.service.genapp;
2+
3+
import lombok.AllArgsConstructor;
4+
import org.springframework.stereotype.Service;
5+
import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo;
6+
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
7+
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
8+
import uk.gov.hmcts.reform.pcs.service.LegalRepresentativeService;
9+
10+
import java.util.UUID;
11+
12+
@Service
13+
@AllArgsConstructor
14+
public class GenAppVisibilityService {
15+
16+
private final LegalRepresentativeService legalRepresentativeService;
17+
18+
public boolean isGenAppVisibleToUser(GenAppEntity genAppEntity, UUID currentUserId) {
19+
if (genAppEntity.getWithoutNotice() != VerticalYesNo.YES) {
20+
return true;
21+
}
22+
23+
PartyEntity applicantParty = genAppEntity.getParty();
24+
if (currentUserId.equals(applicantParty.getIdamId())) {
25+
return true;
26+
}
27+
28+
return legalRepresentativeService.getLegalRepresentativeForParty(applicantParty.getId())
29+
.map(legalRepresentativeEntity -> currentUserId.equals(legalRepresentativeEntity.getIdamId()))
30+
.orElse(false);
31+
}
32+
33+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package uk.gov.hmcts.reform.pcs.ccd.view;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import org.springframework.stereotype.Component;
5+
import uk.gov.hmcts.ccd.sdk.type.Document;
6+
import uk.gov.hmcts.ccd.sdk.type.ListValue;
7+
import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase;
8+
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
9+
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
10+
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
11+
import uk.gov.hmcts.reform.pcs.ccd.service.genapp.GenAppVisibilityService;
12+
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
13+
14+
import java.util.List;
15+
import java.util.UUID;
16+
import java.util.stream.Collectors;
17+
18+
@Component
19+
@RequiredArgsConstructor
20+
public class DocumentsView {
21+
22+
private final SecurityContextService securityContextService;
23+
private final GenAppVisibilityService genAppVisibilityService;
24+
25+
public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) {
26+
pcsCase.setAllDocuments(mapAndWrapDocuments(pcsCaseEntity));
27+
}
28+
29+
private List<ListValue<Document>> mapAndWrapDocuments(PcsCaseEntity pcsCaseEntity) {
30+
31+
if (pcsCaseEntity.getDocuments().isEmpty()) {
32+
return List.of();
33+
}
34+
35+
UUID currentUserId = securityContextService.getCurrentUserId();
36+
37+
return pcsCaseEntity.getDocuments().stream()
38+
.filter(documentEntity -> this.isDocumentVisibleToUser(documentEntity, currentUserId))
39+
.map(entity -> ListValue.<Document>builder()
40+
.id(entity.getId().toString())
41+
.value(Document.builder()
42+
.filename(entity.getFileName())
43+
.url(entity.getUrl())
44+
.binaryUrl(entity.getBinaryUrl())
45+
.categoryId(entity.getCategoryId())
46+
.build())
47+
.build())
48+
.collect(Collectors.toList());
49+
}
50+
51+
public boolean isDocumentVisibleToUser(DocumentEntity documentEntity, UUID currentUserId) {
52+
GenAppEntity genAppEntity = documentEntity.getGeneralApplication();
53+
54+
if (genAppEntity != null) {
55+
return genAppVisibilityService.isGenAppVisibleToUser(genAppEntity, currentUserId);
56+
} else {
57+
return true;
58+
}
59+
}
60+
61+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package uk.gov.hmcts.reform.pcs.ccd.view;
2+
3+
import lombok.AllArgsConstructor;
4+
import org.modelmapper.ModelMapper;
5+
import org.springframework.stereotype.Component;
6+
import uk.gov.hmcts.ccd.sdk.type.Document;
7+
import uk.gov.hmcts.ccd.sdk.type.ListValue;
8+
import uk.gov.hmcts.reform.pcs.ccd.domain.DocumentWithId;
9+
import uk.gov.hmcts.reform.pcs.ccd.domain.PCSCase;
10+
import uk.gov.hmcts.reform.pcs.ccd.domain.Party;
11+
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GeneralApplication;
12+
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
13+
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
14+
import uk.gov.hmcts.reform.pcs.ccd.service.genapp.GenAppVisibilityService;
15+
import uk.gov.hmcts.reform.pcs.security.SecurityContextService;
16+
17+
import java.util.Comparator;
18+
import java.util.List;
19+
import java.util.Optional;
20+
import java.util.UUID;
21+
22+
@Component
23+
@AllArgsConstructor
24+
public class GenAppsView {
25+
26+
private final ModelMapper modelMapper;
27+
private final SecurityContextService securityContextService;
28+
private final GenAppVisibilityService genAppVisibilityService;
29+
30+
public void setCaseFields(PCSCase pcsCase, PcsCaseEntity pcsCaseEntity) {
31+
UUID currentUserId = securityContextService.getCurrentUserId();
32+
33+
List<ListValue<GeneralApplication>> genApps = pcsCaseEntity.getGenApps().stream()
34+
.sorted(Comparator.comparing(GenAppEntity::getApplicationSubmittedDate).reversed())
35+
.filter(genAppEntity -> genAppVisibilityService.isGenAppVisibleToUser(genAppEntity, currentUserId))
36+
.map(this::createListValue)
37+
.toList();
38+
39+
pcsCase.setGenApps(genApps);
40+
}
41+
42+
private ListValue<GeneralApplication> createListValue(GenAppEntity genAppEntity) {
43+
Party party = mapToSimpleParty(genAppEntity);
44+
45+
GeneralApplication generalApplication = GeneralApplication.builder()
46+
.applicationType(genAppEntity.getType())
47+
.party(party)
48+
.submittedOn(genAppEntity.getApplicationSubmittedDate())
49+
.submissionDocument(getSubmissionDocument(genAppEntity))
50+
.build();
51+
52+
return new ListValue<>(genAppEntity.getId().toString(), generalApplication);
53+
}
54+
55+
private Party mapToSimpleParty(GenAppEntity genAppEntity) {
56+
return Optional.ofNullable(genAppEntity.getParty())
57+
.map(partyEntity -> {
58+
UUID idamId = partyEntity.getIdamId();
59+
60+
return Party.builder()
61+
.id(partyEntity.getId().toString())
62+
.idamId(idamId != null ? idamId.toString() : null)
63+
.firstName(partyEntity.getFirstName())
64+
.lastName(partyEntity.getLastName())
65+
.build();
66+
})
67+
.orElse(null);
68+
}
69+
70+
private DocumentWithId getSubmissionDocument(GenAppEntity genAppEntity) {
71+
return Optional.ofNullable(genAppEntity.getSubmissionDocument())
72+
.map(documentEntity -> DocumentWithId.builder()
73+
.id(documentEntity.getId().toString())
74+
.document(modelMapper.map(documentEntity, Document.class))
75+
.build()
76+
)
77+
.orElse(null);
78+
}
79+
80+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package uk.gov.hmcts.reform.pcs.config;
2+
3+
import org.springframework.cache.CacheManager;
4+
import org.springframework.cache.annotation.EnableCaching;
5+
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.context.annotation.ScopedProxyMode;
9+
import org.springframework.web.context.annotation.RequestScope;
10+
11+
@Configuration
12+
@EnableCaching
13+
public class CacheConfiguration {
14+
15+
@Bean
16+
@RequestScope(proxyMode = ScopedProxyMode.TARGET_CLASS)
17+
public CacheManager requestScopedCacheManager() {
18+
return new ConcurrentMapCacheManager();
19+
}
20+
21+
}

0 commit comments

Comments
 (0)