Skip to content

Commit

Permalink
Feat/civ 4541 (#2661)
Browse files Browse the repository at this point in the history
* update ccd with page increment and cron exp.

* fix params and import

* update yml file

* update Resource reader

* add tests for CoreCaseDataService

* checkstyle

* non-null contraints

* enhance null checks

* remove un-used imports

* more null checks

* update null checks

update ccd with page increment and cron exp.

fix params and import

update yml file

update Resource reader

add tests for CoreCaseDataService

checkstyle

non-null contraints

enhance null checks

remove un-used imports

* amend constraint

* fix page increment

* fix cron exp.

* rebase branch

* add supression

* update schedule

* update charts

* add larger page process capacity

* add larger page process capacity

* update chart

* add supression

* Update suppressions.xml

* update master and add necessary changes

* update cron exp

---------

Co-authored-by: mounikahmcts <43175082+mounikahmcts@users.noreply.github.com>
Co-authored-by: mfallonhmcts <114912573+mfallonhmcts@users.noreply.github.com>
Co-authored-by: kdaHMCTS <128375235+kdaHMCTS@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 3, 2023
1 parent a1f77d9 commit 8c70937
Show file tree
Hide file tree
Showing 7 changed files with 497 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package uk.gov.hmcts.cmc.claimstore.jobs.cron;

import lombok.Getter;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.cmc.claimstore.services.ccd.callbacks.caseworker.transfercase.TransferCaseStayedService;
import uk.gov.hmcts.cmc.scheduler.model.CronJob;

@Component
@Getter
@DisallowConcurrentExecution
public class ScheduleCaseStayedStateTransition implements CronJob {

@Value("${schedule.transfer-stayed-claims}")
private String cronExpression;

private TransferCaseStayedService caseStayedTransferService;

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
try {
caseStayedTransferService.findCasesForTransfer();
} catch (Exception e) {
throw new JobExecutionException(e);
}
}

@Autowired
public void setCaseStayedTransferService(TransferCaseStayedService caseStayedTransferService) {
this.caseStayedTransferService = caseStayedTransferService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -915,6 +916,46 @@ public CaseDetails update(String authorisation, CCDCase ccdCase, CaseEvent caseE
}
}

public CaseDetails caseTransferUpdate(String authorisation, CCDCase ccdCase, CaseEvent caseEvent) {
try {
UserDetails userDetails = userService.getUserDetails(authorisation);
Long caseId = ccdCase.getId();
EventRequestData eventRequestData = EventRequestData.builder()
.userId(userDetails.getId())
.jurisdictionId(JURISDICTION_ID)
.caseTypeId(CASE_TYPE_ID)
.eventId(caseEvent.getValue())
.ignoreWarning(true)
.build();

StartEventResponse startEventResponse = startUpdate(
authorisation,
eventRequestData,
caseId,
isRepresented(userDetails)
);

CaseDataContent caseDataContent = CaseDataContentBuilder.build(
startEventResponse,
CMC_CASE_UPDATE_SUMMARY,
SUBMITTING_CMC_CASE_UPDATE_DESCRIPTION,
ccdCase
);

return submitUpdate(authorisation, eventRequestData, caseDataContent, caseId,
isRepresented(userDetails));
} catch (Exception exception) {
logger.error("Error communicating with CCD API");
throw new CoreCaseDataStoreException(
String.format(
"Failed updating claim in CCD store for claim %s on event %s",
ccdCase.getPreviousServiceCaseReference(),
caseEvent
), exception
);
}
}

private StartEventResponse startUpdate(
String authorisation,
EventRequestData eventRequestData,
Expand Down Expand Up @@ -1368,4 +1409,33 @@ public Claim saveBreathingSpaceDetails(Claim claim, BreathingSpace breathingSpac
}
return caseDetailsConverter.extractClaim(update(authorisation, ccdCase, CaseEvent.BREATHING_SPACE_LIFTED));
}

public List<CaseDetails> searchCases(String authorisation,
String userId,
Map<String, String> searchCriteria) {

return coreCaseDataApi.searchForCaseworker(
authorisation,
authTokenGenerator.generate(),
userId,
JURISDICTION_ID,
CASE_TYPE_ID,
searchCriteria
);
}

public Integer getPaginationInfo(String authorisation,
String userId,
Map<String, String> searchCriteria
) {
return coreCaseDataApi.getPaginationInfoForSearchForCaseworkers(
authorisation,
authTokenGenerator.generate(),
userId,
JURISDICTION_ID,
CASE_TYPE_ID,
searchCriteria
).getTotalPagesCount();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package uk.gov.hmcts.cmc.claimstore.services.ccd.callbacks.caseworker.transfercase;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONArray;
import org.springframework.stereotype.Service;
import uk.gov.hmcts.cmc.ccd.domain.CCDCase;
import uk.gov.hmcts.cmc.ccd.domain.CaseEvent;
import uk.gov.hmcts.cmc.claimstore.models.idam.User;
import uk.gov.hmcts.cmc.claimstore.requests.idam.IdamApi;
import uk.gov.hmcts.cmc.claimstore.services.UserService;
import uk.gov.hmcts.cmc.claimstore.services.ccd.CoreCaseDataService;
import uk.gov.hmcts.cmc.domain.models.ClaimState;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@AllArgsConstructor
@Service
@Slf4j
public class TransferCaseStayedService {

private final CoreCaseDataService coreCaseDataService;
private final UserService userService;
private final IdamApi idamApi;

private static final int MAX_ALLOWED_PAGE_PROCESS = 1000;

public void findCasesForTransfer() {

User user = userService.authenticateAnonymousCaseWorker();
String authorisation = user.getAuthorisation();
String userId = idamApi.retrieveUserDetails(authorisation).getId();

Integer numberOfPages = getNumberOfPages(authorisation, userId);
int pageNumber = 1;

log.info("Comparing cases to update into ccd");

do {
compareCases(authorisation, userId, pageNumber);
pageNumber++;
if (pageNumber == (MAX_ALLOWED_PAGE_PROCESS + 1)) {
break;
}
} while (pageNumber <= numberOfPages);
}

public void compareCases(String authorisation, String userId, Integer pageNumber) {
Integer numberOfPages = getNumberOfPages(authorisation, userId);

var listOfCases = listCasesWithDeadLIne(
authorisation,
userId,
pageNumber <= numberOfPages && pageNumber > 0
? pageNumber : 1
);

LocalDate currentDate = LocalDate.now();

JSONArray listOfCasesJson = !listOfCases.isEmpty()
? new JSONArray(listOfCases) : null;

for (int caseIndex = 0; caseIndex < listOfCases.size(); caseIndex++) {
String intentionToProceedDeadline = null;
Long caseId = null;

if (listOfCasesJson.get(caseIndex) != null
&& !listOfCasesJson.isEmpty()
&& listOfCasesJson != null
) {

intentionToProceedDeadline = listOfCasesJson
.getJSONObject(caseIndex)
.get("intentionToProceedDeadline").toString();

caseId = Long.parseLong(
listOfCasesJson
.getJSONObject(caseIndex)
.get("id").toString());
}

boolean currentDateAfter = intentionToProceedDeadline != null && currentDate
.isAfter(LocalDate
.parse(intentionToProceedDeadline));

CCDCase ccdStayClaim = caseId != null ? CCDCase.builder()
.id(caseId)
.build() : null;

if (currentDateAfter && ccdStayClaim != null) {
coreCaseDataService.caseTransferUpdate(
authorisation,
ccdStayClaim,
CaseEvent.STAY_CLAIM
);
}
}
}

private Integer getNumberOfPages(String authorisation, String userId) {
return coreCaseDataService.getPaginationInfo(
authorisation,
userId,
getSearchCriteria(false, null)
);
}

private Map<String, String> getSearchCriteria(boolean isSearchingPerPageEnabled, Integer pageNumber) {
Map<String, String> searchCriteria = new HashMap<>();

if (isSearchingPerPageEnabled && pageNumber != null) {
searchCriteria.put("page", pageNumber.toString());
}

searchCriteria.put("sortDirection", "asc");
searchCriteria.put("state", ClaimState.OPEN.getValue());

return searchCriteria;
}

private List<Object> listCasesWithDeadLIne(String authorisation, String userId, Integer pageNumber) {
var searchedCases = new ArrayList<>(coreCaseDataService.searchCases(
authorisation,
userId,
getSearchCriteria(
true,
pageNumber
)
));

List<Object> claimsList = new ArrayList<>();
List<Object> generatedList = new ArrayList<>();
int index = -1;

for (var searchedCase : searchedCases) {
Map<String, Object> searchedCaseDataMap = searchedCase.getData();
index++;
claimsList.add(searchedCaseDataMap);
for (Map.Entry<String, Object> entry : searchedCaseDataMap.entrySet()) {
if (entry.getKey().contains("intentionToProceedDeadline")) {
generatedList.add(claimsList.get(index));
}
}
}
return generatedList;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gov.hmcts.cmc.claimstore.utils;

import uk.gov.hmcts.cmc.ccd.domain.CCDCase;
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;
Expand Down Expand Up @@ -34,6 +35,23 @@ public static CaseDataContent build(
.build();
}

public static CaseDataContent build(
StartEventResponse startEventResponse,
String eventSummary,
String eventDescription,
CCDCase ccdCase) {

return CaseDataContent.builder()
.eventToken(startEventResponse.getToken())
.event(Event.builder()
.id(startEventResponse.getEventId())
.summary(eventSummary)
.description(eventDescription)
.build())
.data(ccdCase)
.build();
}

private static HashMap<String, Object> initHashMap(StartEventResponse startEventResponse) {
return hasCaseData(startEventResponse)
? new HashMap<>(startEventResponse.getCaseDetails().getData())
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ schedule:
transfer-claims: ""
issue-created-claims: "0 0 8,17,23 ? * * *"
close-hwf-claims-in-awaiting-state: "${SCHEDULE_CLOSE_HWF_CLAIMS_IN_AWAITING_STATE:}"
transfer-stayed-claims: "0 0 23,2,5 ? * * *"
state-transition:
waiting-transfer: ""
stay-claim: ""
Expand Down
Loading

0 comments on commit 8c70937

Please sign in to comment.