Skip to content

Commit 3e3d0d6

Browse files
DIAC-1587 New Event to move the appeal to FTPA Decided state (Rehydrated Case) (#2872)
* DIAC-1586-force-decided-state * DIAC-1587 wip * Update Event.java --------- Co-authored-by: rajeshthuraiyur <48379561+rajeshthuraiyur@users.noreply.github.com>
1 parent 4017292 commit 3e3d0d6

File tree

9 files changed

+576
-2
lines changed

9 files changed

+576
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public enum Event {
165165
APPELLANT_IN_PERSON_MANUAL("appellantInPersonManual"),
166166
GENERATE_LIST_CMR_TASK("generateListCmrTask"),
167167
TURN_ON_NOTIFICATIONS_WA_TASKS("turnOnNotificationsWATasks"),
168-
169168
FORCE_DECIDED_STATE("forceDecidedState"),
169+
FORCE_FTPA_DECIDED_STATE("forceFtpaDecidedState"),
170170

171171
@JsonEnumDefaultValue
172172
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
@@ -595,6 +595,7 @@ security:
595595
- "removeDetainedStatus"
596596
- "editDocuments"
597597
- "forceDecidedState"
598+
- "forceFtpaDecidedState"
598599
- "turnOnNotificationsWATasks"
599600
ctsc:
600601
- "appellantInPersonManual"
@@ -664,6 +665,7 @@ security:
664665
- "editDocuments"
665666
- "addStatutoryTimeframe24Weeks"
666667
- "forceDecidedState"
668+
- "forceFtpaDecidedState"
667669
ctsc-team-leader:
668670
- "appellantInPersonManual"
669671
- "startAppeal"
@@ -731,6 +733,7 @@ security:
731733
- "removeDetainedStatus"
732734
- "editDocuments"
733735
- "forceDecidedState"
736+
- "forceFtpaDecidedState"
734737
national-business-centre:
735738
- "appellantInPersonManual"
736739
- "startAppeal"
@@ -797,6 +800,7 @@ security:
797800
- "removeDetainedStatus"
798801
- "editDocuments"
799802
- "forceDecidedState"
803+
- "forceFtpaDecidedState"
800804
challenged-access-ctsc:
801805
- "appellantInPersonManual"
802806
- "startAppeal"
@@ -863,6 +867,7 @@ security:
863867
- "removeDetainedStatus"
864868
- "editDocuments"
865869
- "forceDecidedState"
870+
- "forceFtpaDecidedState"
866871
challenged-access-admin:
867872
- "appellantInPersonManual"
868873
- "startAppeal"
@@ -930,6 +935,7 @@ security:
930935
- "removeDetainedStatus"
931936
- "editDocuments"
932937
- "forceDecidedState"
938+
- "forceFtpaDecidedState"
933939
caseworker-ia-homeofficeapc:
934940
- "uploadHomeOfficeBundle"
935941
- "uploadAdditionalEvidenceHomeOffice"
@@ -1324,6 +1330,7 @@ security:
13241330
- "removeCaseManagerBulk"
13251331
- "hearingCancelled"
13261332
- "forceDecidedState"
1333+
- "forceFtpaDecidedState"
13271334
caseworker-ia-internal:
13281335
- "revokeCaseAccess"
13291336
- "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
@@ -171,6 +171,6 @@ void has_correct_values() {
171171

172172
@Test
173173
void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
174-
assertEquals(160, Event.values().length);
174+
assertEquals(161, Event.values().length);
175175
}
176176
}
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)