Skip to content

Commit

Permalink
DMP-4613 Add ARM RPO check for getExtendedProductionsByMatter status
Browse files Browse the repository at this point in the history
Added PMD fixes
  • Loading branch information
karen-hedges committed Jan 19, 2025
1 parent 4606362 commit 4857e52
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"responseStatus": 0,
"productions": [
{
"productionID": "1b6a29d9-a72e-420b-8d69-b8acbeed806a"
"productionID": "1b6a29d9-a72e-420b-8d69-b8acbeed806a",
"name": "DARTS_RPO_2024-08-13_CSV",
"status": 4
}
]
}
94 changes: 74 additions & 20 deletions src/main/java/uk/gov/hmcts/darts/arm/rpo/impl/ArmRpoApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ArmRpoApiImpl implements ArmRpoApi {

private static final int READY_STATUS = 4;
private static final int CONNECTION_FAILED = 5;
public static final String COULD_NOT_CONSTRUCT_API_REQUEST = "Could not construct API request: ";

private final ArmRpoClient armRpoClient;
private final ArmRpoService armRpoService;
Expand All @@ -90,7 +91,7 @@ public void getRecordManagementMatter(String bearerToken, Integer executionId, U
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, ArmRpoHelper.getRecordManagementMatterRpoState(),
ArmRpoHelper.inProgressRpoStatus(), userAccount);

StringBuilder errorMessage = new StringBuilder("Failure during ARM RPO getRecordManagementMatter: ");
StringBuilder errorMessage = new StringBuilder(96).append("Failure during ARM RPO getRecordManagementMatter: ");
RecordManagementMatterResponse recordManagementMatterResponse;
try {
EmptyRpoRequest emptyRpoRequest = EmptyRpoRequest.builder().build();
Expand Down Expand Up @@ -118,7 +119,7 @@ public void getIndexesByMatterId(String bearerToken, Integer executionId, String
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, ArmRpoHelper.getIndexesByMatterIdRpoState(),
ArmRpoHelper.inProgressRpoStatus(), userAccount);

StringBuilder errorMessage = new StringBuilder("Failure during ARM RPO get indexes by matter ID: ");
StringBuilder errorMessage = new StringBuilder(151).append("Failure during ARM RPO get indexes by matter ID: ");
IndexesByMatterIdResponse indexesByMatterIdResponse;
try {
indexesByMatterIdResponse = armRpoClient.getIndexesByMatterId(bearerToken, createIndexesByMatterIdRequest(matterId));
Expand All @@ -127,6 +128,12 @@ public void getIndexesByMatterId(String bearerToken, Integer executionId, String
throw handleFailureAndCreateException(errorMessage.toString(), armRpoExecutionDetailEntity, userAccount);
}

processIndexesByMatterIdResponse(matterId, userAccount, indexesByMatterIdResponse, errorMessage, armRpoExecutionDetailEntity);
}

private void processIndexesByMatterIdResponse(String matterId, UserAccountEntity userAccount, IndexesByMatterIdResponse indexesByMatterIdResponse,
StringBuilder errorMessage,
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {
handleResponseStatus(userAccount, indexesByMatterIdResponse, errorMessage, armRpoExecutionDetailEntity);

if (CollectionUtils.isEmpty(indexesByMatterIdResponse.getIndexes())
Expand Down Expand Up @@ -167,6 +174,11 @@ public void getStorageAccounts(String bearerToken, Integer executionId, UserAcco
throw handleFailureAndCreateException(errorMessage.toString(), armRpoExecutionDetailEntity, userAccount);
}

processGetStorageAccountsResponse(userAccount, storageAccountResponse, errorMessage, armRpoExecutionDetailEntity);
}

private void processGetStorageAccountsResponse(UserAccountEntity userAccount, StorageAccountResponse storageAccountResponse, StringBuilder errorMessage,
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {
handleResponseStatus(userAccount, storageAccountResponse, errorMessage, armRpoExecutionDetailEntity);

if (!CollectionUtils.isNotEmpty(storageAccountResponse.getDataDetails())) {
Expand Down Expand Up @@ -205,7 +217,7 @@ public void getProfileEntitlements(String bearerToken, Integer executionId, User
ArmRpoHelper.inProgressRpoStatus(),
userAccount);

final StringBuilder exceptionMessageBuilder = new StringBuilder("ARM getProfileEntitlements: ");
final StringBuilder exceptionMessageBuilder = new StringBuilder(90).append("ARM getProfileEntitlements: ");
ProfileEntitlementResponse response;
try {
EmptyRpoRequest emptyRpoRequest = EmptyRpoRequest.builder().build();
Expand All @@ -216,6 +228,12 @@ public void getProfileEntitlements(String bearerToken, Integer executionId, User
.toString(),
executionDetail, userAccount);
}
processGetProfileEntitlementsResponse(userAccount, response, exceptionMessageBuilder, executionDetail);
}

private void processGetProfileEntitlementsResponse(UserAccountEntity userAccount, ProfileEntitlementResponse response,
StringBuilder exceptionMessageBuilder,
ArmRpoExecutionDetailEntity executionDetail) {
handleResponseStatus(userAccount, response, exceptionMessageBuilder, executionDetail);

var entitlements = response.getEntitlements();
Expand Down Expand Up @@ -254,7 +272,7 @@ public List<MasterIndexFieldByRecordClassSchema> getMasterIndexFieldByRecordClas
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, rpoStateEntity,
ArmRpoHelper.inProgressRpoStatus(), userAccount);

StringBuilder errorMessage = new StringBuilder("Failure during ARM get master index field by record class schema: ");
StringBuilder errorMessage = new StringBuilder(273).append("Failure during ARM get master index field by record class schema: ");

if (!(ArmRpoHelper.getMasterIndexFieldByRecordClassSchemaPrimaryRpoState().getId().equals(rpoStateEntity.getId())
|| ArmRpoHelper.getMasterIndexFieldByRecordClassSchemaSecondaryRpoState().getId().equals(rpoStateEntity.getId()))) {
Expand All @@ -271,6 +289,13 @@ public List<MasterIndexFieldByRecordClassSchema> getMasterIndexFieldByRecordClas
throw handleFailureAndCreateException(errorMessage.toString(), armRpoExecutionDetailEntity, userAccount);
}

return processMasterIndexFieldByRecordClassSchemas(userAccount, masterIndexFieldByRecordClassSchemaResponse, errorMessage, armRpoExecutionDetailEntity);
}

private List<MasterIndexFieldByRecordClassSchema> processMasterIndexFieldByRecordClassSchemas(
UserAccountEntity userAccount, MasterIndexFieldByRecordClassSchemaResponse masterIndexFieldByRecordClassSchemaResponse,
StringBuilder errorMessage, ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {

if (isNull(masterIndexFieldByRecordClassSchemaResponse)
|| CollectionUtils.isEmpty(masterIndexFieldByRecordClassSchemaResponse.getMasterIndexFields())) {
throw handleFailureAndCreateException(errorMessage.append("Unable to find master index fields in response").toString(),
Expand Down Expand Up @@ -314,7 +339,7 @@ public String addAsyncSearch(String bearerToken, Integer executionId, UserAccoun
now.format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"))
);

final StringBuilder exceptionMessageBuilder = new StringBuilder("ARM addAsyncSearch: ");
final StringBuilder exceptionMessageBuilder = new StringBuilder(99).append("ARM addAsyncSearch: ");
ArmAutomatedTaskEntity armAutomatedTaskEntity = armAutomatedTaskRepository.findByAutomatedTask_taskName(ADD_ASYNC_SEARCH_RELATED_TASK_NAME)
.orElseThrow(() -> handleFailureAndCreateException(exceptionMessageBuilder.append("Automated task not found: ")
.append(ADD_ASYNC_SEARCH_RELATED_TASK_NAME)
Expand All @@ -325,7 +350,7 @@ public String addAsyncSearch(String bearerToken, Integer executionId, UserAccoun
try {
requestGenerator = createAddAsyncSearchRequestGenerator(searchName, executionDetail, armAutomatedTaskEntity, now);
} catch (Exception e) {
throw handleFailureAndCreateException(exceptionMessageBuilder.append("Could not construct API request: ")
throw handleFailureAndCreateException(exceptionMessageBuilder.append(COULD_NOT_CONSTRUCT_API_REQUEST)
.append(e)
.toString(),
executionDetail, userAccount);
Expand All @@ -340,12 +365,16 @@ public String addAsyncSearch(String bearerToken, Integer executionId, UserAccoun
.toString(),
executionDetail, userAccount);
}
return processAddAsyncSearch(userAccount, response, exceptionMessageBuilder, executionDetail, searchName);
}

private String processAddAsyncSearch(UserAccountEntity userAccount, ArmAsyncSearchResponse response, StringBuilder exceptionMessageBuilder,
ArmRpoExecutionDetailEntity executionDetail, String searchName) {
handleResponseStatus(userAccount, response, exceptionMessageBuilder, executionDetail);

String searchId = response.getSearchId();
if (searchId == null) {
throw handleFailureAndCreateException(exceptionMessageBuilder.append("The obtained search id was empty")
.toString(),
throw handleFailureAndCreateException(exceptionMessageBuilder.append("The obtained search id was empty").toString(),
executionDetail, userAccount);
}

Expand All @@ -363,7 +392,7 @@ public void saveBackgroundSearch(String bearerToken, Integer executionId, String
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, ArmRpoHelper.saveBackgroundSearchRpoState(),
ArmRpoHelper.inProgressRpoStatus(), userAccount);

StringBuilder errorMessage = new StringBuilder("Failure during ARM save background search: ");
StringBuilder errorMessage = new StringBuilder(134).append("Failure during ARM save background search: ");
SaveBackgroundSearchResponse saveBackgroundSearchResponse;
try {
SaveBackgroundSearchRequest saveBackgroundSearchRequest =
Expand All @@ -386,12 +415,12 @@ public String getExtendedSearchesByMatter(String bearerToken, Integer executionI
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, ArmRpoHelper.getExtendedSearchesByMatterRpoState(),
ArmRpoHelper.inProgressRpoStatus(), userAccount);

StringBuilder errorMessage = new StringBuilder("Failure during ARM RPO getExtendedSearchesByMatter: ");
StringBuilder errorMessage = new StringBuilder(153).append("Failure during ARM RPO getExtendedSearchesByMatter: ");
GetExtendedSearchesByMatterRequestGenerator requestGenerator;
try {
requestGenerator = createExtendedSearchesByMatterRequestGenerator(armRpoExecutionDetailEntity.getMatterId());
} catch (Exception e) {
throw handleFailureAndCreateException(errorMessage.append("Could not construct API request: ").append(e)
throw handleFailureAndCreateException(errorMessage.append(COULD_NOT_CONSTRUCT_API_REQUEST).append(e)
.toString(), armRpoExecutionDetailEntity, userAccount);
}

Expand All @@ -405,6 +434,12 @@ public String getExtendedSearchesByMatter(String bearerToken, Integer executionI

handleResponseStatus(userAccount, extendedSearchesByMatterResponse, errorMessage, armRpoExecutionDetailEntity);

return processExtendedSearchesByMatterResponse(executionId, userAccount, extendedSearchesByMatterResponse, errorMessage, armRpoExecutionDetailEntity);
}

private String processExtendedSearchesByMatterResponse(Integer executionId, UserAccountEntity userAccount,
ExtendedSearchesByMatterResponse extendedSearchesByMatterResponse,
StringBuilder errorMessage, ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {
if (isNull(extendedSearchesByMatterResponse.getSearches())
|| CollectionUtils.isEmpty(extendedSearchesByMatterResponse.getSearches())) {

Expand All @@ -416,11 +451,11 @@ public String getExtendedSearchesByMatter(String bearerToken, Integer executionI

ExtendedSearchesByMatterResponse.SearchDetail searchDetailMatch = null;
for (ExtendedSearchesByMatterResponse.SearchDetail searchDetail : extendedSearchesByMatterResponse.getSearches()) {
if (nonNull(searchDetail.getSearch()) && !StringUtils.isBlank(searchDetail.getSearch().getSearchId())) {
if (searchDetail.getSearch().getSearchId().equals(searchId)) {
searchDetailMatch = searchDetail;
break;
}
if (nonNull(searchDetail.getSearch())
&& !StringUtils.isBlank(searchDetail.getSearch().getSearchId())
&& searchDetail.getSearch().getSearchId().equals(searchId)) {
searchDetailMatch = searchDetail;
break;
}
}
if (isNull(searchDetailMatch)
Expand Down Expand Up @@ -461,7 +496,7 @@ public boolean createExportBasedOnSearchResultsTable(String bearerToken, Integer
armRpoExecutionDetailEntity.getStorageAccountId()
);
} catch (Exception e) {
throw handleFailureAndCreateException(errorMessage.append("Could not construct API request: ").append(e).toString(),
throw handleFailureAndCreateException(errorMessage.append(COULD_NOT_CONSTRUCT_API_REQUEST).append(e).toString(),
armRpoExecutionDetailEntity, userAccount);
}
CreateExportBasedOnSearchResultsTableResponse response;
Expand All @@ -472,6 +507,12 @@ public boolean createExportBasedOnSearchResultsTable(String bearerToken, Integer
log.error(errorMessage.append(UNABLE_TO_GET_ARM_RPO_RESPONSE).append(e).toString(), e);
throw handleFailureAndCreateException(errorMessage.toString(), armRpoExecutionDetailEntity, userAccount);
}
return processCreateExportBasedOnSearchResultsTableResponse(userAccount, response, errorMessage, armRpoExecutionDetailEntity);
}

private boolean processCreateExportBasedOnSearchResultsTableResponse(UserAccountEntity userAccount, CreateExportBasedOnSearchResultsTableResponse response,
StringBuilder errorMessage,
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {
if (isNull(response) || isNull(response.getStatus()) || isNull(response.getIsError())
|| (!response.getIsError() && isNull(response.getResponseStatus()))
) {
Expand Down Expand Up @@ -517,7 +558,7 @@ public boolean getExtendedProductionsByMatter(String bearerToken, Integer execut
try {
requestGenerator = createExtendedProductionsByMatterRequest(armRpoExecutionDetailEntity.getMatterId());
} catch (Exception e) {
throw handleFailureAndCreateException(errorMessage.append("Could not construct API request: ").append(e)
throw handleFailureAndCreateException(errorMessage.append(COULD_NOT_CONSTRUCT_API_REQUEST).append(e)
.toString(), armRpoExecutionDetailEntity, userAccount);
}

Expand All @@ -529,6 +570,13 @@ public boolean getExtendedProductionsByMatter(String bearerToken, Integer execut
throw handleFailureAndCreateException(errorMessage.toString(), armRpoExecutionDetailEntity, userAccount);
}

return processExtendedProductionsByMatterResponse(productionName, userAccount, extendedProductionsByMatterResponse, errorMessage,
armRpoExecutionDetailEntity);
}

private boolean processExtendedProductionsByMatterResponse(String productionName, UserAccountEntity userAccount,
ExtendedProductionsByMatterResponse extendedProductionsByMatterResponse,
StringBuilder errorMessage, ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) {
handleResponseStatus(userAccount, extendedProductionsByMatterResponse, errorMessage, armRpoExecutionDetailEntity);
if (isNull(extendedProductionsByMatterResponse.getProductions())
|| CollectionUtils.isEmpty(extendedProductionsByMatterResponse.getProductions())) {
Expand Down Expand Up @@ -571,7 +619,7 @@ public List<String> getProductionOutputFiles(String bearerToken, Integer executi
ArmRpoHelper.inProgressRpoStatus(),
userAccount);

final StringBuilder exceptionMessageBuilder = new StringBuilder("ARM getProductionOutputFiles: ");
final StringBuilder exceptionMessageBuilder = new StringBuilder(135).append("ARM getProductionOutputFiles: ");

String productionId = executionDetail.getProductionId();
if (StringUtils.isBlank(productionId)) {
Expand All @@ -590,6 +638,12 @@ public List<String> getProductionOutputFiles(String bearerToken, Integer executi
.toString(),
executionDetail, userAccount);
}
return processProductionOutputFilesResponse(userAccount, response, exceptionMessageBuilder, executionDetail);
}

private List<String> processProductionOutputFilesResponse(UserAccountEntity userAccount, ProductionOutputFilesResponse response,
StringBuilder exceptionMessageBuilder,
ArmRpoExecutionDetailEntity executionDetail) {
handleResponseStatus(userAccount, response, exceptionMessageBuilder, executionDetail);

List<ProductionOutputFilesResponse.ProductionExportFile> productionExportFiles = response.getProductionExportFiles();
Expand Down Expand Up @@ -627,7 +681,7 @@ public InputStream downloadProduction(String bearerToken, Integer executionId, S
ArmRpoHelper.inProgressRpoStatus(), userAccount);

feign.Response response;
StringBuilder errorMessage = new StringBuilder("Failure during download production: ");
StringBuilder errorMessage = new StringBuilder(185).append("Failure during download production: ");

try {
response = armRpoDownloadProduction.downloadProduction(bearerToken, executionId, productionExportFileId);
Expand Down

0 comments on commit 4857e52

Please sign in to comment.