Skip to content

Commit 61ae5b1

Browse files
committed
DIAC-1587 wip
1 parent 5cabdca commit 61ae5b1

File tree

9 files changed

+577
-1
lines changed

9 files changed

+577
-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
@@ -164,6 +164,7 @@ public enum Event {
164164
GENERATE_LIST_CMR_TASK("generateListCmrTask"),
165165

166166
FORCE_DECIDED_STATE("forceDecidedState"),
167+
FORCE_FTPA_DECIDED_STATE("forceFtpaDecidedState"),
167168

168169
@JsonEnumDefaultValue
169170
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
@@ -592,6 +592,7 @@ security:
592592
- "removeDetainedStatus"
593593
- "editDocuments"
594594
- "forceDecidedState"
595+
- "forceFtpaDecidedState"
595596
ctsc:
596597
- "appellantInPersonManual"
597598
- "startAppeal"
@@ -658,6 +659,7 @@ security:
658659
- "removeDetainedStatus"
659660
- "editDocuments"
660661
- "forceDecidedState"
662+
- "forceFtpaDecidedState"
661663
ctsc-team-leader:
662664
- "appellantInPersonManual"
663665
- "startAppeal"
@@ -724,6 +726,7 @@ security:
724726
- "removeDetainedStatus"
725727
- "editDocuments"
726728
- "forceDecidedState"
729+
- "forceFtpaDecidedState"
727730
national-business-centre:
728731
- "appellantInPersonManual"
729732
- "startAppeal"
@@ -790,6 +793,7 @@ security:
790793
- "removeDetainedStatus"
791794
- "editDocuments"
792795
- "forceDecidedState"
796+
- "forceFtpaDecidedState"
793797
challenged-access-ctsc:
794798
- "appellantInPersonManual"
795799
- "startAppeal"
@@ -856,6 +860,7 @@ security:
856860
- "removeDetainedStatus"
857861
- "editDocuments"
858862
- "forceDecidedState"
863+
- "forceFtpaDecidedState"
859864
challenged-access-admin:
860865
- "appellantInPersonManual"
861866
- "startAppeal"
@@ -923,6 +928,7 @@ security:
923928
- "removeDetainedStatus"
924929
- "editDocuments"
925930
- "forceDecidedState"
931+
- "forceFtpaDecidedState"
926932
caseworker-ia-homeofficeapc:
927933
- "uploadHomeOfficeBundle"
928934
- "uploadAdditionalEvidenceHomeOffice"
@@ -1315,6 +1321,7 @@ security:
13151321
- "removeCaseManagerBulk"
13161322
- "hearingCancelled"
13171323
- "forceDecidedState"
1324+
- "forceFtpaDecidedState"
13181325
caseworker-ia-internal:
13191326
- "revokeCaseAccess"
13201327
- "removeCaseManagerBulk"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,11 @@ void has_correct_values() {
163163
assertEquals("generateListCmrTask", Event.GENERATE_LIST_CMR_TASK.toString());
164164
assertEquals("appellantInPersonManual", Event.APPELLANT_IN_PERSON_MANUAL.toString());
165165
assertEquals("forceDecidedState", Event.FORCE_DECIDED_STATE.toString());
166+
assertEquals("forceFtpaDecidedState", Event.FORCE_FTPA_DECIDED_STATE.toString());
166167
}
167168

168169
@Test
169170
void if_this_test_fails_it_is_because_it_needs_updating_with_your_changes() {
170-
assertEquals(158, Event.values().length);
171+
assertEquals(159, Event.values().length);
171172
}
172173
}
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)