Skip to content
Snippets Groups Projects
Commit 540724ea authored by OZG-Cloud Team's avatar OZG-Cloud Team
Browse files

Merge pull request 'OZG-5156-Anbindung-Versammlungsanzeige' (#129) from...

Merge pull request 'OZG-5156-Anbindung-Versammlungsanzeige' (#129) from OZG-5156-Anbindung-Versammlungsanzeige into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/eingang-manager/pulls/129


Reviewed-by: default avatarOZG-Cloud Team <noreply@ozg-sh.de>
parents 91661041 5131c011
No related branches found
No related tags found
No related merge requests found
Showing
with 716 additions and 0 deletions
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.ozgcloud.eingang</groupId>
<artifactId>eingang-manager</artifactId>
<version>2.10.0-SNAPSHOT</version>
</parent>
<artifactId>fim-adapter</artifactId>
<name>Eingangs Adapter - FIM</name>
<dependencies>
<!--ozg-Cloud-->
<dependency>
<groupId>de.ozgcloud.eingang</groupId>
<artifactId>common</artifactId>
</dependency>
<dependency>
<groupId>de.ozgcloud.eingang</groupId>
<artifactId>semantik-adapter</artifactId>
</dependency>
<!--spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--test -->
<dependency>
<groupId>de.ozgcloud.eingang</groupId>
<artifactId>common</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package de.ozgcloud.eingang.fim;
import de.ozgcloud.eingang.common.formdata.FormData;
public interface AntragstellerExtractor {
default void extractAntragsteller(final FormData.FormDataBuilder builder, final FormData initialFormData) {}
}
package de.ozgcloud.eingang.fim;
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.semantik.enginebased.EngineBasedMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@Log4j2
@Component
class FimBasedMapper implements EngineBasedMapper {
@Autowired
private FimService fimService;
public boolean isResponsible(final FormData formData) {
//FIXME isResponsible from meta data
final List<IncomingFileGroup> attachments = formData.getAttachments();
final Optional<IncomingFile> metadataFileOpt = findFile(attachments, "fim_xtaMetadata.xml");
return metadataFileOpt.isPresent();
}
public FormData parseFormData(final FormData initialFormData) {
if (!isResponsible(initialFormData)) {
return initialFormData;
}
final List<IncomingFileGroup> attachments = initialFormData.getAttachments();
final Optional<IncomingFile> metadataFileOpt = findFile(attachments, "fim_xtaMetadata.xml");
if (metadataFileOpt.isEmpty()) {
LOG.error("Metadata File not found for fim data mapping");
return initialFormData;
}
final Optional<String> entryPointOpt = getEntryPoint(metadataFileOpt.get());
if (entryPointOpt.isEmpty()) {
LOG.error("No entry point found in metadata file for fim data mapping");
return initialFormData;
}
final Optional<IncomingFile> fileOpt = findFile(attachments, entryPointOpt.get());
if (fileOpt.isEmpty()) {
LOG.error("Entry point file not found for fim data mapping");
return initialFormData;
}
try {
final Document document = loadDocument(fileOpt.get());
return fimService.transformDocument(document, initialFormData);
} catch (ParserConfigurationException | SAXException | IOException | FimException e) {
LOG.error("Can't transform document into fim formdata");
return initialFormData;
}
}
private Optional<IncomingFile> findFile(final Collection<IncomingFileGroup> attachments, final String name) {
for (IncomingFileGroup group : attachments) {
for (IncomingFile file : group.getFiles()) {
if (file.getName().endsWith(name)) {
return Optional.of(file);
}
}
}
return Optional.empty();
}
private Optional<String> getEntryPoint(final IncomingFile incomingFile) {
// FIXME sollte über formdata metadaten kommen statt aus dem meta file geparsed zu werden
return Optional.of("Antrag.xml");
}
private Document loadDocument(final IncomingFile incomingFile) throws ParserConfigurationException, IOException, SAXException {
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.parse(incomingFile.getContentStream());
}
}
package de.ozgcloud.eingang.fim;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.IncomingFileGroup;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.function.TriFunction;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
@Service
@Log4j2
class FimDataMapper implements TriFunction<Document, FimScheme, Collection<IncomingFileGroup>, FormData.FormDataBuilder> {
private static final String LABEL_KEY = "label";
private static final String VALUE_KEY = "value";
@Override
public FormData.FormDataBuilder apply(final Document document, final FimScheme fimScheme, final Collection<IncomingFileGroup> attachments) {
final FormData.FormDataBuilder formDataBuilder = FormData.builder();
Map<String, Object> data = new LinkedHashMap<>();
process(document.getDocumentElement(), fimScheme, data, 0);
formDataBuilder.formData(data);
formDataBuilder.attachments(attachments);
return formDataBuilder;
}
private void process(final Element element, final FimScheme fimScheme, final Map<String, Object> data, final int level) {
final NodeList childNodes = element.getChildNodes();
LOG.debug(">".repeat(level) + " " + element.getNodeName());
for(int i = 0; i < childNodes.getLength();i++) {
final Node child = childNodes.item(i);
if (!(child instanceof Element)) {
continue;
}
if (child.getChildNodes().getLength() == 1 && child.getChildNodes().item(0) instanceof Text textNode) {
insertValueIntoFormData(data, fimScheme.getFieldName(child.getNodeName()), child.getNodeName(), textNode.getTextContent());
} else {
final Map<String, Object> childMap = new LinkedHashMap<>();
insertValueIntoFormData(data, fimScheme.getFieldName(child.getNodeName()), child.getNodeName(), childMap);
process((Element) child, fimScheme, childMap, level + 1);
}
}
}
private void insertValueIntoFormData(final Map<String, Object> data, final Optional<String> fieldName, final String nodeName, final Object obj) {
final Map<String, Object> labelMap = Map.of(LABEL_KEY, fieldName.orElse(nodeName), VALUE_KEY, obj);
data.put(nodeName, labelMap);
}
}
package de.ozgcloud.eingang.fim;
import de.ozgcloud.eingang.common.errorhandling.TechnicalException;
public class FimException extends TechnicalException {
public FimException(final String ex) {
super(ex);
}
}
package de.ozgcloud.eingang.fim;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import org.springframework.validation.annotation.Validated;
import java.util.ArrayList;
import java.util.List;
@Validated
@Configuration
@ConfigurationProperties(prefix = FimProperties.PROPERTIES_PREFIX)
@Getter
public class FimProperties {
static final String PROPERTIES_PREFIX = "fim";
/**
* List of paths to fim scheme files which should be processed by the fim-adapter.
*
* Only fim data that is in the namespace and versions of these files will be mapped by the fim-adapter.
* All other fim data will be left untouched by the mapper.
*/
private final List<String> schemeLocations = new ArrayList<>();
}
package de.ozgcloud.eingang.fim;
import lombok.Getter;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
class FimScheme {
private final Document doc;
@Getter
private final FimSchemeIdentifier identifier;
@Getter
private final FimSchemeAdapter schemeAdapter;
private final Map<String, Element> fieldIndex = new LinkedHashMap<>();
FimScheme(final Document doc, final FimSchemeIdentifier identifier, final FimSchemeAdapter schemeAdapter) {
this.doc = doc;
this.identifier = identifier;
this.schemeAdapter = schemeAdapter;
buildFieldIndex();
}
private void buildFieldIndex() {
final NodeList groupList = doc.getElementsByTagName("xs:element");
for (int i = 0; i < groupList.getLength();i++) {
final Element group = (Element) groupList.item(i);
final String groupName = group.getAttribute("name");
fieldIndex.put(groupName, group);
}
}
Optional<String> getFieldName(final String fieldName) {
return schemeAdapter.getFieldName(fieldIndex, fieldName);
}
}
package de.ozgcloud.eingang.fim;
import lombok.extern.log4j.Log4j2;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import java.util.Map;
import java.util.Optional;
@Log4j2
public abstract class FimSchemeAdapter implements ZustaendigeStelleExtractor, AntragstellerExtractor {
public abstract FimSchemeIdentifier forIdentifier();
public Optional<String> getFieldName(final Map<String, Element> fieldIndex, final String fieldName) {
final String[] fieldNameParts = fieldName.split(":");
final String fieldNameWithoutNamespace = fieldNameParts[fieldNameParts.length - 1];
if (!fieldIndex.containsKey(fieldNameWithoutNamespace)) {
LOG.error("Cannot find Field: " + fieldName);
return Optional.empty();
}
final Element nodeNameElement = fieldIndex.get(fieldNameWithoutNamespace);
final Optional<String> nodeNameOpt = getNameForElement(nodeNameElement);
return nodeNameOpt.map(this::cleanNodeName);
}
public Optional<String> getNameForElement(final Element element) {
final NodeList nameTags = element.getElementsByTagName("name");
if (nameTags.getLength() != 1) {
return Optional.empty();
}
return Optional.ofNullable(nameTags.item(0).getTextContent());
}
public String cleanNodeName(final String s) {
return s.trim();
}
}
package de.ozgcloud.eingang.fim;
import java.util.LinkedHashMap;
class FimSchemeAdapterCatalogue extends LinkedHashMap<FimSchemeIdentifier, FimSchemeAdapter> {
}
package de.ozgcloud.eingang.fim;
import java.util.LinkedHashMap;
class FimSchemeCatalogue extends LinkedHashMap<FimSchemeIdentifier, FimScheme> {
}
package de.ozgcloud.eingang.fim;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class FimSchemeIdentifier {
private final String schemeId;
FimSchemeIdentifier(String schemeId) {
this.schemeId = schemeId;
}
public static FimSchemeIdentifier fromString(final String s) {
return new FimSchemeIdentifier(s);
}
}
package de.ozgcloud.eingang.fim;
import de.ozgcloud.eingang.common.formdata.FormData;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.PostConstruct;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Service
@Log4j2
public class FimService {
public static final String UNKNOWN_SCHEME_NAME = "unknown";
@Autowired
private FimProperties fimProperties;
@Autowired
private FimDataMapper fimDataMapper;
@Autowired
private final List<FimSchemeAdapter> fimSchemeAdapters = new ArrayList<>();
private final FimSchemeCatalogue fimSchemeCatalogue = new FimSchemeCatalogue();
private final FimSchemeAdapterCatalogue fimSchemeAdapterCatalogue = new FimSchemeAdapterCatalogue();
private static final FimSchemeAdapter DEFAULT_FIM_SCHEME_ADAPTER = new FimSchemeAdapter() {
@Override
public FimSchemeIdentifier forIdentifier() { return null; }
};
@PostConstruct
private void postConstruct() throws ParserConfigurationException, IOException, SAXException {
for (final FimSchemeAdapter fimSchemeAdapter : fimSchemeAdapters) {
fimSchemeAdapterCatalogue.put(fimSchemeAdapter.forIdentifier(), fimSchemeAdapter);
}
for (final String fimSchemaLocation : fimProperties.getSchemeLocations()) {
final FimScheme fimScheme = loadFimScheme(fimSchemaLocation.trim());
fimSchemeCatalogue.put(fimScheme.getIdentifier(), fimScheme);
}
final FimScheme unknownScheme = buildUnknownScheme();
fimSchemeCatalogue.put(unknownScheme.getIdentifier(), unknownScheme);
}
private FimScheme loadFimScheme(final String path) throws ParserConfigurationException, IOException, SAXException {
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
final Document doc = builder.parse(new File(path));
final String targetNamespace = doc.getDocumentElement().getAttribute("targetNamespace");
final FimSchemeIdentifier fimSchemeIdentifier = FimSchemeIdentifier.fromString(targetNamespace);
final FimSchemeAdapter fimSchemeAdapter = fimSchemeAdapterCatalogue.getOrDefault(fimSchemeIdentifier, DEFAULT_FIM_SCHEME_ADAPTER);
return new FimScheme(doc, fimSchemeIdentifier, fimSchemeAdapter);
}
private FimScheme buildUnknownScheme() throws ParserConfigurationException {
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
final FimSchemeIdentifier unknownFimSchemeIdentifier = FimSchemeIdentifier.fromString(UNKNOWN_SCHEME_NAME);
final FimSchemeAdapter fimSchemeAdapter = fimSchemeAdapterCatalogue.get(unknownFimSchemeIdentifier);
return new FimScheme(doc, unknownFimSchemeIdentifier, fimSchemeAdapter);
}
public FormData transformDocument(final Document document, final FormData initialFormData) {
final String schemeName = document.getDocumentElement().getAttribute("xmlns:xfd");
if (StringUtils.isEmpty(schemeName)) {
throw new FimException("XML Document does not provide a scheme");
}
final FimScheme scheme = getSchemeForIdentifier(schemeName);
final FormData.FormDataBuilder builder = fimDataMapper.apply(document, scheme, initialFormData.getAttachments());
final FimSchemeAdapter adapter = scheme.getSchemeAdapter();
builder.header(initialFormData.getHeader());
adapter.extractAntragsteller(builder, initialFormData);
adapter.extractZustaendigeStelle(builder, initialFormData);
return builder.build();
}
FimScheme getSchemeForIdentifier(final String fimSchemaName) {
final FimSchemeIdentifier fimSchemeIdentifier = FimSchemeIdentifier.fromString(fimSchemaName);
final FimScheme fimScheme = fimSchemeCatalogue.get(fimSchemeIdentifier);
if (fimScheme == null) {
LOG.error("Cannot find schema for: " + fimSchemaName);
return fimSchemeCatalogue.get(FimSchemeIdentifier.fromString(UNKNOWN_SCHEME_NAME));
}
return fimScheme;
}
}
package de.ozgcloud.eingang.fim;
import org.springframework.stereotype.Service;
import org.w3c.dom.Element;
import java.util.Map;
import java.util.Optional;
@Service
public class UnknownSchemeAdapter extends FimSchemeAdapter {
public FimSchemeIdentifier forIdentifier() {
return FimSchemeIdentifier.fromString(FimService.UNKNOWN_SCHEME_NAME);
}
@Override
public Optional<String> getFieldName(Map<String, Element> fieldIndex, String fieldName) {
return Optional.of(fieldName);
}
}
package de.ozgcloud.eingang.fim;
import de.ozgcloud.eingang.common.formdata.FormData;
public interface ZustaendigeStelleExtractor {
default void extractZustaendigeStelle (final FormData.FormDataBuilder builder, final FormData initialFormData) {}
}
fim:
schemeLocations:
- src/main/resources/fim-s17000652_1.4/S17000652V1.4_xfall.xsd
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><gc:CodeList xmlns:gc="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"><gc:Identification><gc:ShortName>codelist</gc:ShortName><gc:LongName></gc:LongName><gc:Version>2022-02-16</gc:Version><gc:CanonicalUri>urn:de:fim:codeliste:dokumenttyp</gc:CanonicalUri><gc:CanonicalVersionUri>urn:de:fim:codeliste:dokumenttyp_2022-02-16</gc:CanonicalVersionUri></gc:Identification><gc:ColumnSet><gc:Column Id="code" Use="required"><gc:ShortName>Code</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Column Id="name" Use="required"><gc:ShortName>Name</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Key Id="codeKey"><gc:ShortName>CodeKey</gc:ShortName><gc:ColumnRef Ref="code"/></gc:Key><gc:Key Id="codenameKey"><gc:ShortName>CodenameKey</gc:ShortName><gc:ColumnRef Ref="name"/></gc:Key></gc:ColumnSet><gc:SimpleCodeList><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>01</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Anzeige einer öffentlichen Versammlung unter freiem Himmel (ortsfest)</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>02</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Anzeige einer sich fortbewegenden Versammlung (Aufzug, Umzug)</gc:SimpleValue></gc:Value></gc:Row></gc:SimpleCodeList></gc:CodeList>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><gc:CodeList xmlns:gc="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"><gc:Identification><gc:ShortName></gc:ShortName><gc:LongName></gc:LongName><gc:Version>2023-09-26</gc:Version><gc:CanonicalUri>urn:de:fim:codeliste:artteilnahmeveranstaltung</gc:CanonicalUri><gc:CanonicalVersionUri>urn:de:fim:codeliste:artteilnahmeveranstaltung_2023-09-26</gc:CanonicalVersionUri></gc:Identification><gc:ColumnSet><gc:Column Id="code" Use="required"><gc:ShortName>Code</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Column Id="name" Use="required"><gc:ShortName>Name</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Key Id="codeKey"><gc:ShortName>CodeKey</gc:ShortName><gc:ColumnRef Ref="code"/></gc:Key><gc:Key Id="codenameKey"><gc:ShortName>CodenameKey</gc:ShortName><gc:ColumnRef Ref="name"/></gc:Key></gc:ColumnSet><gc:SimpleCodeList><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>001</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>zu Fuß</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>002</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>per Fahrrad</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>003</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>per Motorrad</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>004</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>per Personenkraftwagen</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>005</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Sonstiges</gc:SimpleValue></gc:Value></gc:Row></gc:SimpleCodeList></gc:CodeList>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><gc:CodeList xmlns:gc="http://docs.oasis-open.org/codelist/ns/genericode/1.0/"><gc:Identification><gc:ShortName></gc:ShortName><gc:LongName></gc:LongName><gc:Version>2023-09-29</gc:Version><gc:CanonicalUri>urn:de:fim:codeliste:buehneversammlung</gc:CanonicalUri><gc:CanonicalVersionUri>urn:de:fim:codeliste:buehneversammlung_2023-09-29</gc:CanonicalVersionUri></gc:Identification><gc:ColumnSet><gc:Column Id="code" Use="required"><gc:ShortName>Code</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Column Id="name" Use="required"><gc:ShortName>Name</gc:ShortName><gc:Data Type="string"/></gc:Column><gc:Key Id="codeKey"><gc:ShortName>CodeKey</gc:ShortName><gc:ColumnRef Ref="code"/></gc:Key><gc:Key Id="codenameKey"><gc:ShortName>CodenameKey</gc:ShortName><gc:ColumnRef Ref="name"/></gc:Key></gc:ColumnSet><gc:SimpleCodeList><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>001</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Ja</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>002</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Nein</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>003</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Nicht bekannt</gc:SimpleValue></gc:Value></gc:Row><gc:Row><gc:Value ColumnRef="code"><gc:SimpleValue>004</gc:SimpleValue></gc:Value><gc:Value ColumnRef="name"><gc:SimpleValue>Keine</gc:SimpleValue></gc:Value></gc:Row></gc:SimpleCodeList></gc:CodeList>
\ No newline at end of file
This diff is collapsed.
package de.ozgcloud.eingang.fim;
import de.ozgcloud.common.test.ITCase;
import de.ozgcloud.eingang.common.formdata.FormData;
import de.ozgcloud.eingang.common.formdata.IncomingFile;
import de.ozgcloud.eingang.common.formdata.IncomingFileGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@ITCase
@ActiveProfiles({ "itcase", "test" })
@ImportAutoConfiguration
@SpringBootTest(classes= FimTestConfig.class)
public class FimServiceITCase {
@Autowired
private FimService fimService;
@Autowired
private FimBasedMapper fimBasedMapper;
@Test
void shouldFailOnEmptyScheme() {
assertThatThrownBy(() -> {
final Document document = loadDocument("src/test/resources/test1.xml");
fimService.transformDocument(document, FormData.builder().build());
}).isInstanceOf(FimException.class).hasMessage("XML Document does not provide a scheme");
}
@Test
void shouldNoFindInvalidScheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("test");
assertThat(FimSchemeIdentifier.fromString("unknown")).isEqualTo(scheme.getIdentifier());
}
@Test
void shouldFindVersammlungsScheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("urn:xoev-de:xfall:standard:fim-s17000652_1.4");
assertThat(scheme).isNotNull();
}
@Test
void shouldFindTest2Scheme() {
final FimScheme scheme = fimService.getSchemeForIdentifier("test2");
assertThat(scheme).isNotNull();
}
@Test
void shouldTransformSimpleDocument() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/test2.xml");
final FormData formData = fimService.transformDocument(document, FormData.builder().build());
final Map<String, Object> expected = Map.of(
"xs:fim.S1235", Map.of("label", "Testkey", "value", "Testvalue"),
"xs:fim.S1236", Map.of("label", "xs:fim.S1236", "value", "Testvalue 2")
);
assertThat(expected).isEqualTo(formData.getFormData());
}
@Test
void shouldTransformDocument() throws ParserConfigurationException, IOException, SAXException {
final Document document = loadDocument("src/test/resources/S17000652V1.4_test01.xml");
FormData formData = fimService.transformDocument(document, FormData.builder().build());
assertThat(formData).isNotNull();
final Map<String, Object> expected = Map.of(
"xfd:G17003529", Map.of(
"label","EfA|SH Standard",
"value", Map.of(
"xfd:G05001479", Map.of(
"label","nachrichtenkopf",
"value", Map.of(
"xfd:G05001480", Map.of(
"label","identifikation.nachricht",
"value", Map.of(
"xfd:F05002750", Map.of("label", "nachrichtenUUID", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"),
"xfd:F05002751", Map.of("label", "erstellungszeitpunkt", "value", "2022-08-15T09:30:47"),
"xfd:F05002752", Map.of("label", "nachrichtentyp", "value", "fim.S17000652.17000652001004"),
"xfd:F05002753", Map.of("label", "dienstname", "value", "urn:fim:Versammlungsanzeige:1.4")
)
),
"xfd:G05001481", Map.of(
"label","Leser",
"value", Map.of(
"xfd:F05002754", Map.of("label", "Organisationsname", "value", "Celle"),
"xfd:F05002755", Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"xfd:F05002756", Map.of("label", "Kategorie", "value", "Versammlungsbehörde")
)
),
"xfd:G05001482", Map.of(
"label","Autor",
"value", Map.of(
"xfd:F05002754", Map.of("label", "Organisationsname", "value", "OSI-Onlinedienst Niedersachsen Versammlungsanzeige"),
"xfd:F05002755", Map.of("label", "Organisationsschlüssel", "value", "vbe:010550120100"),
"xfd:F05002756", Map.of("label", "Kategorie", "value", "Engagement- und Hobbyportal")
)
)
)
),
"xfd:F17005454", Map.of("label", "Datenschutzhinweis DSGVO", "value", "true"),
"xfd:F17005455", Map.of("label", "Zustimmung zu einem digitalen Bescheid", "value", "true"),
"xfd:F17005533", Map.of("label", "UUID", "value", "String")
)
),
"xfd:F17009191", Map.of("label", "Anzeige durch Person", "value", "true"),
"xfd:F17003371", Map.of("label", "Anzeigenart", "value", "String")
);
assertThat(expected).isEqualTo(formData.getFormData());
}
@Test
void shouldFallbackUnknownScheme() {
final FormData initialFormData = FormData.builder().attachment(
IncomingFileGroup.builder()
.file(IncomingFile.builder().name("src/test/resources/test3/Antrag.xml").file(new File("src/test/resources/test3/Antrag.xml")).build())
.file(IncomingFile.builder().name("src/test/resources/test3/fim_xtaMetadata.xml").build()).build()).build();
FormData formData = fimBasedMapper.parseFormData(initialFormData);
assertThat(formData).isNotNull();
final Map<String, Object> expected = Map.of(
"xfd:G17003529", Map.of(
"label","xfd:G17003529",
"value", Map.of(
"xfd:G05001479", Map.of(
"label","xfd:G05001479",
"value", Map.of(
"xfd:G05001480", Map.of(
"label","xfd:G05001480",
"value", Map.of(
"xfd:F05002750", Map.of("label", "xfd:F05002750", "value", "d447e43a-5723-4821-a170-cb44d2dbf143"),
"xfd:F05002751", Map.of("label", "xfd:F05002751", "value", "2022-08-15T09:30:47"),
"xfd:F05002752", Map.of("label", "xfd:F05002752", "value", "fim.S17000652.17000652001004"),
"xfd:F05002753", Map.of("label", "xfd:F05002753", "value", "urn:fim:Versammlungsanzeige:1.4")
)
),
"xfd:G05001481", Map.of(
"label","xfd:G05001481",
"value", Map.of(
"xfd:F05002754", Map.of("label", "xfd:F05002754", "value", "Celle"),
"xfd:F05002755", Map.of("label", "xfd:F05002755", "value", "vbe:010550120100"),
"xfd:F05002756", Map.of("label", "xfd:F05002756", "value", "Versammlungsbehörde")
)
),
"xfd:G05001482", Map.of(
"label","xfd:G05001482",
"value", Map.of(
"xfd:F05002754", Map.of("label", "xfd:F05002754", "value", "OSI-Onlinedienst Niedersachsen Versammlungsanzeige"),
"xfd:F05002755", Map.of("label", "xfd:F05002755", "value", "vbe:010550120100"),
"xfd:F05002756", Map.of("label", "xfd:F05002756", "value", "Engagement- und Hobbyportal")
)
)
)
),
"xfd:F17005454", Map.of("label", "xfd:F17005454", "value", "true"),
"xfd:F17005455", Map.of("label", "xfd:F17005455", "value", "true"),
"xfd:F17005533", Map.of("label", "xfd:F17005533", "value", "String")
)
),
"xfd:F17009191", Map.of("label", "xfd:F17009191", "value", "true"),
"xfd:F17003371", Map.of("label", "xfd:F17003371", "value", "String")
);
assertThat(expected).isEqualTo(formData.getFormData());
}
private Document loadDocument(final String path) throws ParserConfigurationException, IOException, SAXException {
final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return builder.parse(new File(path));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment