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
Fixed sonar complaint
  • Loading branch information
karen-hedges committed Jan 22, 2025
1 parent dbe917d commit 99b7bf9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
10 changes: 6 additions & 4 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 @@ -56,6 +56,7 @@
import java.util.Objects;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static uk.gov.hmcts.darts.arm.enums.ArmRpoResponseStatusCode.IN_PROGRESS_STATUS;
Expand All @@ -76,6 +77,7 @@ public class ArmRpoApiImpl implements ArmRpoApi {
private static final String CREATE_EXPORT_CSV_EXTENSION = "_CSV";

private static final String COULD_NOT_CONSTRUCT_API_REQUEST = "Could not construct API request: ";
public static final String AND_RESPONSE = " and response - ";

private final ArmRpoClient armRpoClient;
private final ArmRpoService armRpoService;
Expand Down Expand Up @@ -524,13 +526,13 @@ private boolean processCreateExportBasedOnSearchResultsTableResponse(
return false;
} else {
throw handleFailureAndCreateException(errorMessage.append("ARM RPO API failed with invalid status - ").append(responseStatus)
.append(" and response - ").append(
.append(AND_RESPONSE).append(
createExportBasedOnSearchResultsTableResponse).toString(),
armRpoExecutionDetailEntity, userAccount);
}
} else if (!responseStatus.is2xxSuccessful() || createExportBasedOnSearchResultsTableResponse.getIsError()) {
} else if (!responseStatus.is2xxSuccessful() || TRUE.equals(createExportBasedOnSearchResultsTableResponse.getIsError())) {
throw handleFailureAndCreateException(errorMessage.append("ARM RPO API failed with status - ").append(responseStatus)
.append(" and response - ").append(
.append(AND_RESPONSE).append(
createExportBasedOnSearchResultsTableResponse).toString(),
armRpoExecutionDetailEntity, userAccount);
}
Expand Down Expand Up @@ -786,7 +788,7 @@ private void handleResponseStatus(UserAccountEntity userAccount, BaseRpoResponse
HttpStatus responseStatus = HttpStatus.valueOf(baseRpoResponse.getStatus());
if (!responseStatus.is2xxSuccessful() || baseRpoResponse.getIsError()) {
throw handleFailureAndCreateException(errorMessage.append("ARM RPO API failed with status - ").append(responseStatus)
.append(" and response - ").append(baseRpoResponse).toString(),
.append(AND_RESPONSE).append(baseRpoResponse).toString(),
armRpoExecutionDetailEntity, userAccount);
}
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,7 @@ public void pollArmRpo(boolean isManualRun) {
boolean createExportBasedOnSearchResultsTable = armRpoApi.createExportBasedOnSearchResultsTable(
bearerToken, executionId, headerColumns, productionName, userAccount);
if (createExportBasedOnSearchResultsTable) {
// step to call ARM RPO API to get the extended productions by matter
boolean getExtendedProductionsByMatter = armRpoApi.getExtendedProductionsByMatter(bearerToken, executionId, productionName, userAccount);
if (getExtendedProductionsByMatter) {
// step to call ARM RPO API to get the production output files
var productionOutputFiles = armRpoApi.getProductionOutputFiles(bearerToken, executionId, userAccount);

for (var productionExportFileId : productionOutputFiles) {
processProductionFiles(productionExportFileId, bearerToken, executionId, userAccount);
}
if (CollectionUtils.isNotEmpty(tempProductionFiles)) {
// step to call ARM RPO API to remove the production
armRpoApi.removeProduction(bearerToken, executionId, userAccount);
log.debug("About to reconcile production files");
armRpoService.reconcileArmRpoCsvData(armRpoExecutionDetailEntity, tempProductionFiles);
} else {
log.warn("No production export files found");
}
logApi.armRpoPollingSuccessful(executionId);
} else {
log.warn("ARM RPO Polling is still in-progress for getExtendedProductionsByMatter");
}
processProductions(bearerToken, executionId, productionName, userAccount, armRpoExecutionDetailEntity);
} else {
log.warn("ARM RPO Polling is still in-progress for createExportBasedOnSearchResultsTable");
}
Expand All @@ -117,6 +97,31 @@ public void pollArmRpo(boolean isManualRun) {
}
}

private void processProductions(String bearerToken, Integer executionId, String productionName, UserAccountEntity userAccount,
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity) throws IOException {
// step to call ARM RPO API to get the extended productions by matter
boolean getExtendedProductionsByMatter = armRpoApi.getExtendedProductionsByMatter(bearerToken, executionId, productionName, userAccount);
if (getExtendedProductionsByMatter) {
// step to call ARM RPO API to get the production output files
var productionOutputFiles = armRpoApi.getProductionOutputFiles(bearerToken, executionId, userAccount);

for (var productionExportFileId : productionOutputFiles) {
processProductionFiles(productionExportFileId, bearerToken, executionId, userAccount);
}
if (CollectionUtils.isNotEmpty(tempProductionFiles)) {
// step to call ARM RPO API to remove the production
armRpoApi.removeProduction(bearerToken, executionId, userAccount);
log.debug("About to reconcile production files");
armRpoService.reconcileArmRpoCsvData(armRpoExecutionDetailEntity, tempProductionFiles);
} else {
log.warn("No production export files found");
}
logApi.armRpoPollingSuccessful(executionId);
} else {
log.warn("ARM RPO Polling is still in-progress for getExtendedProductionsByMatter");
}
}

private void processProductionFiles(String productionExportFileId, String bearerToken, Integer executionId,
UserAccountEntity userAccount) throws IOException {
String productionExportFilename = generateTempProductionExportFilename(productionExportFileId);
Expand Down

0 comments on commit 99b7bf9

Please sign in to comment.