Skip to content
Snippets Groups Projects
Commit eb4da15f authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-5412 intelliform-adapter: Fix duplicate key

parent 449ef147
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ package de.ozgcloud.eingang.intelliform; ...@@ -25,6 +25,7 @@ package de.ozgcloud.eingang.intelliform;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -90,12 +91,14 @@ class DepositDataMapper { ...@@ -90,12 +91,14 @@ class DepositDataMapper {
.build(); .build();
} }
private Map<String, IncomingFile> mapDepositAttachmentsToIncomingFiles(DepositData depositData) { Map<String, IncomingFile> mapDepositAttachmentsToIncomingFiles(DepositData depositData) {
return depositData.getAttachments() return depositData.getAttachments()
.stream() .stream()
.collect( .collect(Collectors.toMap(
Collectors.toMap(Attachment::getId, this::mapAttachmentToIncomingFile) Attachment::getId,
); this::mapAttachmentToIncomingFile,
(u, v) -> v,
LinkedHashMap::new));
} }
IncomingFile mapAttachmentToIncomingFile(Attachment attachment) { IncomingFile mapAttachmentToIncomingFile(Attachment attachment) {
......
...@@ -136,6 +136,36 @@ class DepositDataMapperTest { ...@@ -136,6 +136,36 @@ class DepositDataMapperTest {
} }
@DisplayName("map deposit attachments to incoming files")
@Nested
class TestMapDepositAttachmentsToIncomingFiles {
@DisplayName("should keep entry order")
@Test
void shouldKeepEntryOrder() {
var depositData = DepositDataTestFactory.create(ATTACHMENTS);
var incomingFileMap = mapper.mapDepositAttachmentsToIncomingFiles(depositData);
var keys = incomingFileMap.keySet().stream().toList();
assertThat(keys).containsExactly(XML_ATTACHMENT_ID, PDF_ATTACHMENT_ID, PNG_ATTACHMENT_ID);
}
@DisplayName("should keep last entry for duplicate key")
@Test
void shouldKeepLastEntryForDuplicateKey() {
var depositData = DepositDataTestFactory.create(List.of(
AttachmentTestFactory.createXmlDaten(),
AttachmentTestFactory.createPdf(),
AttachmentTestFactory.createXmlDaten()
));
var incomingFileMap = mapper.mapDepositAttachmentsToIncomingFiles(depositData);
var keys = incomingFileMap.keySet().stream().toList();
assertThat(keys).containsExactly(XML_ATTACHMENT_ID, PDF_ATTACHMENT_ID);
}
}
@DisplayName("map attachment to incoming file") @DisplayName("map attachment to incoming file")
@Nested @Nested
class TestMapAttachmentToIncomingFile { class TestMapAttachmentToIncomingFile {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment