Skip to content
Snippets Groups Projects
Verified Commit 10edaa24 authored by Jesper Zedlitz's avatar Jesper Zedlitz
Browse files

Update auf Spring Boot 3.4.0 und Jena 5.2.0

Die neue Jena Version machte es notwendig, IRIs besser zu prüfen und mehr defekte IRIs zu ersetzen.
parent a439a2a2
No related branches found
No related tags found
1 merge request!5Resolve "DataService und DatasetSeries erhalten"
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version> <version>3.4.0</version>
<relativePath /> <relativePath />
</parent> </parent>
<groupId>de.landsh.opendata</groupId> <groupId>de.landsh.opendata</groupId>
<artifactId>dcat-catalog-proxy</artifactId> <artifactId>dcat-catalog-proxy</artifactId>
<version>1.3.0</version> <version>1.4.0-SNAPSHOT</version>
<name>dcat-catalog-proxy</name> <name>dcat-catalog-proxy</name>
<description>DCAT catalog proxy</description> <description>DCAT catalog proxy</description>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<jena.version>4.7.0</jena.version> <jena.version>5.2.0</jena.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
...@@ -80,6 +79,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -80,6 +79,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<artifactId>snakeyaml</artifactId> <artifactId>snakeyaml</artifactId>
<version>1.32</version> <version>1.32</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<build> <build>
...@@ -92,7 +97,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -92,7 +97,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version> <version>0.8.12</version>
<executions> <executions>
<execution> <execution>
<id>coverage-initialize</id> <id>coverage-initialize</id>
...@@ -157,7 +162,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -157,7 +162,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<plugin> <plugin>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId> <artifactId>dependency-check-maven</artifactId>
<version>7.4.4</version> <version>11.1.0</version>
<configuration> <configuration>
<suppressionFiles> <suppressionFiles>
<suppressionFile>owasp-suppressions.xml</suppressionFile> <suppressionFile>owasp-suppressions.xml</suppressionFile>
...@@ -165,6 +170,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -165,6 +170,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<failBuildOnCVSS>8</failBuildOnCVSS> <failBuildOnCVSS>8</failBuildOnCVSS>
<assemblyAnalyzerEnabled>false</assemblyAnalyzerEnabled> <assemblyAnalyzerEnabled>false</assemblyAnalyzerEnabled>
<failOnError>true</failOnError> <failOnError>true</failOnError>
<nvdApiKey>${env.NVD_API_KEY}</nvdApiKey>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
...@@ -177,7 +183,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -177,7 +183,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<plugin> <plugin>
<groupId>org.codehaus.mojo</groupId> <groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId> <artifactId>versions-maven-plugin</artifactId>
<version>2.14.2</version> <version>2.18.0</version>
<configuration> <configuration>
<rulesUri>file:///${project.basedir}/rules.xml</rulesUri> <rulesUri>file:///${project.basedir}/rules.xml</rulesUri>
</configuration> </configuration>
...@@ -187,14 +193,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x ...@@ -187,14 +193,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/x
<artifactId>spotbugs-maven-plugin</artifactId> <artifactId>spotbugs-maven-plugin</artifactId>
<version>4.5.3.0</version> <version>4.5.3.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.14.2</version>
<configuration>
<rulesUri>file:///${project.basedir}/rules.xml</rulesUri>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>
...@@ -11,15 +11,5 @@ ...@@ -11,15 +11,5 @@
<ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion> <ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
</ignoreVersions> </ignoreVersions>
<rules> <rules>
<!-- 4.7.0 is the last version that work. There is an additional rule for
IRIs in later versions that prevents some of CKAN's responses
to be parsed. -->
<rule groupId="org.apache.jena" comparisonMethod="maven">
<ignoreVersions>
<ignoreVersion type="regex">4.[89].*</ignoreVersion>
<ignoreVersion type="regex">4.1[0-9].*</ignoreVersion>
</ignoreVersions>
</rule>
</rules> </rules>
</ruleset> </ruleset>
...@@ -14,6 +14,7 @@ import org.springframework.beans.factory.InitializingBean; ...@@ -14,6 +14,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import java.io.InputStream; import java.io.InputStream;
import java.nio.channels.Selector;
import java.util.*; import java.util.*;
/** /**
...@@ -359,8 +360,7 @@ public class CatalogFilter implements InitializingBean { ...@@ -359,8 +360,7 @@ public class CatalogFilter implements InitializingBean {
void changeStartAndEndDate(Model model) { void changeStartAndEndDate(Model model) {
LinkedList<Statement> oldStatements = new LinkedList<>(); LinkedList<Statement> oldStatements = new LinkedList<>();
Selector selectorStart = new SimpleSelector(null, model.createProperty("http://schema.org/startDate"), (Object) null); StmtIterator it = model.listStatements(null, model.createProperty("http://schema.org/startDate"), (String) null);
StmtIterator it = model.listStatements(selectorStart);
while (it.hasNext()) { while (it.hasNext()) {
Statement stmt = it.next(); Statement stmt = it.next();
oldStatements.add(stmt); oldStatements.add(stmt);
...@@ -368,8 +368,7 @@ public class CatalogFilter implements InitializingBean { ...@@ -368,8 +368,7 @@ public class CatalogFilter implements InitializingBean {
} }
it.close(); it.close();
Selector selectorEnd = new SimpleSelector(null, model.createProperty("http://schema.org/endDate"), (Object) null); it = model.listStatements(null, model.createProperty("http://schema.org/endDate"), (String) null);
it = model.listStatements(selectorEnd);
while (it.hasNext()) { while (it.hasNext()) {
Statement stmt = it.next(); Statement stmt = it.next();
oldStatements.add(stmt); oldStatements.add(stmt);
......
package de.landsh.opendata.catalogproxy; package de.landsh.opendata.catalogproxy;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.jena.irix.IRIException;
import org.apache.jena.irix.IRIs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
...@@ -10,8 +15,9 @@ import java.nio.charset.StandardCharsets; ...@@ -10,8 +15,9 @@ import java.nio.charset.StandardCharsets;
public class FilterInvalidRDF extends InputStream { public class FilterInvalidRDF extends InputStream {
private static final String RDF_ABOUT_DOUBLE_QUOTE = "rdf:about=\"";
private static final String RDF_ABOUT_SINGLE_QUOTE = "rdf:about='"; private static final Logger log = LoggerFactory.getLogger(FilterInvalidRDF.class);
private final BufferedReader reader; private final BufferedReader reader;
boolean initialized = false; boolean initialized = false;
private byte[] currentLine = null; private byte[] currentLine = null;
...@@ -40,27 +46,51 @@ public class FilterInvalidRDF extends InputStream { ...@@ -40,27 +46,51 @@ public class FilterInvalidRDF extends InputStream {
line = StringUtils.join(fragments, "&"); line = StringUtils.join(fragments, "&");
} }
line = fixRdfAbout(line, "about");
return fixRdfAbout(line, "resource");
}
private static String fixRdfAbout(String line, String propertyName) {
final String propertyWithDoubleQuote = "rdf:" + propertyName + "=\"";
final String propertyWithSingleQuote = "rdf:" + propertyName + "='";
String before = null; String before = null;
String iri = null; String iri = null;
String after = null; String after = null;
if (line.contains(RDF_ABOUT_DOUBLE_QUOTE)) { if (line.contains(propertyWithDoubleQuote)) {
before = StringUtils.substringBefore(line, RDF_ABOUT_DOUBLE_QUOTE) + RDF_ABOUT_DOUBLE_QUOTE; before = StringUtils.substringBefore(line, propertyWithDoubleQuote) + propertyWithDoubleQuote;
iri = StringUtils.substringBetween(line, RDF_ABOUT_DOUBLE_QUOTE, "\""); iri = StringUtils.substringBetween(line, propertyWithDoubleQuote, "\"");
after = "\"" + StringUtils.substringAfter(StringUtils.substringAfter(line, RDF_ABOUT_DOUBLE_QUOTE), "\""); after = "\"" + StringUtils.substringAfter(StringUtils.substringAfter(line, propertyWithDoubleQuote), "\"");
} else if (line.contains(RDF_ABOUT_SINGLE_QUOTE)) { } else if (line.contains(propertyWithSingleQuote)) {
before = StringUtils.substringBefore(line, RDF_ABOUT_DOUBLE_QUOTE) + RDF_ABOUT_SINGLE_QUOTE; before = StringUtils.substringBefore(line, propertyWithDoubleQuote) + propertyWithSingleQuote;
iri = StringUtils.substringBetween(line, RDF_ABOUT_DOUBLE_QUOTE, "'"); iri = StringUtils.substringBetween(line, propertyWithDoubleQuote, "'");
after = "'" + StringUtils.substringAfter(StringUtils.substringAfter(line, RDF_ABOUT_DOUBLE_QUOTE), "'"); after = "'" + StringUtils.substringAfter(StringUtils.substringAfter(line, propertyWithDoubleQuote), "'");
} }
if (iri == null) { if (iri == null) {
return line; return line;
} else { } else {
final String fixedIRI = iri.replaceAll(" ", "%20");
return before + fixedIRI + after; return before + fixIRI(iri) + after;
} }
} }
private static String fixIRI(String iri) {
String result = iri.replaceAll(" ", "%20");
try {
IRIs.reference(result);
} catch (IRIException e) {
log.info("Found a really bad IRI: '{}'", iri);
// A reliable way to turn any text (even a broken URI) into a URI is to use a hash value.
result = "urn:" + DigestUtils.md5Hex(iri);
}
return result;
}
private void readNextLine() throws IOException { private void readNextLine() throws IOException {
final String line = reader.readLine(); final String line = reader.readLine();
if (line == null) { if (line == null) {
...@@ -96,7 +126,7 @@ public class FilterInvalidRDF extends InputStream { ...@@ -96,7 +126,7 @@ public class FilterInvalidRDF extends InputStream {
index++; index++;
return '\n'; return '\n';
} }
byte result = currentLine[index]; byte result = currentLine[index];
index++; index++;
return result; return result;
......
package de.landsh.opendata.catalogproxy; package de.landsh.opendata.catalogproxy;
import org.apache.jena.rdf.model.*; import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.ResIterator;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.RDFLanguages; import org.apache.jena.riot.RDFLanguages;
import org.apache.jena.riot.RDFParser; import org.apache.jena.riot.RDFParser;
import org.apache.jena.riot.system.ErrorHandlerFactory; import org.apache.jena.riot.system.ErrorHandlerFactory;
...@@ -270,11 +273,8 @@ public class CatalogFilterTest { ...@@ -270,11 +273,8 @@ public class CatalogFilterTest {
try (final InputStream inputStream = getClass().getResourceAsStream("/catalog.xml")) { try (final InputStream inputStream = getClass().getResourceAsStream("/catalog.xml")) {
final Model model = catalogFilter.work(inputStream); final Model model = catalogFilter.work(inputStream);
Selector selectorSchema = new SimpleSelector(null, model.createProperty("http://schema.org/startDate"), (Object) null); assertFalse(model.listStatements(null, model.createProperty("http://schema.org/startDate"), (String) null).hasNext());
assertFalse(model.listStatements(selectorSchema).hasNext()); assertTrue(model.listStatements(null, DCAT.startDate, (String) null).hasNext());
Selector selectorDCAT = new SimpleSelector(null, DCAT.startDate, (Object) null);
assertTrue(model.listStatements(selectorDCAT).hasNext());
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment