Skip to content

Commit a28c367

Browse files
committed
DIAC-1587 wip
1 parent dcf98d7 commit a28c367

File tree

9 files changed

+576
-1
lines changed

9 files changed

+576
-1
lines changed

src/main/java/uk/gov/hmcts/reform/iacaseapi/domain/entities/ccd/Event.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public enum Event {
166166
GENERATE_LIST_CMR_TASK("generateListCmrTask"),
167167

168168
FORCE_DECIDED_STATE("forceDecidedState"),
169+
FORCE_FTPA_DECIDED_STATE("forceFtpaDecidedState"),
169170

170171
@JsonEnumDefaultValue
171172
UNKNOWN("unknown");
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import org.springframework.stereotype.Component;
6+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
7+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
8+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
9+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
10+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PostSubmitCallbackHandler;
11+
12+
@Component
13+
public class ForceFtpaDecidedStateConfirmation implements PostSubmitCallbackHandler<AsylumCase> {
14+
15+
public boolean canHandle(
16+
Callback<AsylumCase> callback
17+
) {
18+
requireNonNull(callback, "callback must not be null");
19+
20+
return callback.getEvent() == Event.FORCE_FTPA_DECIDED_STATE;
21+
}
22+
23+
public PostSubmitCallbackResponse handle(
24+
Callback<AsylumCase> callback
25+
) {
26+
if (!canHandle(callback)) {
27+
throw new IllegalStateException("Cannot handle callback");
28+
}
29+
30+
PostSubmitCallbackResponse postSubmitResponse =
31+
new PostSubmitCallbackResponse();
32+
33+
postSubmitResponse.setConfirmationHeader("# The appeal has been moved to the FTPA decided state");
34+
postSubmitResponse.setConfirmationBody(
35+
"#### What happens next\n\n"
36+
+ "The appeal can now be progressed from the FTPA decided state."
37+
);
38+
39+
return postSubmitResponse;
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.FTPA_APPLICANT_TYPE;
5+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_FTPA_APPELLANT_DECIDED;
6+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.IS_FTPA_RESPONDENT_DECIDED;
7+
8+
import org.springframework.stereotype.Component;
9+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
10+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
11+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
12+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
13+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
14+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
15+
16+
17+
@Component
18+
public class ForceFtpaDecidedStateHandler implements PreSubmitCallbackHandler<AsylumCase> {
19+
20+
public boolean canHandle(
21+
PreSubmitCallbackStage callbackStage,
22+
Callback<AsylumCase> callback
23+
) {
24+
requireNonNull(callbackStage, "callbackStage must not be null");
25+
requireNonNull(callback, "callback must not be null");
26+
27+
return callbackStage == PreSubmitCallbackStage.ABOUT_TO_SUBMIT
28+
&& (callback.getEvent() == Event.FORCE_FTPA_DECIDED_STATE);
29+
}
30+
31+
public PreSubmitCallbackResponse<AsylumCase> handle(
32+
PreSubmitCallbackStage callbackStage,
33+
Callback<AsylumCase> callback
34+
) {
35+
if (!canHandle(callbackStage, callback)) {
36+
throw new IllegalStateException("Cannot handle callback");
37+
}
38+
39+
final AsylumCase asylumCase = callback.getCaseDetails().getCaseData();
40+
41+
String appellantType = asylumCase.read(FTPA_APPLICANT_TYPE, String.class)
42+
.orElseThrow(() -> new IllegalStateException("appellantType is missing"));
43+
44+
if (appellantType.equals("appellant")) {
45+
asylumCase.write(IS_FTPA_APPELLANT_DECIDED, "Yes");
46+
} else if (appellantType.equals("respondent")) {
47+
asylumCase.write(IS_FTPA_RESPONDENT_DECIDED, "Yes");
48+
} else {
49+
throw new IllegalStateException("appellantType is is new and needs handling");
50+
}
51+
52+
return new PreSubmitCallbackResponse<>(asylumCase);
53+
}
54+
55+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.presubmit;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_DECIDED;
5+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCaseFieldDefinition.HAS_BEEN_FTPA_DECIDED;
6+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.FORCE_FTPA_DECIDED_STATE;
7+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.LEADERSHIP_JUDGE_FTPA_DECISION;
8+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event.RESIDENT_JUDGE_FTPA_DECISION;
9+
import static uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage.ABOUT_TO_SUBMIT;
10+
11+
import org.springframework.stereotype.Component;
12+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
13+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
14+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
15+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackResponse;
16+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PreSubmitCallbackStage;
17+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.field.YesOrNo;
18+
import uk.gov.hmcts.reform.iacaseapi.domain.handlers.PreSubmitCallbackHandler;
19+
20+
@Component
21+
public class FtpaDecidedFlagHandler implements PreSubmitCallbackHandler<AsylumCase> {
22+
23+
public boolean canHandle(
24+
PreSubmitCallbackStage callbackStage,
25+
Callback<AsylumCase> callback) {
26+
requireNonNull(callbackStage, "callbackStage must not be null");
27+
requireNonNull(callback, "callback must not be null");
28+
29+
Event event = callback.getEvent();
30+
return callbackStage.equals(ABOUT_TO_SUBMIT) &&
31+
event.equals(LEADERSHIP_JUDGE_FTPA_DECISION) ||
32+
event.equals(RESIDENT_JUDGE_FTPA_DECISION) ||
33+
event.equals(FORCE_FTPA_DECIDED_STATE);
34+
}
35+
36+
public PreSubmitCallbackResponse<AsylumCase> handle(PreSubmitCallbackStage callbackStage, Callback<AsylumCase> callback) {
37+
if (!canHandle(callbackStage, callback)) {
38+
throw new IllegalStateException("Cannot handle callback");
39+
}
40+
41+
AsylumCase asylumCase =
42+
callback
43+
.getCaseDetails()
44+
.getCaseData();
45+
46+
asylumCase.write(HAS_BEEN_DECIDED, YesOrNo.YES);
47+
asylumCase.write(HAS_BEEN_FTPA_DECIDED, YesOrNo.YES);
48+
49+
return new PreSubmitCallbackResponse<>(asylumCase);
50+
}
51+
}

src/main/resources/application.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ security:
593593
- "removeDetainedStatus"
594594
- "editDocuments"
595595
- "forceDecidedState"
596+
- "forceFtpaDecidedState"
596597
ctsc:
597598
- "appellantInPersonManual"
598599
- "startAppeal"
@@ -660,6 +661,7 @@ security:
660661
- "editDocuments"
661662
- "addStatutoryTimeframe24Weeks"
662663
- "forceDecidedState"
664+
- "forceFtpaDecidedState"
663665
ctsc-team-leader:
664666
- "appellantInPersonManual"
665667
- "startAppeal"
@@ -726,6 +728,7 @@ security:
726728
- "removeDetainedStatus"
727729
- "editDocuments"
728730
- "forceDecidedState"
731+
- "forceFtpaDecidedState"
729732
national-business-centre:
730733
- "appellantInPersonManual"
731734
- "startAppeal"
@@ -792,6 +795,7 @@ security:
792795
- "removeDetainedStatus"
793796
- "editDocuments"
794797
- "forceDecidedState"
798+
- "forceFtpaDecidedState"
795799
challenged-access-ctsc:
796800
- "appellantInPersonManual"
797801
- "startAppeal"
@@ -858,6 +862,7 @@ security:
858862
- "removeDetainedStatus"
859863
- "editDocuments"
860864
- "forceDecidedState"
865+
- "forceFtpaDecidedState"
861866
challenged-access-admin:
862867
- "appellantInPersonManual"
863868
- "startAppeal"
@@ -925,6 +930,7 @@ security:
925930
- "removeDetainedStatus"
926931
- "editDocuments"
927932
- "forceDecidedState"
933+
- "forceFtpaDecidedState"
928934
caseworker-ia-homeofficeapc:
929935
- "uploadHomeOfficeBundle"
930936
- "uploadAdditionalEvidenceHomeOffice"
@@ -1319,6 +1325,7 @@ security:
13191325
- "removeCaseManagerBulk"
13201326
- "hearingCancelled"
13211327
- "forceDecidedState"
1328+
- "forceFtpaDecidedState"
13221329
caseworker-ia-internal:
13231330
- "revokeCaseAccess"
13241331
- "removeCaseManagerBulk"

src/test/java/uk/gov/hmcts/reform/iacaseapi/domain/entities/ccd/EventTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,6 @@ void has_correct_values() {
170170

171171
@Test
172172
void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
173-
assertEquals(160, Event.values().length);
173+
assertEquals(161, Event.values().length);
174174
}
175175
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package uk.gov.hmcts.reform.iacaseapi.domain.handlers.postsubmit;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import static org.mockito.Mockito.reset;
9+
import static org.mockito.Mockito.when;
10+
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.extension.ExtendWith;
14+
import org.mockito.Mock;
15+
import org.mockito.junit.jupiter.MockitoExtension;
16+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.AsylumCase;
17+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.Event;
18+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.Callback;
19+
import uk.gov.hmcts.reform.iacaseapi.domain.entities.ccd.callback.PostSubmitCallbackResponse;
20+
21+
@ExtendWith(MockitoExtension.class)
22+
@SuppressWarnings("unchecked")
23+
class ForceFtpaDecidedStateConfirmationTest {
24+
25+
@Mock
26+
private Callback<AsylumCase> callback;
27+
28+
private ForceFtpaDecidedStateConfirmation forceFtpaDecidedStateConfirmation;
29+
30+
@BeforeEach
31+
public void setUp() {
32+
forceFtpaDecidedStateConfirmation = new ForceFtpaDecidedStateConfirmation();
33+
}
34+
35+
@Test
36+
void should_return_confirmation() {
37+
38+
when(callback.getEvent()).thenReturn(Event.FORCE_FTPA_DECIDED_STATE);
39+
40+
PostSubmitCallbackResponse callbackResponse =
41+
forceFtpaDecidedStateConfirmation.handle(callback);
42+
43+
assertNotNull(callbackResponse);
44+
assertTrue(callbackResponse.getConfirmationHeader().isPresent());
45+
assertTrue(callbackResponse.getConfirmationBody().isPresent());
46+
47+
assertThat(
48+
callbackResponse.getConfirmationHeader().get())
49+
.contains("# The appeal has been moved to the FTPA decided state");
50+
51+
assertThat(
52+
callbackResponse.getConfirmationBody().get())
53+
.contains("#### What happens next");
54+
55+
assertThat(
56+
callbackResponse.getConfirmationBody().get())
57+
.contains("The appeal can now be progressed from the FTPA decided state.");
58+
}
59+
60+
@Test
61+
void handling_should_throw_if_cannot_actually_handle() {
62+
63+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(callback))
64+
.hasMessage("Cannot handle callback")
65+
.isExactlyInstanceOf(IllegalStateException.class);
66+
}
67+
68+
@Test
69+
void it_can_handle_callback() {
70+
71+
for (Event event : Event.values()) {
72+
73+
when(callback.getEvent()).thenReturn(event);
74+
75+
boolean canHandle = forceFtpaDecidedStateConfirmation.canHandle(callback);
76+
77+
if (event == Event.FORCE_FTPA_DECIDED_STATE) {
78+
79+
assertTrue(canHandle);
80+
} else {
81+
assertFalse(canHandle);
82+
}
83+
84+
reset(callback);
85+
}
86+
}
87+
88+
@Test
89+
void should_not_allow_null_arguments() {
90+
91+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.canHandle(null))
92+
.hasMessage("callback must not be null")
93+
.isExactlyInstanceOf(NullPointerException.class);
94+
95+
assertThatThrownBy(() -> forceFtpaDecidedStateConfirmation.handle(null))
96+
.hasMessage("callback must not be null")
97+
.isExactlyInstanceOf(NullPointerException.class);
98+
}
99+
}

0 commit comments

Comments
 (0)