-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
a1f77d9
commit 8c70937
Showing
7 changed files
with
497 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/main/java/uk/gov/hmcts/cmc/claimstore/jobs/cron/ScheduleCaseStayedStateTransition.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,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; | ||
} | ||
} |
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
151 changes: 151 additions & 0 deletions
151
.../claimstore/services/ccd/callbacks/caseworker/transfercase/TransferCaseStayedService.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,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; | ||
} | ||
} |
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
Oops, something went wrong.