-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into CIV-15956
- Loading branch information
Showing
15 changed files
with
583 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/uk/gov/hmcts/reform/civil/enums/ObligationReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package uk.gov.hmcts.reform.civil.enums; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ObligationReason { | ||
UNLESS_ORDER("Unless order"), | ||
STAY_A_CASE("Stay a case"), | ||
LIFT_A_STAY("Lift a stay"), | ||
DISMISS_CASE("Dismiss case"), | ||
PRE_TRIAL_CHECKLIST("Pre trial checklist"), | ||
GENERAL_ORDER("General order"), | ||
RESERVE_JUDGMENT("Reserve Judgment"), | ||
OTHER("Other"); | ||
|
||
private final String displayedValue; | ||
} |
37 changes: 37 additions & 0 deletions
37
...rm/civil/handler/callback/camunda/caseevents/UpdateConfirmOrderReviewCallbackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.hmcts.reform.civil.handler.callback.camunda.caseevents; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.reform.civil.callback.Callback; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackHandler; | ||
import uk.gov.hmcts.reform.civil.callback.CallbackParams; | ||
import uk.gov.hmcts.reform.civil.callback.CaseEvent; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; | ||
import static uk.gov.hmcts.reform.civil.callback.CaseEvent.UPDATE_CONFIRM_REVIEW_ORDER_EVENT; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UpdateConfirmOrderReviewCallbackHandler extends CallbackHandler { | ||
|
||
private static final List<CaseEvent> EVENTS = List.of(UPDATE_CONFIRM_REVIEW_ORDER_EVENT); | ||
public static final String TASK_ID = "UpdateConfirmOrderReviewEvent"; | ||
|
||
@Override | ||
protected Map<String, Callback> callbacks() { | ||
return Map.of(callbackKey(ABOUT_TO_SUBMIT), this::emptyCallbackResponse); | ||
} | ||
|
||
@Override | ||
public String camundaActivityId(CallbackParams callbackParams) { | ||
return TASK_ID; | ||
} | ||
|
||
@Override | ||
public List<CaseEvent> handledEvents() { | ||
return EVENTS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
src/main/java/uk/gov/hmcts/reform/civil/handler/tasks/ConfirmOrderReviewTaskHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package uk.gov.hmcts.reform.civil.handler.tasks; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.camunda.bpm.client.exception.ValueMapperException; | ||
import org.camunda.bpm.client.task.ExternalTask; | ||
import org.springframework.stereotype.Component; | ||
import uk.gov.hmcts.reform.ccd.client.model.CaseDataContent; | ||
import uk.gov.hmcts.reform.ccd.client.model.Event; | ||
import uk.gov.hmcts.reform.ccd.client.model.StartEventResponse; | ||
import uk.gov.hmcts.reform.civil.callback.CaseEvent; | ||
import uk.gov.hmcts.reform.civil.enums.ObligationReason; | ||
import uk.gov.hmcts.reform.civil.exceptions.InvalidCaseDataException; | ||
import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; | ||
import uk.gov.hmcts.reform.civil.model.BusinessProcess; | ||
import uk.gov.hmcts.reform.civil.model.CaseData; | ||
import uk.gov.hmcts.reform.civil.model.ExternalTaskData; | ||
import uk.gov.hmcts.reform.civil.model.ObligationData; | ||
import uk.gov.hmcts.reform.civil.service.CoreCaseDataService; | ||
import uk.gov.hmcts.reform.civil.service.data.ExternalTaskInput; | ||
|
||
import java.util.Collections; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
/** | ||
* Handles the external camunda task for updating contact information. | ||
* This task handler retrieves caseId and caseEvent from the external task variables and the businessProcess | ||
*/ | ||
@RequiredArgsConstructor | ||
@Component | ||
public class ConfirmOrderReviewTaskHandler extends BaseExternalTaskHandler { | ||
|
||
private final CoreCaseDataService coreCaseDataService; | ||
private final CaseDetailsConverter caseDetailsConverter; | ||
private final ObjectMapper mapper; | ||
|
||
@Override | ||
public ExternalTaskData handleTask(ExternalTask externalTask) { | ||
try { | ||
ExternalTaskInput taskVariables = parseExternalTaskVariables(externalTask); | ||
|
||
String caseIdentifier = validateCaseId(taskVariables.getCaseId()); | ||
CaseEvent event = validateCaseEvent(taskVariables.getCaseEvent()); | ||
|
||
StartEventResponse startEvent = coreCaseDataService.startUpdate(caseIdentifier, event); | ||
|
||
coreCaseDataService.submitUpdate(caseIdentifier, caseDataContent(startEvent, externalTask)); | ||
|
||
return ExternalTaskData.builder().build(); | ||
} catch (ValueMapperException | IllegalArgumentException ex) { | ||
throw new InvalidCaseDataException("Mapper conversion failed due to incompatible types", ex); | ||
} | ||
} | ||
|
||
private ExternalTaskInput parseExternalTaskVariables(ExternalTask externalTask) { | ||
return mapper.convertValue(externalTask.getAllVariables(), ExternalTaskInput.class); | ||
} | ||
|
||
private String validateCaseId(String caseId) { | ||
return ofNullable(caseId) | ||
.orElseThrow(() -> new InvalidCaseDataException("The caseId was not provided")); | ||
} | ||
|
||
private CaseEvent validateCaseEvent(CaseEvent caseEvent) { | ||
return ofNullable(caseEvent) | ||
.orElseThrow(() -> new InvalidCaseDataException("The case event was not provided")); | ||
} | ||
|
||
private CaseDataContent caseDataContent(StartEventResponse startEventResponse, ExternalTask externalTask) { | ||
CaseData caseData = caseDetailsConverter.toCaseData(startEventResponse.getCaseDetails()); | ||
BusinessProcess businessProcess = updateProcessInstanceId(caseData.getBusinessProcess(), externalTask); | ||
|
||
String obligationReasons = getObligationReasons(caseData); | ||
String obligationActions = obligationActions(caseData); | ||
|
||
return CaseDataContent.builder() | ||
.eventToken(startEventResponse.getToken()) | ||
.event(Event.builder() | ||
.id(startEventResponse.getEventId()) | ||
.description(obligationActions) | ||
.summary(obligationReasons) | ||
.build()) | ||
.data(caseData.toBuilder() | ||
.businessProcess(businessProcess) | ||
.build().toMap(mapper)) | ||
.build(); | ||
} | ||
|
||
private BusinessProcess updateProcessInstanceId(BusinessProcess businessProcess, ExternalTask externalTask) { | ||
return businessProcess.hasSameProcessInstanceId(externalTask.getProcessInstanceId()) | ||
? businessProcess : businessProcess.updateProcessInstanceId(externalTask.getProcessInstanceId()); | ||
} | ||
|
||
private String getObligationReasons(CaseData caseData) { | ||
return Optional.ofNullable(caseData.getStoredObligationData()) | ||
.orElse(Collections.emptyList()) | ||
.stream() | ||
.map(element -> { | ||
ObligationData data = element.getValue(); | ||
ObligationReason reason = data.getObligationReason(); | ||
|
||
if (reason == ObligationReason.OTHER) { | ||
return reason.getDisplayedValue() + ": " + data.getOtherObligationReason(); | ||
} | ||
return reason.getDisplayedValue(); | ||
}) | ||
.collect(Collectors.joining(" --- ")); | ||
} | ||
|
||
private String obligationActions(CaseData caseData) { | ||
return Optional.ofNullable(caseData.getStoredObligationData()) | ||
.orElse(Collections.emptyList()) | ||
.stream() | ||
.map(element -> element.getValue().getObligationAction()) | ||
.collect(Collectors.joining(" --- ")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/uk/gov/hmcts/reform/civil/model/ObligationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uk.gov.hmcts.reform.civil.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import uk.gov.hmcts.reform.civil.enums.ObligationReason; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
@Builder(toBuilder = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ObligationData { | ||
|
||
private LocalDate obligationDate; | ||
private ObligationReason obligationReason; | ||
private String otherObligationReason; | ||
private String obligationAction; | ||
} |
Oops, something went wrong.