diff --git a/src/main/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImpl.java b/src/main/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImpl.java index 7eecd1a6653..8aa8ed9d308 100644 --- a/src/main/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImpl.java +++ b/src/main/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImpl.java @@ -40,6 +40,7 @@ public class OutboundFileZipGeneratorImpl implements OutboundFileZipGenerator { private static final String DAUDIO = "daudio"; private static final String LOCALAUDIO = "localaudio"; private static final String VIQ_METADATA_TYPE = "Zip"; + private static final int CASE_NUMBER_SPLIT_INDEX = 5; private final AudioConfigurationProperties audioConfigurationProperties; private final OutboundFileZipGeneratorHelper outboundFileZipGeneratorHelper; @@ -156,11 +157,14 @@ private Map generateZipStructure(List> audioSess private Path generateZipPath(String caseNumber, int directoryIndex, AudioFileInfo audioFileInfo) { var nameElement1 = DAUDIO; var nameElement2 = LOCALAUDIO; - var nameElement3 = caseNumber.substring(0, 5); - var nameElement4 = caseNumber.substring(5); var nameElement5 = String.format("%04d", directoryIndex + 1); var filename = String.format("%s.a%02d", nameElement5, audioFileInfo.getChannel() - 1); + if (caseNumber.length() <= CASE_NUMBER_SPLIT_INDEX) { + return Path.of(nameElement1, nameElement2, caseNumber, nameElement5, filename); + } + var nameElement3 = caseNumber.substring(0, CASE_NUMBER_SPLIT_INDEX); + var nameElement4 = caseNumber.substring(CASE_NUMBER_SPLIT_INDEX); return Path.of(nameElement1, nameElement2, nameElement3, nameElement4, nameElement5, filename); } @@ -187,4 +191,4 @@ private void writeZip(Map sourceToDestinationPaths, Path outputPath) log.debug("Produced zip file: {}", outputPath); } -} \ No newline at end of file +} diff --git a/src/test/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImplTest.java b/src/test/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImplTest.java index 9b57783907f..ec80ea3b9c0 100644 --- a/src/test/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImplTest.java +++ b/src/test/java/uk/gov/hmcts/darts/audio/component/impl/OutboundFileZipGeneratorImplTest.java @@ -80,7 +80,7 @@ void setUp() throws IOException, ParserConfigurationException { } @Test - void generateAndWriteZipShouldProduceZipWithTheExpectedFileStructure() { + void generateAndWriteZip_ShouldProduceZipWithTheExpectedFileStructure_WhenNineDigitCaseNumber() { var audioWithSession1AndChannel1 = createDummyFileAndAudioFileInfo(1); var audioWithSession1AndChannel2 = createDummyFileAndAudioFileInfo(2); List session1 = List.of( @@ -113,6 +113,46 @@ void generateAndWriteZipShouldProduceZipWithTheExpectedFileStructure() { assertThat(paths, hasItem("daudio/localaudio/T2019/0024/0002/annotations.xml")); } + @Test + void generateAndWriteZip_ShouldProduceZip_WhenSingleCharacterCaseNumber() { + var audioWithSession1AndChannel1 = createDummyFileAndAudioFileInfo(1); + + Path path = outboundFileZipGenerator.generateAndWriteZip( + List.of(List.of(audioWithSession1AndChannel1)), + createDummyMediaRequestEntity("b") + ); + + assertTrue(Files.exists(path)); + + List paths = readZipStructure(path); + + assertEquals(4, paths.size()); + assertThat(paths, hasItem("readMe.txt")); + assertThat(paths, hasItem("playlist.xml")); + assertThat(paths, hasItem("daudio/localaudio/b/0001/0001.a00")); + assertThat(paths, hasItem("daudio/localaudio/b/0001/annotations.xml")); + } + + @Test + void generateAndWriteZip_ShouldProduceZip_WhenFiveCharacterCaseNumber() { + var audioWithSession1AndChannel1 = createDummyFileAndAudioFileInfo(1); + + Path path = outboundFileZipGenerator.generateAndWriteZip( + List.of(List.of(audioWithSession1AndChannel1)), + createDummyMediaRequestEntity("T2019") + ); + + assertTrue(Files.exists(path)); + + List paths = readZipStructure(path); + + assertEquals(4, paths.size()); + assertThat(paths, hasItem("readMe.txt")); + assertThat(paths, hasItem("playlist.xml")); + assertThat(paths, hasItem("daudio/localaudio/T2019/0001/0001.a00")); + assertThat(paths, hasItem("daudio/localaudio/T2019/0001/annotations.xml")); + } + private MediaRequestEntity createDummyMediaRequestEntity(String caseNumber) { HearingEntity mockHearingEntity = mock(HearingEntity.class);