Skip to content
Snippets Groups Projects
Commit 3c153b92 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-7144 read oe-id from deposit (and other custom parameter)

parent 9896ad22
Branches
No related tags found
1 merge request!1Ozg 7144 orgid lower case
......@@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
......@@ -49,6 +50,7 @@ import org.xml.sax.SAXException;
import de.ozgcloud.common.binaryfile.TempFileUtils;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.FormData.FormDataControl;
import de.ozgcloud.eingang.common.formdata.IncomingFile;
import de.ozgcloud.eingang.common.formdata.IncomingFileGroup;
import lombok.RequiredArgsConstructor;
......@@ -57,7 +59,8 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
class DepositDataMapper {
// TODO Resolve code duplication (xta-adapter: de.ozgcloud.eingang.xdomea.XMLHelper)
// TODO Resolve code duplication (xta-adapter:
// de.ozgcloud.eingang.xdomea.XMLHelper)
private static final DocumentBuilder DOCUMENT_BUILDER = createDocumentBuilder();
private static DocumentBuilder createDocumentBuilder() {
......@@ -75,10 +78,14 @@ class DepositDataMapper {
var document = parsePrimaryXmlRepresentation(depositData, incomingFileMap);
var attachmentGroups = findAttachmentGroups(document);
return mapToFormDataWithRepresentationsAndAttachments(
var formData = mapToFormDataWithRepresentationsAndAttachments(
getRepresentations(incomingFileMap, getAttachmentFileIds(attachmentGroups)),
getAttachmentFileGroups(attachmentGroups, incomingFileMap)
);
getAttachmentFileGroups(attachmentGroups, incomingFileMap));
return formData.toBuilder()
.control(FormDataControl.builder().metaData(Optional.of(buildMetaData(depositData))).build())
.build();
}
private List<String> getAttachmentFileIds(Map<String, List<String>> attachmentGroups) {
......@@ -89,8 +96,7 @@ class DepositDataMapper {
private FormData mapToFormDataWithRepresentationsAndAttachments(
List<IncomingFile> representations,
List<IncomingFileGroup> attachments
) {
List<IncomingFileGroup> attachments) {
return FormData.builder()
.attachments(attachments)
.numberOfAttachments(attachments.size())
......@@ -131,8 +137,7 @@ class DepositDataMapper {
private Document parsePrimaryXmlRepresentation(DepositData depositData, Map<String, IncomingFile> incomingFileMap) {
// Expect that the <primaryDataAttachmentId> refers to the XML file
return parseDocument(
getIncomingFileById(depositData.getPrimaryDataAttachmentId(), incomingFileMap)
);
getIncomingFileById(depositData.getPrimaryDataAttachmentId(), incomingFileMap));
}
private static Document parseDocument(IncomingFile incomingFile) {
......@@ -185,4 +190,13 @@ class DepositDataMapper {
.map(Element.class::cast);
}
IntelliFormMetaData buildMetaData(DepositData depositData) {
var builder = IntelliFormMetaData.builder()
.origin(depositData.getTimestamp().toGregorianCalendar().toZonedDateTime());
depositData.getCustomParameters()
.forEach(entry -> builder.customParameter(IntelliFormMetaData.CUSTOM_PARAM_PREFIX + entry.key.toUpperCase(), entry.value));
return builder.build();
}
}
package de.ozgcloud.eingang.intelliform;
import java.time.ZonedDateTime;
import java.util.Map;
import de.ozgcloud.eingang.common.formdata.FormMetaData;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
@Builder
@Getter
class IntelliFormMetaData implements FormMetaData {
private final ZonedDateTime origin;
@Builder.Default
private final ZonedDateTime delivery = ZonedDateTime.now();
static final String CUSTOM_PARAM_PREFIX = "CUSTOMPARAMETER_";
@Singular
@Getter(AccessLevel.NONE)
private Map<String, String> customParameters;
@Override
public String getEntry(String name) {
return customParameters.get(name);
}
}
......@@ -27,11 +27,14 @@ import static de.ozgcloud.eingang.intelliform.AttachmentTestFactory.*;
import static de.ozgcloud.eingang.intelliform.DepositDataTestFactory.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
......@@ -53,6 +56,7 @@ import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.IncomingFile;
import de.ozgcloud.eingang.common.formdata.IncomingFileGroup;
import de.ozgcloud.eingang.intelliform.AttachmentTestFactory.MetaAttachment;
import lombok.SneakyThrows;
class DepositDataMapperTest {
......@@ -147,8 +151,7 @@ class DepositDataMapperTest {
withEmptyName(createPdf()),
createPdf(),
withEmptyName(createPng()),
createPng()
));
createPng()));
}
private Attachment withEmptyName(Attachment attachment) {
......@@ -211,8 +214,7 @@ class DepositDataMapperTest {
assertThat(incomingFileIds).containsExactly(
XML_ATTACHMENT_ID,
XML_ROHFORM_ATTACHMENT_ID,
XML_ORIGINALFORM_ATTACHMENT_ID
);
XML_ORIGINALFORM_ATTACHMENT_ID);
}
@DisplayName("should return with attachment groups")
......@@ -237,8 +239,7 @@ class DepositDataMapperTest {
PDF2_ATTACHMENT_ID,
ODT_ATTACHMENT_ID,
JPG_ATTACHMENT_ID,
PNG_ATTACHMENT_ID
);
PNG_ATTACHMENT_ID);
}
}
......@@ -255,6 +256,15 @@ class DepositDataMapperTest {
}
}
@Test
void shouldAddMetaData() {
depositData = DepositDataTestFactory.create();
doMapping();
verify(mapper).buildMetaData(any());
}
private FormData doMapping() {
return mapper.mapToFormData(depositData);
}
......@@ -295,12 +305,10 @@ class DepositDataMapperTest {
.name("XML-Daten (Rohform).xml")
.contentType(XML_CONTENT_TYPE)
.content("abc")
.build()
),
.build()),
AttachmentTestFactory.createPdf(),
AttachmentTestFactory.createXmlDaten(),
AttachmentTestFactory.createPng()
));
AttachmentTestFactory.createPng()));
var incomingFileMap = mapper.mapDepositAttachmentsToSortedIncomingFiles(depositData);
......@@ -314,8 +322,7 @@ class DepositDataMapperTest {
var depositData = DepositDataTestFactory.create(List.of(
AttachmentTestFactory.createXmlDaten(),
AttachmentTestFactory.createPdf(),
AttachmentTestFactory.createXmlDaten()
));
AttachmentTestFactory.createXmlDaten()));
var incomingFileMap = mapper.mapDepositAttachmentsToSortedIncomingFiles(depositData);
......@@ -445,4 +452,28 @@ class DepositDataMapperTest {
}
}
@Nested
class TestCreateMetaData {
@Test
void shouldHaveOrigin() {
var metaData = mapper.buildMetaData(DepositDataTestFactory.create());
assertThat(metaData.getOrigin()).isEqualTo(DepositDataTestFactory.TIMESTAMP_DATETIME);
}
@Test
void shouldHaveDelivery() {
var metaData = mapper.buildMetaData(DepositDataTestFactory.create());
assertThat(metaData.getDelivery()).isCloseTo(ZonedDateTime.now(), within(1, ChronoUnit.SECONDS));
}
@Test
void shouldHaveCustomParameter() {
var metaData = mapper.buildMetaData(DepositDataTestFactory.create());
assertThat(metaData.getEntry("CUSTOMPARAMETER_PARAM_KEY")).isEqualTo(DepositDataTestFactory.CUTOMPARA_VALUE);
}
}
}
......@@ -26,20 +26,37 @@ package de.ozgcloud.eingang.intelliform;
import static de.ozgcloud.eingang.intelliform.AttachmentTestFactory.*;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import de.ozgcloud.common.test.TestUtils;
public class DepositDataTestFactory {
static final String TIMESTAMP_STRING = "2024-12-03T07:49:46.969+01:00";
public static final XMLGregorianCalendar TIMESTAMP = DatatypeFactory.newDefaultInstance().newXMLGregorianCalendar(TIMESTAMP_STRING);
public static final ZonedDateTime TIMESTAMP_DATETIME = ZonedDateTime.parse(TIMESTAMP_STRING);
public static final String CUSTOMPARA_KEY = "param_key";
public static final String CUTOMPARA_VALUE = "param_value";
private static final Entry CUSTOMPARA_ENTRY;
static {
var entry = new Entry();
entry.setKey(CUSTOMPARA_KEY);
entry.setValue(CUTOMPARA_VALUE);
CUSTOMPARA_ENTRY = entry;
}
public static final List<Attachment> ATTACHMENTS = List.of(
AttachmentTestFactory.createXmlDaten(),
AttachmentTestFactory.createPdf(),
AttachmentTestFactory.createPng()
);
AttachmentTestFactory.createPng());
public static final List<Attachment> MANY_ATTACHMENTS = createManyAttachments(
TestUtils.loadTextFile("intelliform/XML-Daten-complex.template.xml"),
......@@ -52,8 +69,7 @@ public class DepositDataTestFactory {
"anrede_code", ANTRAGSTELLER_ANREDE_CODE,
"antragsteller_nachname", ANTRAGSTELLER_NACHNAME,
"antragsteller_vorname", "Max",
"antragsteller_email", "max.mustermann@example.com"
),
"antragsteller_email", "max.mustermann@example.com"),
DOCX1_ATTACHMENT_ID, "Document1.docx", DOCX_ATTACHMENT_CONTENT_TYPE, DOCX_ATTACHMENT_CONTENT, "fileid-docx1",
PDF_ATTACHMENT_ID, "Document2.pdf", PDF_ATTACHMENT_CONTENT_TYPE, PDF_ATTACHMENT_CONTENT, "fileid-pdf1",
DOCX2_ATTACHMENT_ID, "Document3.docx", DOCX_ATTACHMENT_CONTENT_TYPE, DOCX_ATTACHMENT_CONTENT, "fileid-docx2",
......@@ -68,8 +84,14 @@ public class DepositDataTestFactory {
JPG_ATTACHMENT_ID, "Document11.jpg", "image/jpeg", "TestContent6", "fileid-jpg1",
PNG_ATTACHMENT_ID, "Document12.png", "image/png", "TestContent7", "fileid-png1");
public static DepositData create() {
return create(ATTACHMENTS);
}
public static DepositData create(Collection<Attachment> attachments) {
var depositData = new DepositData();
depositData.setTimestamp(TIMESTAMP);
depositData.getCustomParameters().add(CUSTOMPARA_ENTRY);
depositData.setPrimaryDataAttachmentId(AttachmentTestFactory.XML_ATTACHMENT_ID);
depositData.getAttachments().addAll(attachments);
return depositData;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment