Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -156,11 +157,14 @@ private Map<Path, Path> generateZipStructure(List<List<AudioFileInfo>> 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);
}

Expand All @@ -187,4 +191,4 @@ private void writeZip(Map<Path, Path> sourceToDestinationPaths, Path outputPath)
log.debug("Produced zip file: {}", outputPath);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioFileInfo> session1 = List.of(
Expand Down Expand Up @@ -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<String> 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<String> 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);
Expand Down
Loading