Skip to content

Commit

Permalink
DMP-4065 UnstructuredToArmDataStore leaves record stuck in 'Arm Inges…
Browse files Browse the repository at this point in the history
…tion'

Added a shutdown hook to reset states before closing down
  • Loading branch information
karen-hedges committed Dec 4, 2024
1 parent ef868c7 commit cf17a5a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.lang.reflect.InvocationTargetException;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -48,14 +47,12 @@ void testGetDirectoryIfMediaDate24Hours() throws Exception {
// setup the test data
generateDataWithMediaForInbound(setupHoursBeforeCurrentTime);

int hourDurationBeyondHours = setupHoursBeforeCurrentTime; // which no records are

// exercise the logic
List<Integer> results = externalObjectDirectoryRepository
.findIdsIn2StorageLocationsBeforeTime(
EodHelper.storedStatus(), EodHelper.storedStatus(),
EodHelper.inboundLocation(), EodHelper.armLocation(),
getCurrentDateTimeWithHoursBefore(hourDurationBeyondHours),
getCurrentDateTimeWithHoursBefore(setupHoursBeforeCurrentTime),
ExternalObjectDirectoryQueryTypeEnum.MEDIA_QUERY.getIndex(),
Limit.of(100_000));

Expand All @@ -72,13 +69,11 @@ void testGetDirectoryIfMediaDateBeyond24Hours() throws Exception {
// setup the test data
generateDataWithMediaForInbound(setupHoursBeforeCurrentTime);

int hourDurationBeyondHours = setupHoursBeforeCurrentTime; // which no records are

// excerise the logic
// exercise the logic
List<Integer> results = externalObjectDirectoryRepository
.findIdsIn2StorageLocationsBeforeTime(EodHelper.storedStatus(), EodHelper.storedStatus(),
EodHelper.inboundLocation(), EodHelper.armLocation(),
getCurrentDateTimeWithHoursBefore(hourDurationBeyondHours),
getCurrentDateTimeWithHoursBefore(setupHoursBeforeCurrentTime),
ExternalObjectDirectoryQueryTypeEnum.MEDIA_QUERY.getIndex(),
Limit.of(100_000));

Expand All @@ -95,14 +90,12 @@ void testGetDirectoryIfAnnotationDate24Hours() throws Exception {
// setup the test data
generateDataWithAnnotationForInbound(setupHoursBeforeCurrentTime);

int hourDurationBeyondHours = setupHoursBeforeCurrentTime; // which no records are

// exercise the logic
List<Integer> results = externalObjectDirectoryRepository
.findIdsIn2StorageLocationsBeforeTime(
EodHelper.storedStatus(), EodHelper.storedStatus(),
EodHelper.inboundLocation(), EodHelper.armLocation(),
getCurrentDateTimeWithHoursBefore(hourDurationBeyondHours), ExternalObjectDirectoryQueryTypeEnum.ANNOTATION_QUERY.getIndex(),
getCurrentDateTimeWithHoursBefore(setupHoursBeforeCurrentTime), ExternalObjectDirectoryQueryTypeEnum.ANNOTATION_QUERY.getIndex(),
Limit.of(100_000));

// assert the logic
Expand Down Expand Up @@ -300,10 +293,8 @@ private void generateDataWithAnnotationForUnstructured(int hoursBeforeCurrentTim

OffsetDateTime lastModifiedBeforeCurrentTimeForArm = currentTimeHelper.currentOffsetDateTime().minusHours(hoursBeforeCurrentTimeForArm);

OffsetDateTime lastModifiedBeforeCurrentTimeForUnstructured = currentTimeHelper.currentOffsetDateTime().minus(
weeksBeforeCurrentTimeForUnstructured,
ChronoUnit.WEEKS
);
OffsetDateTime lastModifiedBeforeCurrentTimeForUnstructured = currentTimeHelper.currentOffsetDateTime().minusWeeks(
weeksBeforeCurrentTimeForUnstructured);

OffsetDateTime lastModifiedNotBeforeThreshold = currentTimeHelper.currentOffsetDateTime().minusHours(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public UnableToReadArmFileException(String armFilename, Throwable cause) {
}

public UnableToReadArmFileException() {
// This constructor is intentionally empty. Nothing special is needed here.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.stereotype.Component;
import uk.gov.hmcts.darts.arm.api.ArmDataManagementApi;
import uk.gov.hmcts.darts.arm.component.ArchiveRecordFileGenerator;
Expand All @@ -21,6 +20,7 @@
import uk.gov.hmcts.darts.common.entity.ExternalLocationTypeEntity;
import uk.gov.hmcts.darts.common.entity.ExternalObjectDirectoryEntity;
import uk.gov.hmcts.darts.common.entity.UserAccountEntity;
import uk.gov.hmcts.darts.common.exception.DartsException;
import uk.gov.hmcts.darts.common.repository.ExternalObjectDirectoryRepository;
import uk.gov.hmcts.darts.common.service.FileOperationService;
import uk.gov.hmcts.darts.common.util.EodHelper;
Expand All @@ -34,6 +34,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.PreDestroy;

import static uk.gov.hmcts.darts.common.util.EodHelper.equalsAnyStatus;
import static uk.gov.hmcts.darts.common.util.EodHelper.isEqual;
Expand All @@ -42,7 +43,7 @@
@Slf4j
@Component
@RequiredArgsConstructor
public class UnstructuredToArmBatchProcessorImpl implements UnstructuredToArmBatchProcessor, DisposableBean {
public class UnstructuredToArmBatchProcessorImpl implements UnstructuredToArmBatchProcessor {
private final ArchiveRecordService archiveRecordService;
private final ArchiveRecordFileGenerator archiveRecordFileGenerator;
private final DataStoreToArmHelper unstructuredToArmHelper;
Expand Down Expand Up @@ -167,7 +168,7 @@ private void updateArmEodToArmIngestionStatus(ExternalObjectDirectoryEntity armE
} else {
log.error("Unable to find matching external object directory for {}", armEod.getId());
unstructuredToArmHelper.updateExternalObjectDirectoryFailedTransferAttempts(armEod, userAccount);
throw new RuntimeException(MessageFormat.format("Unable to find matching external object directory for {0}", armEod.getId()));
throw new DartsException(MessageFormat.format("Unable to find matching external object directory for {0}", armEod.getId()));
}
}

Expand Down Expand Up @@ -235,9 +236,11 @@ private void recoverByUpdatingEodToFailedArmStatus(ArmBatchItem batchItem, UserA
}
}

@Override
public void destroy() throws Exception {
@PreDestroy
public void destroy() {
log.info("UnstructuredToArmBatchProcessorImpl shutting down.");
if (CollectionUtils.isNotEmpty(eodsForTransfer)) {
log.info("Reverting EODs to failed status for {} EODs", eodsForTransfer.size());
unstructuredToArmHelper.updateEodByIdAndStatus(eodsForTransfer,
EodHelper.armIngestionStatus(),
EodHelper.failedArmRawDataStatus(),
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/uk/gov/hmcts/darts/util/DataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public final class DataUtil {
private DataUtil() {

// Utility class
}

public static String toUpperCase(String value) {
Expand All @@ -32,19 +32,19 @@ public static String trim(String item) {
}

public static void preProcess(DartsEvent dartsEvent) {
dartsEvent.setCourthouse(DataUtil.toUpperCase(dartsEvent.getCourthouse()));
dartsEvent.setCourtroom(DataUtil.toUpperCase(dartsEvent.getCourtroom()));
dartsEvent.setCourthouse(toUpperCase(dartsEvent.getCourthouse()));
dartsEvent.setCourtroom(toUpperCase(dartsEvent.getCourtroom()));
}

public static void preProcess(AddCaseRequest addCaseRequest) {
addCaseRequest.setCourthouse(DataUtil.toUpperCase(addCaseRequest.getCourthouse()));
addCaseRequest.defenders(DataUtil.trim(addCaseRequest.getDefenders()));
addCaseRequest.prosecutors(DataUtil.trim(addCaseRequest.getProsecutors()));
addCaseRequest.defendants(DataUtil.trim(addCaseRequest.getDefendants()));
addCaseRequest.setCourthouse(toUpperCase(addCaseRequest.getCourthouse()));
addCaseRequest.defenders(trim(addCaseRequest.getDefenders()));
addCaseRequest.prosecutors(trim(addCaseRequest.getProsecutors()));
addCaseRequest.defendants(trim(addCaseRequest.getDefendants()));
}

public static void preProcess(AddAudioMetadataRequest metadata) {
metadata.setCourthouse(DataUtil.toUpperCase(metadata.getCourthouse()));
metadata.setCourtroom(DataUtil.toUpperCase(metadata.getCourtroom()));
metadata.setCourthouse(toUpperCase(metadata.getCourthouse()));
metadata.setCourtroom(toUpperCase(metadata.getCourtroom()));
}
}

0 comments on commit cf17a5a

Please sign in to comment.