generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DMP-596 - Mark Audio files for deletion in the inbound datastore if t… (
#676)
- Loading branch information
1 parent
4af8077
commit 07098c8
Showing
26 changed files
with
576 additions
and
65 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
121 changes: 87 additions & 34 deletions
121
src/integrationTest/java/uk/gov/hmcts/darts/task/service/AutomatedTaskServiceTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
139 changes: 139 additions & 0 deletions
139
...ntegrationTest/java/uk/gov/hmcts/darts/task/service/InboundAudioDeleterProcessorTest.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,139 @@ | ||
package uk.gov.hmcts.darts.task.service; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import uk.gov.hmcts.darts.audio.service.InboundAudioDeleterProcessor; | ||
import uk.gov.hmcts.darts.common.entity.ExternalObjectDirectoryEntity; | ||
import uk.gov.hmcts.darts.common.entity.HearingEntity; | ||
import uk.gov.hmcts.darts.common.entity.MediaEntity; | ||
import uk.gov.hmcts.darts.common.enums.ExternalLocationTypeEnum; | ||
import uk.gov.hmcts.darts.common.helper.CurrentTimeHelper; | ||
import uk.gov.hmcts.darts.testutils.IntegrationBase; | ||
import uk.gov.hmcts.darts.testutils.data.MediaTestData; | ||
|
||
import java.time.LocalDate; | ||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
import static uk.gov.hmcts.darts.common.enums.ObjectDirectoryStatusEnum.MARKED_FOR_DELETION; | ||
import static uk.gov.hmcts.darts.common.enums.ObjectDirectoryStatusEnum.STORED; | ||
|
||
@SuppressWarnings("PMD.ExcessiveImports") | ||
@SpringBootTest | ||
@ActiveProfiles({"intTest", "h2db"}) | ||
class InboundAudioDeleterProcessorTest extends IntegrationBase { | ||
|
||
public static final LocalDate HEARING_DATE = LocalDate.of(2023, 6, 10); | ||
|
||
@Autowired | ||
private InboundAudioDeleterProcessor inboundAudioDeleterProcessor; | ||
|
||
@MockBean | ||
private CurrentTimeHelper currentTimeHelper; | ||
|
||
@Test | ||
void updatedMoreThan24HrsAgo() { | ||
when(currentTimeHelper.currentOffsetDateTime()) | ||
.thenReturn(OffsetDateTime.now().plusHours(500)); | ||
HearingEntity hearing = dartsDatabase.createHearing( | ||
"NEWCASTLE", | ||
"Int Test Courtroom 2", | ||
"2", | ||
HEARING_DATE | ||
); | ||
|
||
MediaEntity savedMedia = dartsDatabase.save( | ||
MediaTestData.createMediaWith( | ||
hearing.getCourtroom(), | ||
OffsetDateTime.parse("2023-09-26T13:00:00Z"), | ||
OffsetDateTime.parse("2023-09-26T13:45:00Z"), | ||
1 | ||
)); | ||
|
||
UUID uuid = UUID.fromString("075987ea-b34d-49c7-b8db-439bfbe2496c"); | ||
|
||
ExternalObjectDirectoryEntity inboundEod = dartsDatabase.getExternalObjectDirectoryStub().createExternalObjectDirectory( | ||
savedMedia, | ||
dartsDatabase.getObjectDirectoryStatusEntity(STORED), | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.INBOUND), | ||
uuid | ||
); | ||
dartsDatabase.save(inboundEod); | ||
|
||
ExternalObjectDirectoryEntity armEod = dartsDatabase.getExternalObjectDirectoryStub().createExternalObjectDirectory( | ||
savedMedia, | ||
dartsDatabase.getObjectDirectoryStatusEntity(STORED), | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.ARM), | ||
uuid | ||
); | ||
dartsDatabase.save(armEod); | ||
|
||
inboundAudioDeleterProcessor.markForDeletion(); | ||
|
||
List<ExternalObjectDirectoryEntity> foundMediaList = dartsDatabase.getExternalObjectDirectoryRepository().findByMediaAndExternalLocationType( | ||
savedMedia, | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.INBOUND) | ||
); | ||
|
||
assertEquals(1, foundMediaList.size()); | ||
ExternalObjectDirectoryEntity foundMedia = foundMediaList.get(0); | ||
assertEquals(MARKED_FOR_DELETION.getId(), foundMedia.getStatus().getId()); | ||
} | ||
|
||
|
||
@Test | ||
void updatedLessThan24HrsAgo() { | ||
when(currentTimeHelper.currentOffsetDateTime()) | ||
.thenReturn(OffsetDateTime.now().plusHours(1)); | ||
HearingEntity hearing = dartsDatabase.createHearing( | ||
"NEWCASTLE", | ||
"Int Test Courtroom 2", | ||
"2", | ||
HEARING_DATE | ||
); | ||
|
||
MediaEntity savedMedia = dartsDatabase.save( | ||
MediaTestData.createMediaWith( | ||
hearing.getCourtroom(), | ||
OffsetDateTime.parse("2023-09-26T13:00:00Z"), | ||
OffsetDateTime.parse("2023-09-26T13:45:00Z"), | ||
1 | ||
)); | ||
|
||
UUID uuid = UUID.fromString("075987ea-b34d-49c7-b8db-439bfbe2496c"); | ||
|
||
ExternalObjectDirectoryEntity inboundEod = dartsDatabase.getExternalObjectDirectoryStub().createExternalObjectDirectory( | ||
savedMedia, | ||
dartsDatabase.getObjectDirectoryStatusEntity(STORED), | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.INBOUND), | ||
uuid | ||
); | ||
dartsDatabase.save(inboundEod); | ||
|
||
ExternalObjectDirectoryEntity armEod = dartsDatabase.getExternalObjectDirectoryStub().createExternalObjectDirectory( | ||
savedMedia, | ||
dartsDatabase.getObjectDirectoryStatusEntity(STORED), | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.ARM), | ||
uuid | ||
); | ||
dartsDatabase.save(armEod); | ||
|
||
inboundAudioDeleterProcessor.markForDeletion(); | ||
|
||
List<ExternalObjectDirectoryEntity> foundMediaList = dartsDatabase.getExternalObjectDirectoryRepository().findByMediaAndExternalLocationType( | ||
savedMedia, | ||
dartsDatabase.getExternalLocationTypeEntity(ExternalLocationTypeEnum.INBOUND) | ||
); | ||
|
||
|
||
assertEquals(1, foundMediaList.size()); | ||
ExternalObjectDirectoryEntity foundMedia = foundMediaList.get(0); | ||
assertEquals(STORED.getId(), foundMedia.getStatus().getId()); | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
src/main/java/uk/gov/hmcts/darts/audio/service/InboundAudioDeleterProcessor.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,6 @@ | ||
package uk.gov.hmcts.darts.audio.service; | ||
|
||
public interface InboundAudioDeleterProcessor { | ||
|
||
void markForDeletion(); | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/uk/gov/hmcts/darts/audio/service/impl/InboundAudioDeleterProcessorImpl.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,78 @@ | ||
package uk.gov.hmcts.darts.audio.service.impl; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import uk.gov.hmcts.darts.audio.service.InboundAudioDeleterProcessor; | ||
import uk.gov.hmcts.darts.common.entity.ExternalLocationTypeEntity; | ||
import uk.gov.hmcts.darts.common.entity.ObjectDirectoryStatusEntity; | ||
import uk.gov.hmcts.darts.common.entity.UserAccountEntity; | ||
import uk.gov.hmcts.darts.common.enums.ExternalLocationTypeEnum; | ||
import uk.gov.hmcts.darts.common.enums.ObjectDirectoryStatusEnum; | ||
import uk.gov.hmcts.darts.common.helper.CurrentTimeHelper; | ||
import uk.gov.hmcts.darts.common.helper.SystemUserHelper; | ||
import uk.gov.hmcts.darts.common.repository.ExternalLocationTypeRepository; | ||
import uk.gov.hmcts.darts.common.repository.ExternalObjectDirectoryRepository; | ||
import uk.gov.hmcts.darts.common.repository.ObjectDirectoryStatusRepository; | ||
import uk.gov.hmcts.darts.common.repository.UserAccountRepository; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
|
||
import static uk.gov.hmcts.darts.common.enums.ObjectDirectoryStatusEnum.MARKED_FOR_DELETION; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class InboundAudioDeleterProcessorImpl implements InboundAudioDeleterProcessor { | ||
private final UserAccountRepository userAccountRepository; | ||
private final ObjectDirectoryStatusRepository objectDirectoryStatusRepository; | ||
private final ExternalObjectDirectoryRepository externalObjectDirectoryRepository; | ||
private final ExternalLocationTypeRepository externalLocationTypeRepository; | ||
private final CurrentTimeHelper currentTimeHelper; | ||
private final SystemUserHelper systemUserHelper; | ||
|
||
@Value("${darts.data-management.retention-period.inbound.arm-minimum}") | ||
int hoursInArm; | ||
|
||
@Transactional | ||
public void markForDeletion() { | ||
ObjectDirectoryStatusEntity storedStatus = objectDirectoryStatusRepository.getReferenceById( | ||
ObjectDirectoryStatusEnum.STORED.getId()); | ||
ExternalLocationTypeEntity inboundLocation = externalLocationTypeRepository.getReferenceById( | ||
ExternalLocationTypeEnum.INBOUND.getId()); | ||
ExternalLocationTypeEntity armLocation = externalLocationTypeRepository.getReferenceById( | ||
ExternalLocationTypeEnum.ARM.getId()); | ||
OffsetDateTime lastModifiedBefore = currentTimeHelper.currentOffsetDateTime().minus( | ||
hoursInArm, | ||
ChronoUnit.HOURS | ||
); | ||
List<Integer> audioFileIdsToBeMarked = externalObjectDirectoryRepository.findMediaFileIdsIn2StorageLocationsBeforeTime( | ||
storedStatus, | ||
storedStatus, | ||
inboundLocation, | ||
armLocation, | ||
lastModifiedBefore | ||
); | ||
|
||
if (audioFileIdsToBeMarked.isEmpty()) { | ||
log.debug("No Inbound Audio files found that need to be marked for deletion."); | ||
return; | ||
} | ||
log.debug("Marking the following ExternalObjectDirectory.Id's for deletion:- {}", audioFileIdsToBeMarked); | ||
|
||
ObjectDirectoryStatusEntity deletionStatus = objectDirectoryStatusRepository.getReferenceById( | ||
MARKED_FOR_DELETION.getId()); | ||
|
||
UserAccountEntity user = userAccountRepository.findSystemUser(systemUserHelper.findSystemUserGuid("housekeeping")); | ||
externalObjectDirectoryRepository.updateStatus( | ||
deletionStatus, | ||
user, | ||
audioFileIdsToBeMarked, | ||
OffsetDateTime.now() | ||
); | ||
} | ||
} |
Oops, something went wrong.