Skip to content
Snippets Groups Projects
Commit fabaafa6 authored by Lukas Malte Monnerjahn's avatar Lukas Malte Monnerjahn
Browse files

OZG-5808 XML-Anhänge von Eingängen über XTA/NB immer als Repräsentation behandeln

parent 525107cd
Branches
Tags
No related merge requests found
......@@ -24,13 +24,26 @@ public class XdomeaXMLValueReader {
private static final String DATEINAME_NODE_QUERY_STRING = "//Hauptobjekt//Dateiname";
private static final XPathExpression DATEINAME_NODE_QUERY = compileXPathExpression(DATEINAME_NODE_QUERY_STRING);
// Query für XML-Dateien in Anlagen
// Siehe auch https://www.xrepository.de/details/urn:xoev-de:xdomea:kosit:standard:xdomea
// und https://www.xrepository.de/details/urn:xoev-de:xdomea:codeliste:dateiformat
public static final String ANLAGE_NODE_QUERY_DFOERDER = "//Anlage//Format/Name[@listURI='urn:xoev-de:xdomea:codeliste:dateiformat']/code[.='030']/../..//Dateiname";
public static final String ANLAGE_NODE_QUERY_AFM = "//Anlage//Format/Name[substring(., 1, 3)='030']/..//Dateiname";
public static final String ANLAGE_NODE_QUERY_STRING = ANLAGE_NODE_QUERY_DFOERDER + " | " + ANLAGE_NODE_QUERY_AFM;
private static final XPathExpression ANLAGE_NODE_QUERY = compileXPathExpression(ANLAGE_NODE_QUERY_STRING);
public List<String> readRepresentationFileNames(IncomingFile xdomeaXMLFile) {
return getTextsFromNodes(
queryDateinameNodeList(
XMLHelper.parseDocument(xdomeaXMLFile)
.getDocumentElement()
)
);
var parsedXML = XMLHelper.parseDocument(xdomeaXMLFile).getDocumentElement();
return Stream.concat(
getTextsFromNodes(
queryDateinameNodeList(
parsedXML
)),
getTextsFromNodes(
queryAnlageNodeList(
parsedXML
))
).toList();
}
private NodeList queryDateinameNodeList(Element contextElement) {
......@@ -45,11 +58,22 @@ public class XdomeaXMLValueReader {
}
}
private List<String> getTextsFromNodes(NodeList nodeList) {
private NodeList queryAnlageNodeList(Element contextElement) {
try {
return (NodeList) ANLAGE_NODE_QUERY
.evaluate(
contextElement,
XPathConstants.NODESET
);
} catch (XPathExpressionException e) {
throw new TechnicalException("Failed to execute xpath search!", e);
}
}
private Stream<String> getTextsFromNodes(NodeList nodeList) {
return streamNodeList(nodeList)
.map(Node::getTextContent)
.map(String::trim)
.toList();
.map(String::trim);
}
private Stream<Node> streamNodeList(NodeList nodeList) {
......
......@@ -22,6 +22,8 @@ import lombok.SneakyThrows;
class XdomeaXMLValueReaderTest {
private static final String XML_FILE_NAME = "file.xml";
private static final String PDF_FILE_NAME = "file.pdf";
private static final String XML_ATTACHMENT_FILE_NAME = "saml-attachment-file.xml";
public static final String PDF_ATTACHMENT_FILE_NAME = "some-attachment-file.pdf";
@Spy
@InjectMocks
......@@ -34,7 +36,7 @@ class XdomeaXMLValueReaderTest {
@Mock
IncomingFile incomingXmlFile;
@DisplayName("should find 'Dateiname' elements in MSR mantelantrag")
@DisplayName("should find 'Dateiname' elements and all XML-files in MSR mantelantrag")
@ParameterizedTest
@ValueSource(strings = {
"xdomea/mantelantrag_Geschaeftsgang.Geschaeftsgang.0201.xml",
......@@ -45,12 +47,14 @@ class XdomeaXMLValueReaderTest {
var xmlString = TestUtils.loadTextFile(
antragXMLFilename,
XML_FILE_NAME + "\n",
PDF_FILE_NAME);
PDF_FILE_NAME,
XML_ATTACHMENT_FILE_NAME,
PDF_ATTACHMENT_FILE_NAME);
when(incomingXmlFile.getContentStream()).thenReturn(IOUtils.toInputStream(xmlString, StandardCharsets.UTF_8));
var names = valueReader.readRepresentationFileNames(incomingXmlFile);
assertThat(names).isEqualTo(List.of(XML_FILE_NAME, PDF_FILE_NAME));
assertThat(names).isEqualTo(List.of(XML_FILE_NAME, PDF_FILE_NAME, XML_ATTACHMENT_FILE_NAME));
}
}
......
......@@ -104,4 +104,35 @@
</Verfuegung>
</Beteiligungsschritt>
</ExternerGeschaeftsgang>
<Anlage>
<Dokument>
<Identifikation>
<ID>1d8ca22a-9d20-4507-aa5e-b764bb5642f0</ID>
</Identifikation>
<Typ>Anlage</Typ>
<Version>
<Nummer>1</Nummer>
<Format>
<Name listURI="urn:xoev-de:xdomea:codeliste:dateiformat" listVersionID="1.0" xsi:type="DateiformatCodeType">
<code xmlns="">030</code>
<name xmlns="">xml-eXtensible Markup Language</name>
</Name>
<Version>0.0</Version>
<Primaerdokument>
<Dateiname>%s</Dateiname>
</Primaerdokument>
</Format>
<Format>
<Name listURI="urn:xoev-de:xdomea:codeliste:dateiformat" listVersionID="1.0" xsi:type="DateiformatCodeType">
<code xmlns="">018</code>
<name xmlns="">pdf-Portable Document Format</name>
</Name>
<Version>0.0</Version>
<Primaerdokument>
<Dateiname>%s</Dateiname>
</Primaerdokument>
</Format>
</Version>
</Dokument>
</Anlage>
</Geschaeftsgang.Geschaeftsgang.0201>
......@@ -96,4 +96,37 @@
</xdomea:Verfuegung>
</xdomea:Beteiligungsschritt>
</xdomea:ExternerGeschaeftsgang>
<xdomea:Anlage>
<xdomea:Dokument>
<xdomea:Identifikation>
<xdomea:ID>1d8ca22a-9d20-4507-aa5e-b764bb5642f0</xdomea:ID>
</xdomea:Identifikation>
<xdomea:Typ>Anlage</xdomea:Typ>
<xdomea:Version>
<xdomea:Nummer>1</xdomea:Nummer>
<xdomea:Format>
<xdomea:Name codeName="xml - eXtensible Markup Language"
codelistAgencyName="AG XDOMEA des KoopA ADV" codelistVersionIdentifier="2.0.0"
languageCode="de" codelistName="Dateiformat">030
</xdomea:Name>
<xdomea:Version>0.0</xdomea:Version>
<xdomea:Primaerdokument>
<xdomea:Dateiname>%s</xdomea:Dateiname>
</xdomea:Primaerdokument>
</xdomea:Format>
</xdomea:Version>
<xdomea:Version>
<xdomea:Nummer>1</xdomea:Nummer>
<xdomea:Format>
<xdomea:Name codeName="pdf - Portable Document Format" codelistAgencyName="AG XDOMEA des KoopA ADV"
codelistVersionIdentifier="2.0.0" languageCode="de" codelistName="Dateiformat">018
</xdomea:Name>
<xdomea:Version>0.0</xdomea:Version>
<xdomea:Primaerdokument>
<xdomea:Dateiname>%s</xdomea:Dateiname>
</xdomea:Primaerdokument>
</xdomea:Format>
</xdomea:Version>
</xdomea:Dokument>
</xdomea:Anlage>
</xdomea:Geschaeftsgang.Geschaeftsgang.0201>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment