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
1) Add to the ARM RPO getExtendedProductionsByMatter object status and check that it is either 4 or 5.

4 represents READY

5 represents CONNECTION_ERROR

If neither status don't move on, just keep as in-progress.

2) Add getExtendedProductionsByMatter in-progress to re-polling states

3) Fix bug where first search name is being return by getExtendedSearchesByMatter instead of the matching search items name

4) Change  getExtendedProductionsByMatter to not return the production id of the first production but the one that matches the search name for point 3.
  • Loading branch information
karen-hedges committed Jan 19, 2025
1 parent ba3152b commit 7de10f2
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ArmRpoApiCreateExportBasedOnSearchResultsTableIntTest extends PostgresInte
@Autowired
private ArmRpoApi armRpoApi;


@Test
void createExportBasedOnSearchResultsTable_ReturnsTrue() {
// given
Expand Down Expand Up @@ -101,9 +100,8 @@ void createExportBasedOnSearchResultsTable_ReturnsFalse_WhenInProgress() {
private List<MasterIndexFieldByRecordClassSchema> createHeaderColumns() {
return List.of(
createMasterIndexFieldByRecordClassSchema("200b9c27-b497-4977-82e7-1586b32a5871", "Record Class", "record_class", "string", false),
createMasterIndexFieldByRecordClassSchema("90ee0e13-8639-4c4a-b542-66b6c8911549", "Archived Date", "ingestionDate", "date", false),
createMasterIndexFieldByRecordClassSchema("a9b8daf2-d9ff-4815-b65a-f6ae2763b92c", "Client Identifier", "client_identifier", "string",
false),
createMasterIndexFieldByRecordClassSchema("90ee0e13-8639-4c4a-b542-66b6c8911549", "Archived Date", "ingestionDate", "date", true),
createMasterIndexFieldByRecordClassSchema("a9b8daf2-d9ff-4815-b65a-f6ae2763b92c", "Client Identifier", "client_identifier", "string", false),
createMasterIndexFieldByRecordClassSchema("109b6bf1-57a0-48ec-b22e-c7248dc74f91", "Contributor", "contributor", "string", false),
createMasterIndexFieldByRecordClassSchema("893048bf-1e7c-4811-9abf-00cd77a715cf", "Record Date", "recordDate", "date", false),
createMasterIndexFieldByRecordClassSchema("fdd0fcbb-da46-4af1-a627-ac255c12bb23", "ObjectId", "bf_012", "number", false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uk.gov.hmcts.darts.arm.rpo;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import uk.gov.hmcts.darts.arm.client.ArmRpoClient;
Expand All @@ -15,11 +17,14 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

class ArmRpoApiGetExtendedProductionsByMatterIntTest extends IntegrationBase {

public static final String PRODUCTION_NAME = "DARTS_RPO_2024-08-13";
@MockBean
private ArmRpoClient armRpoClient;

Expand All @@ -29,14 +34,17 @@ class ArmRpoApiGetExtendedProductionsByMatterIntTest extends IntegrationBase {
@Autowired
private ArmRpoApi armRpoApi;

@Test
void getExtendedSearchesByMatterSuccess() {
@ParameterizedTest
@ValueSource(ints = {4, 5})
void getExtendedSearchesByMatter_ReturnsTrue_WithValidStatus(int status) {
// given
ExtendedProductionsByMatterResponse extendedProductionsByMatterResponse = new ExtendedProductionsByMatterResponse();
extendedProductionsByMatterResponse.setStatus(200);
extendedProductionsByMatterResponse.setIsError(false);
ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions();
productions.setProductionId("4");
productions.setProductionId("1234");
productions.setStatus(status);
productions.setName(PRODUCTION_NAME);
extendedProductionsByMatterResponse.setProductions(List.of(productions));

when(armRpoClient.getExtendedProductionsByMatter(any(), any())).thenReturn(extendedProductionsByMatterResponse);
Expand All @@ -50,13 +58,47 @@ void getExtendedSearchesByMatterSuccess() {
var bearerAuth = "Bearer some-token";

// when
armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), userAccount);
var result = armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), PRODUCTION_NAME, userAccount);

// then
assertTrue(result);
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get();
assertEquals(ArmRpoStateEnum.GET_EXTENDED_PRODUCTIONS_BY_MATTER.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.COMPLETED.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId());
assertEquals("4", armRpoExecutionDetailEntityUpdated.getProductionId());
assertEquals("1234", armRpoExecutionDetailEntityUpdated.getProductionId());

}

@Test
void getExtendedSearchesByMatter_ReturnsFalse_WhenInProgress() {
// given
ExtendedProductionsByMatterResponse extendedProductionsByMatterResponse = new ExtendedProductionsByMatterResponse();
extendedProductionsByMatterResponse.setStatus(200);
extendedProductionsByMatterResponse.setIsError(false);
ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions();
productions.setProductionId("1234");
productions.setStatus(2);
productions.setName(PRODUCTION_NAME);
extendedProductionsByMatterResponse.setProductions(List.of(productions));

when(armRpoClient.getExtendedProductionsByMatter(any(), any())).thenReturn(extendedProductionsByMatterResponse);

UserAccountEntity userAccount = dartsDatabase.getUserAccountStub().getIntegrationTestUserAccountEntity();
ArmRpoExecutionDetailEntity armRpoExecutionDetailEntity = new ArmRpoExecutionDetailEntity();
armRpoExecutionDetailEntity.setMatterId("1");
armRpoExecutionDetailEntity.setCreatedBy(userAccount);
armRpoExecutionDetailEntity.setLastModifiedBy(userAccount);
var armRpoExecutionDetail = dartsPersistence.save(armRpoExecutionDetailEntity);
var bearerAuth = "Bearer some-token";

// when
var result = armRpoApi.getExtendedProductionsByMatter(bearerAuth, armRpoExecutionDetail.getId(), PRODUCTION_NAME, userAccount);

// then
assertFalse(result);
var armRpoExecutionDetailEntityUpdated = dartsPersistence.getArmRpoExecutionDetailRepository().findById(armRpoExecutionDetail.getId()).get();
assertEquals(ArmRpoStateEnum.GET_EXTENDED_PRODUCTIONS_BY_MATTER.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoState().getId());
assertEquals(ArmRpoStatusEnum.IN_PROGRESS.getId(), armRpoExecutionDetailEntityUpdated.getArmRpoStatus().getId());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class ArmRpoPollServiceIntTest extends PostgresIntegrationBase {

private static final String BEARER_TOKEN = "BearerToken";
private static final String PRODUCTIONEXPORTFILE_CSV = "tests/arm/service/ArmRpoPollServiceTest/productionexportfile.csv";
private static final String PRODUCTION_ID = "DARTS_RPO_2024-08-13";
private static final String PRODUCTION_NAME = "DARTS_RPO_2024-08-13";
private static final String PRODUCTION_ID = " b52268a3-75e5-4dd4-a8d3-0b43781cfcf9";
private static final String SEARCH_ID = "8271f101-8c14-4c41-8865-edc5d8baed99";
private static final String MATTER_ID = "MatterId";
private static final String MATTER_ID = "cb70c7fa-8972-4400-af1d-ff5dd76d2104";
private static final String STORAGE_ACCOUNT_ID = "StorageAccountId";
private static final String PROPERTY_NAME = "propertyName";
private static final String INGESTION_DATE = "ingestionDate";
Expand Down Expand Up @@ -95,7 +96,7 @@ void setUp() {
}

@Test
void pollArmRpo_shouldPollSuccessfullyWithSaveBackgroundCompleted() throws IOException {
void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompleted() throws IOException {
// given
armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.completedRpoStatus());
armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.saveBackgroundSearchRpoState());
Expand Down Expand Up @@ -144,7 +145,7 @@ void pollArmRpo_shouldPollSuccessfullyWithSaveBackgroundCompleted() throws IOExc
}

@Test
void pollArmRpo_shouldPollSuccessfullyWithGetExtendedSearchesByMatterInProgress() throws IOException {
void pollArmRpo_shouldPollSuccessfully_WithGetExtendedSearchesByMatterInProgress() throws IOException {
// given
armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.inProgressRpoStatus());
armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.getExtendedSearchesByMatterRpoState());
Expand Down Expand Up @@ -194,7 +195,7 @@ void pollArmRpo_shouldPollSuccessfullyWithGetExtendedSearchesByMatterInProgress(
}

@Test
void pollArmRpo_shouldPollSuccessfullyWithSaveBackgroundCompletedCreateExportInProgress() throws IOException {
void pollArmRpo_shouldPollSuccessfully_WithSaveBackgroundCompletedCreateExportInProgress() {
// given
armRpoExecutionDetailEntity.setArmRpoStatus(ArmRpoHelper.completedRpoStatus());
armRpoExecutionDetailEntity.setArmRpoState(ArmRpoHelper.saveBackgroundSearchRpoState());
Expand Down Expand Up @@ -307,7 +308,7 @@ public InputStream asInputStream() throws IOException {
}

@Override
public Reader asReader(Charset charset) throws IOException {
public Reader asReader(Charset charset) {
return null;
}

Expand Down Expand Up @@ -348,6 +349,8 @@ public void close() throws IOException {
response.setIsError(false);
ExtendedProductionsByMatterResponse.Productions productions = new ExtendedProductionsByMatterResponse.Productions();
productions.setProductionId(PRODUCTION_ID);
productions.setName(PRODUCTION_NAME);
productions.setStatus(4);
response.setProductions(List.of(productions));
return response;
}
Expand Down Expand Up @@ -395,7 +398,7 @@ private ExtendedSearchesByMatterResponse getExtendedSearchesByMatterResponse() {
response.setIsError(false);
ExtendedSearchesByMatterResponse.Search search = new ExtendedSearchesByMatterResponse.Search();
search.setTotalCount(4);
search.setName(PRODUCTION_ID);
search.setName(PRODUCTION_NAME);
search.setIsSaved(true);
search.setSearchId(SEARCH_ID);
ExtendedSearchesByMatterResponse.SearchDetail searchDetail = new ExtendedSearchesByMatterResponse.SearchDetail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ public static class Productions {

@JsonProperty("productionID")
private String productionId;
@JsonProperty("status")
private Integer status;
@JsonProperty("name")
private String name;

}
}
2 changes: 1 addition & 1 deletion src/main/java/uk/gov/hmcts/darts/arm/rpo/ArmRpoApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ boolean createExportBasedOnSearchResultsTable(String bearerToken, Integer execut
List<MasterIndexFieldByRecordClassSchema> headerColumns, String productionName,
UserAccountEntity userAccount);

void getExtendedProductionsByMatter(String bearerToken, Integer executionId, UserAccountEntity userAccount);
boolean getExtendedProductionsByMatter(String bearerToken, Integer executionId, String productionName, UserAccountEntity userAccount);

List<String> getProductionOutputFiles(String bearerToken, Integer executionId, UserAccountEntity userAccount);

Expand Down
41 changes: 32 additions & 9 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 @@ -70,8 +70,11 @@ public class ArmRpoApiImpl implements ArmRpoApi {
private static final String RECORD_CLASS_CODE = "DARTS";
private static final int FIELD_TYPE_7 = 7;
private static final String ADD_ASYNC_SEARCH_RELATED_TASK_NAME = "ProcessE2EArmRpoPending";
public static final String UNABLE_TO_GET_ARM_RPO_RESPONSE = "Unable to get ARM RPO response from client ";
public static final String CREATE_EXPORT_CSV_EXTENSION = "_CSV";
private static final String UNABLE_TO_GET_ARM_RPO_RESPONSE = "Unable to get ARM RPO response from client ";
private static final String CREATE_EXPORT_CSV_EXTENSION = "_CSV";

private static final int READY_STATUS = 4;
private static final int CONNECTION_FAILED = 5;

private final ArmRpoClient armRpoClient;
private final ArmRpoService armRpoService;
Expand Down Expand Up @@ -435,7 +438,7 @@ public String getExtendedSearchesByMatter(String bearerToken, Integer executionI
}
armRpoExecutionDetailEntity.setSearchItemCount(searchDetailMatch.getSearch().getTotalCount());
armRpoService.updateArmRpoStatus(armRpoExecutionDetailEntity, ArmRpoHelper.completedRpoStatus(), userAccount);
return extendedSearchesByMatterResponse.getSearches().getFirst().getSearch().getName();
return searchDetailMatch.getSearch().getName();
}


Expand Down Expand Up @@ -502,7 +505,7 @@ public boolean createExportBasedOnSearchResultsTable(String bearerToken, Integer
}

@Override
public void getExtendedProductionsByMatter(String bearerToken, Integer executionId, UserAccountEntity userAccount) {
public boolean getExtendedProductionsByMatter(String bearerToken, Integer executionId, String productionName, UserAccountEntity userAccount) {
log.debug("getExtendedProductionsByMatter called with executionId: {}", executionId);
var armRpoExecutionDetailEntity = armRpoService.getArmRpoExecutionDetailEntity(executionId);
armRpoService.updateArmRpoStateAndStatus(armRpoExecutionDetailEntity, ArmRpoHelper.getExtendedProductionsByMatterRpoState(),
Expand All @@ -528,15 +531,35 @@ public void getExtendedProductionsByMatter(String bearerToken, Integer execution

handleResponseStatus(userAccount, extendedProductionsByMatterResponse, errorMessage, armRpoExecutionDetailEntity);
if (isNull(extendedProductionsByMatterResponse.getProductions())
|| CollectionUtils.isEmpty(extendedProductionsByMatterResponse.getProductions())
|| isNull(extendedProductionsByMatterResponse.getProductions().getFirst())
|| StringUtils.isBlank(extendedProductionsByMatterResponse.getProductions().getFirst().getProductionId())) {
|| CollectionUtils.isEmpty(extendedProductionsByMatterResponse.getProductions())) {
throw handleFailureAndCreateException(errorMessage.append("ProductionId is missing from ARM RPO response").toString(),
armRpoExecutionDetailEntity, userAccount);
}

armRpoExecutionDetailEntity.setProductionId(extendedProductionsByMatterResponse.getProductions().getFirst().getProductionId());
ExtendedProductionsByMatterResponse.Productions productionMatch = null;
for (ExtendedProductionsByMatterResponse.Productions productionsItem : extendedProductionsByMatterResponse.getProductions()) {
if (nonNull(productionsItem) && !StringUtils.isBlank(productionsItem.getName()) && productionName.equals(productionsItem.getName())) {
productionMatch = productionsItem;
break;
}
}

if (isNull(productionMatch)
|| StringUtils.isBlank(productionMatch.getProductionId())
|| isNull(productionMatch.getStatus())) {
throw handleFailureAndCreateException(errorMessage.append("Production Id or status is missing from ARM RPO response").toString(),
armRpoExecutionDetailEntity, userAccount);
}

List<Integer> validStatuses = List.of(READY_STATUS, CONNECTION_FAILED);
if (!validStatuses.contains(productionMatch.getStatus())) {
log.error(errorMessage.append("Production status is not ready: ").append(productionMatch.getStatus()).toString());
return false;
}

armRpoExecutionDetailEntity.setProductionId(productionMatch.getProductionId());
armRpoService.updateArmRpoStatus(armRpoExecutionDetailEntity, ArmRpoHelper.completedRpoStatus(), userAccount);
return true;
}

@Override
Expand Down Expand Up @@ -748,7 +771,7 @@ private CreateExportBasedOnSearchResultsTableRequest createRequestForCreateExpor
.headerColumns(createHeaderColumnsFromMasterIndexFieldByRecordClassSchemaResponse(headerColumns))
.productionName(productionName + CREATE_EXPORT_CSV_EXTENSION)
.storageAccountId(storageAccountId)
.onlyForCurrentUser(Boolean.FALSE)
.onlyForCurrentUser(FALSE)
.exportType(32)
.build();
}
Expand Down
Loading

0 comments on commit 7de10f2

Please sign in to comment.