Skip to content

Commit

Permalink
Revert SSCS-11648 Commit (#3717)
Browse files Browse the repository at this point in the history
* Revert SSCS-11648 Commit

* Suppressions

* Unused import

* Update build.gradle

---------

Co-authored-by: DGordonV1 <david.gordon@hmcts.net>
  • Loading branch information
DGordonV1 and DGordonV1 committed Apr 2, 2024
1 parent 4998e75 commit 270bd6c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 136 deletions.
2 changes: 1 addition & 1 deletion config/owasp/suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress until = "2024-04-01">
<suppress until = "2024-05-01">
<cve>CVE-2023-35116</cve>
<cve>CVE-2023-36052</cve>
</suppress>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package uk.gov.hmcts.reform.sscs.ccd.presubmit.caseupdated;

import static java.util.Objects.isNull;
import static java.util.Objects.*;
import static java.util.Objects.nonNull;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
Expand Down Expand Up @@ -41,7 +40,6 @@
import uk.gov.hmcts.reform.sscs.service.RefDataService;
import uk.gov.hmcts.reform.sscs.service.RegionalProcessingCenterService;
import uk.gov.hmcts.reform.sscs.service.VenueService;
import uk.gov.hmcts.reform.sscs.utility.EmailUtil;

@Component
@Slf4j
Expand Down Expand Up @@ -154,7 +152,6 @@ && isNotBlank(appellant.getAddress().getPostcode())) {
final boolean hasSystemUserRole = userDetails.hasRole(SYSTEM_USER);

updateHearingTypeForNonSscs1Case(sscsCaseData, preSubmitCallbackResponse, hasSystemUserRole);
validateHearingVideoEmail(sscsCaseData, preSubmitCallbackResponse);

YesNo isJointPartyAddressSameAsAppellant = sscsCaseData.getJointParty().getJointPartyAddressSameAsAppellant();
if (sscsCaseData.isThereAJointParty() && !Objects.isNull(isJointPartyAddressSameAsAppellant) && isJointPartyAddressSameAsAppellant.toBoolean()) {
Expand All @@ -175,18 +172,6 @@ && isNotBlank(appellant.getAddress().getPostcode())) {
return preSubmitCallbackResponse;
}

private void validateHearingVideoEmail(SscsCaseData sscsCaseData, PreSubmitCallbackResponse<SscsCaseData> response) {
HearingSubtype hearingSubtype = sscsCaseData.getAppeal().getHearingSubtype();
if (hearingSubtype != null
&& YesNo.isYes(hearingSubtype.getWantsHearingTypeVideo())) {

String hearingVideoEmail = hearingSubtype.getHearingVideoEmail();
if (!EmailUtil.isEmailValid(hearingVideoEmail)) {
response.addError("Hearing video email address must be valid email address");
}
}
}

private void updateLanguage(SscsCaseData sscsCaseData) {
HearingOptions hearingOptions = sscsCaseData.getAppeal().getHearingOptions();
if (nonNull(hearingOptions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.getUpdatedDirectionDueDate;
import static uk.gov.hmcts.reform.sscs.helper.SscsHelper.validateHearingOptionsAndExcludeDates;
import static uk.gov.hmcts.reform.sscs.idam.UserRole.SYSTEM_USER;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.*;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.clearOtherPartiesIfEmpty;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.getOtherPartiesWithClearedRoles;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.getOtherPartyUcb;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.isConfidential;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.otherPartyWantsToAttendHearing;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.roleAbsentForOtherParties;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.roleExistsForOtherParties;
import static uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil.sendNewOtherPartyNotification;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.reform.sscs.ccd.callback.Callback;
import uk.gov.hmcts.reform.sscs.ccd.callback.CallbackType;
import uk.gov.hmcts.reform.sscs.ccd.callback.PreSubmitCallbackResponse;
import uk.gov.hmcts.reform.sscs.ccd.domain.Benefit;
import uk.gov.hmcts.reform.sscs.ccd.domain.CcdValue;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingSubtype;
import uk.gov.hmcts.reform.sscs.ccd.domain.HearingType;
import uk.gov.hmcts.reform.sscs.ccd.domain.OtherParty;
import uk.gov.hmcts.reform.sscs.ccd.domain.SscsCaseData;
Expand All @@ -30,13 +35,10 @@
import uk.gov.hmcts.reform.sscs.ccd.presubmit.PreSubmitCallbackHandler;
import uk.gov.hmcts.reform.sscs.idam.IdamService;
import uk.gov.hmcts.reform.sscs.idam.UserDetails;
import uk.gov.hmcts.reform.sscs.util.OtherPartyDataUtil;
import uk.gov.hmcts.reform.sscs.utility.EmailUtil;


@Component
@Slf4j
@AllArgsConstructor
public class UpdateOtherPartyAboutToSubmitHandler implements PreSubmitCallbackHandler<SscsCaseData> {

private static final String WARN_NON_SSCS1_PAPER_TO_ORAL = "The hearing type will be changed from Paper to Oral as "
Expand All @@ -47,7 +49,12 @@ public class UpdateOtherPartyAboutToSubmitHandler implements PreSubmitCallbackHa

private static final String ERR_ROLE_REQUIRED = "Role is required for the selected case";

private final IdamService idamService;
private IdamService idamService;

@Autowired
UpdateOtherPartyAboutToSubmitHandler(IdamService idamService) {
this.idamService = idamService;
}

@Override
public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callback) {
Expand All @@ -60,9 +67,7 @@ public boolean canHandle(CallbackType callbackType, Callback<SscsCaseData> callb
}

@Override
public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
Callback<SscsCaseData> callback,
String userAuthorisation) {
public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType, Callback<SscsCaseData> callback, String userAuthorisation) {
if (!canHandle(callbackType, callback)) {
throw new IllegalStateException("Cannot handle callback");
}
Expand All @@ -77,12 +82,6 @@ public PreSubmitCallbackResponse<SscsCaseData> handle(CallbackType callbackType,
PreSubmitCallbackResponse<SscsCaseData> response = new PreSubmitCallbackResponse<>(sscsCaseData);
response.addErrors(verifyHearingUnavailableDates(sscsCaseData.getOtherParties()));

final UserDetails userDetails = idamService.getUserDetails(userAuthorisation);
final boolean hasSystemUserRole = userDetails.hasRole(SYSTEM_USER);
updateHearingTypeForNonSscs1Case(sscsCaseData, response, hasSystemUserRole);
getUpdatedDirectionDueDate(sscsCaseData);
validateHearingVideoEmail(sscsCaseData, response);

if (isNonSscs1Case(sscsCaseData, response)) {
response.getData().getAppeal().setHearingType(HearingType.ORAL.getValue());
final UserDetails user = idamService.getUserDetails(userAuthorisation);
Expand Down Expand Up @@ -111,49 +110,12 @@ && isBenefitTypeValidForOtherPartyValidation(sscsCaseData.getBenefitType())) {
return response;
}

private boolean isBenefitTypeValidForOtherPartyValidation(Optional<Benefit> benefitType) {
return benefitType.filter(benefit -> SscsType.SSCS5.equals(benefit.getSscsType())).isPresent();
}

private void validateHearingVideoEmail(SscsCaseData sscsCaseData, PreSubmitCallbackResponse<SscsCaseData> response) {
List<CcdValue<OtherParty>> otherParties = Optional.ofNullable(sscsCaseData.getOtherParties()).orElse(Collections.emptyList());

for (CcdValue<OtherParty> otherParty : otherParties) {
HearingSubtype hearingSubtype = otherParty.getValue().getHearingSubtype();

if (hearingSubtype != null
&& YesNo.isYes(hearingSubtype.getWantsHearingTypeVideo())) {

String hearingVideoEmail = hearingSubtype.getHearingVideoEmail();
if (!EmailUtil.isEmailValid(hearingVideoEmail)) {
response.addError("Hearing video email address must be valid email address");
}
}
}
}

private void updateHearingTypeForNonSscs1Case(SscsCaseData sscsCaseData,
PreSubmitCallbackResponse<SscsCaseData> response,
boolean hasSystemUserRole) {
if (sscsCaseData.getAppeal().getHearingType() != null
&& HearingType.PAPER.getValue().equals(sscsCaseData.getAppeal().getHearingType())
&& isBenefitTypeValidForHearingTypeValidation(response.getData().getBenefitType())
&& OtherPartyDataUtil.otherPartyWantsToAttendHearing(response.getData().getOtherParties())) {

response.getData().getAppeal().setHearingType(HearingType.ORAL.getValue());
if (!hasSystemUserRole) {
response.addWarning("The hearing type will be changed from Paper to Oral as at least one of the"
+ " parties to the case would like to attend the hearing");
}
}
}

private List<String> verifyHearingUnavailableDates(final List<CcdValue<OtherParty>> otherParties) {
List<String> errors = new ArrayList<>();
if (!isNull(otherParties)) {
otherParties.stream()
.map(CcdValue::getValue)
.filter(this::hasValidHearingOptionsAndWantsToExcludeDates)
.filter(otherParty -> hasValidHearingOptionsAndWantsToExcludeDates(otherParty))
.forEach(otherParty -> errors.addAll(
validateHearingOptionsAndExcludeDates(otherParty.getHearingOptions().getExcludeDates())
));
Expand All @@ -168,7 +130,7 @@ private boolean hasValidHearingOptionsAndWantsToExcludeDates(final OtherParty ot
}

private boolean isNonSscs1Case(final SscsCaseData sscsCaseData,
final PreSubmitCallbackResponse<SscsCaseData> response) {
final PreSubmitCallbackResponse<SscsCaseData> response) {
return sscsCaseData.getAppeal().getHearingType() != null
&& HearingType.PAPER.getValue().equals(sscsCaseData.getAppeal().getHearingType())
&& isBenefitTypeValidForHearingTypeValidation(response.getData().getBenefitType())
Expand All @@ -179,4 +141,8 @@ private boolean isBenefitTypeValidForHearingTypeValidation(final Optional<Benefi
return benefitType.filter(benefit -> SscsType.SSCS2.equals(benefit.getSscsType())
|| SscsType.SSCS5.equals(benefit.getSscsType())).isPresent();
}

private boolean isBenefitTypeValidForOtherPartyValidation(final Optional<Benefit> benefitType) {
return benefitType.filter(benefit -> SscsType.SSCS5.equals(benefit.getSscsType())).isPresent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import junitparams.converters.Nullable;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -372,68 +371,6 @@ public void givenSscs2CaseOtherPartyWithRoleEntered_thenNoError() {
assertEquals(0, response.getErrors().size());
}

@Test
@Parameters({"null", "", "sample", "sample.com"})
public void givenACaseWhenUserWantsHearingTypeVideoButTheEmailIsInvalidForSingleOtherParty_thenThrowAnError(@Nullable String email) {
HearingSubtype hearingSubtype = HearingSubtype.builder()
.wantsHearingTypeVideo("Yes")
.hearingVideoEmail(email)
.build();

CcdValue<OtherParty> otherPartyCcdValue = buildOtherParty(ID_1);
otherPartyCcdValue.getValue().setHearingSubtype(hearingSubtype);

SscsCaseData sscsCaseData = SscsCaseData.builder()
.appeal(Appeal.builder()
.benefitType(BenefitType.builder().code("childSupport").build())
.hearingType(HearingType.PAPER.getValue())
.build())
.otherParties(List.of(otherPartyCcdValue))
.build();

when(caseDetails.getCaseData()).thenReturn(sscsCaseData);

PreSubmitCallbackResponse<SscsCaseData> response = handler.handle(ABOUT_TO_SUBMIT, callback, USER_AUTHORISATION);

assertEquals(1, response.getErrors().size());
assertEquals(0, response.getWarnings().size());
assertEquals("Hearing video email address must be valid email address", response.getErrors().stream().findFirst().get());
}

@Test
@Parameters({"null", "", "sample", "sample.com"})
public void givenACaseWhenUserWantsHearingTypeVideoButTheEmailIsInvalidForMultipleOtherParty_thenThrowAnError(@Nullable String email) {
HearingSubtype hearingSubtype1 = HearingSubtype.builder()
.wantsHearingTypeVideo("Yes")
.hearingVideoEmail("example@example.com")
.build();
HearingSubtype hearingSubtype2 = HearingSubtype.builder()
.wantsHearingTypeVideo("Yes")
.hearingVideoEmail(email)
.build();

CcdValue<OtherParty> otherPartyCcdValue1 = buildOtherParty(ID_1);
CcdValue<OtherParty> otherPartyCcdValue2 = buildOtherParty(ID_2);
otherPartyCcdValue1.getValue().setHearingSubtype(hearingSubtype1);
otherPartyCcdValue2.getValue().setHearingSubtype(hearingSubtype2);

SscsCaseData sscsCaseData = SscsCaseData.builder()
.appeal(Appeal.builder()
.benefitType(BenefitType.builder().code("childSupport").build())
.hearingType(HearingType.PAPER.getValue())
.build())
.otherParties(List.of(otherPartyCcdValue1, otherPartyCcdValue2))
.build();

when(caseDetails.getCaseData()).thenReturn(sscsCaseData);

PreSubmitCallbackResponse<SscsCaseData> response = handler.handle(ABOUT_TO_SUBMIT, callback, USER_AUTHORISATION);

assertEquals(1, response.getErrors().size());
assertEquals(0, response.getWarnings().size());
assertEquals("Hearing video email address must be valid email address", response.getErrors().stream().findFirst().get());
}

@Test
@Parameters({"childSupport", "taxCredit", "guardiansAllowance", "taxFreeChildcare", "homeResponsibilitiesProtection",
"childBenefit","thirtyHoursFreeChildcare","guaranteedMinimumPension","nationalInsuranceCredits"})
Expand Down

0 comments on commit 270bd6c

Please sign in to comment.