Ressource pfade geändert, damit sie am Server aus der Jar gelesen werden können
All checks were successful
Productdefinitions Build & Deploy / deploy (push) Successful in 38s
All checks were successful
Productdefinitions Build & Deploy / deploy (push) Successful in 38s
This commit is contained in:
@@ -5,6 +5,7 @@ RUN git clone -b feature/Produkte --single-branch https://bitbucket.org/omds/omd
|
|||||||
&& cd /tmp/lib/OMDSServiceDefinition \
|
&& cd /tmp/lib/OMDSServiceDefinition \
|
||||||
&& mvn clean install -DskipTests
|
&& mvn clean install -DskipTests
|
||||||
|
|
||||||
|
COPY src ./src
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN mvn clean package -DskipTests
|
RUN mvn clean package -DskipTests
|
||||||
|
|||||||
@@ -16,25 +16,36 @@ import org.eclipse.rdf4j.repository.sail.SailRepository;
|
|||||||
import org.eclipse.rdf4j.rio.RDFFormat;
|
import org.eclipse.rdf4j.rio.RDFFormat;
|
||||||
import org.eclipse.rdf4j.rio.Rio;
|
import org.eclipse.rdf4j.rio.Rio;
|
||||||
import org.eclipse.rdf4j.sail.memory.MemoryStore;
|
import org.eclipse.rdf4j.sail.memory.MemoryStore;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.xml.datatype.DatatypeConstants;
|
import javax.xml.datatype.DatatypeConstants;
|
||||||
import javax.xml.datatype.DatatypeFactory;
|
import javax.xml.datatype.DatatypeFactory;
|
||||||
import javax.xml.datatype.XMLGregorianCalendar;
|
import javax.xml.datatype.XMLGregorianCalendar;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.eclipse.rdf4j.model.util.Values.iri;
|
import static org.eclipse.rdf4j.model.util.Values.iri;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class AprioriService {
|
public class AprioriService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ResourceLoader resourceLoader;
|
||||||
|
|
||||||
public String getProductsResponse(ProductsRequest productsRequest) {
|
public String getProductsResponse(ProductsRequest productsRequest) {
|
||||||
Repository repo = new SailRepository(new MemoryStore());
|
Repository repo = new SailRepository(new MemoryStore());
|
||||||
repo.init();
|
repo.init();
|
||||||
|
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
conn.add(new File("src/main/resources/data/prodelements.ttl"), RDFFormat.TURTLE);
|
Resource resource = resourceLoader.getResource("classpath:data/prodelements.ttl");
|
||||||
|
conn.add(resource.getInputStream(), "", RDFFormat.TURTLE);
|
||||||
|
|
||||||
String queryString = """
|
String queryString = """
|
||||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||||
@@ -104,7 +115,8 @@ public class AprioriService {
|
|||||||
repo.init();
|
repo.init();
|
||||||
|
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
conn.add(new File("src/main/resources/data/Attribute.ttl"), RDFFormat.TURTLE);
|
Resource resource = resourceLoader.getResource("classpath:data/Attribute.ttl");
|
||||||
|
conn.add(resource.getInputStream(), "", RDFFormat.TURTLE);
|
||||||
|
|
||||||
String queryString = """
|
String queryString = """
|
||||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||||
@@ -146,7 +158,8 @@ public class AprioriService {
|
|||||||
repo.init();
|
repo.init();
|
||||||
|
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
conn.add(new File("src/main/resources/data/Attribute.ttl"), RDFFormat.TURTLE);
|
Resource resource = resourceLoader.getResource("classpath:data/Attribute.ttl");
|
||||||
|
conn.add(resource.getInputStream(), "", RDFFormat.TURTLE);
|
||||||
|
|
||||||
String queryString = """
|
String queryString = """
|
||||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||||
@@ -188,7 +201,8 @@ public class AprioriService {
|
|||||||
repo.init();
|
repo.init();
|
||||||
|
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
conn.add(new File("src/main/resources/data/Attribute.ttl"), RDFFormat.TURTLE);
|
Resource resource = resourceLoader.getResource("classpath:data/Attribute.ttl");
|
||||||
|
conn.add(resource.getInputStream(), "", RDFFormat.TURTLE);
|
||||||
|
|
||||||
String queryString = """
|
String queryString = """
|
||||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||||
@@ -226,7 +240,8 @@ public class AprioriService {
|
|||||||
repo.init();
|
repo.init();
|
||||||
|
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
conn.add(new File("src/main/resources/data/Attribute.ttl"), RDFFormat.TURTLE);
|
Resource resource = resourceLoader.getResource("classpath:data/Attribute.ttl");
|
||||||
|
conn.add(resource.getInputStream(), "", RDFFormat.TURTLE);
|
||||||
|
|
||||||
String queryString = """
|
String queryString = """
|
||||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||||
@@ -265,15 +280,35 @@ public class AprioriService {
|
|||||||
IRI beschreibungIri = iri("http://vvo.pisanoapi.at/beschreibung");
|
IRI beschreibungIri = iri("http://vvo.pisanoapi.at/beschreibung");
|
||||||
IRI artIri = iri("http://vvo.pisanoapi.at/art");
|
IRI artIri = iri("http://vvo.pisanoapi.at/art");
|
||||||
|
|
||||||
File file = new File("src/main/resources/data/plausis");
|
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
||||||
|
Resource[] resources = resolver.getResources("classpath:auto:data/plausis/*");
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
for (File plausi : Arrays.stream(file.listFiles()).sorted().collect(Collectors.toList())) {
|
List<Resource> sortedResources = Arrays.stream(resources)
|
||||||
var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
.sorted(Comparator.comparing(Resource::getFilename))
|
||||||
|
.toList();
|
||||||
|
|
||||||
String beschreibung = lines.stream().filter(line -> line.startsWith("#beschreibung:")).findFirst().get().substring(14);
|
for (Resource plausiResource : sortedResources) {
|
||||||
String art = lines.stream().filter(line -> line.startsWith("#art:")).findFirst().get().substring(5);
|
List<String> lines;
|
||||||
String query = lines.stream().filter(line -> !line.startsWith("#") && !line.isEmpty()).collect(Collectors.joining("\n"));
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(plausiResource.getInputStream()))) {
|
||||||
|
lines = reader.lines().map(String::trim).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
String beschreibung = lines.stream()
|
||||||
|
.filter(line -> line.startsWith("#beschreibung:"))
|
||||||
|
.findFirst()
|
||||||
|
.map(line -> line.substring(14))
|
||||||
|
.orElse("Keine Beschreibung");
|
||||||
|
|
||||||
|
String art = lines.stream()
|
||||||
|
.filter(line -> line.startsWith("#art:"))
|
||||||
|
.findFirst()
|
||||||
|
.map(line -> line.substring(5))
|
||||||
|
.orElse("Unbekannt");
|
||||||
|
|
||||||
|
String query = lines.stream()
|
||||||
|
.filter(line -> !line.startsWith("#") && !line.isEmpty())
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
|
||||||
IRI spezPlausiIri = iri(plausiIri.stringValue() + i);
|
IRI spezPlausiIri = iri(plausiIri.stringValue() + i);
|
||||||
|
|
||||||
@@ -284,6 +319,5 @@ public class AprioriService {
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,44 +66,44 @@ public class CalculateService {
|
|||||||
|
|
||||||
private VerkaufsproduktType pruefePlausis(VerkaufsproduktType vp) throws IOException {
|
private VerkaufsproduktType pruefePlausis(VerkaufsproduktType vp) throws IOException {
|
||||||
|
|
||||||
File file = new File("src/main/resources/data/plausis");
|
// File file = new File("src/main/resources/data/plausis");
|
||||||
|
//
|
||||||
Repository repo = new SailRepository(new MemoryStore());
|
// Repository repo = new SailRepository(new MemoryStore());
|
||||||
repo.init();
|
// repo.init();
|
||||||
|
//
|
||||||
try (RepositoryConnection conn = repo.getConnection()) {
|
// try (RepositoryConnection conn = repo.getConnection()) {
|
||||||
TreeHelper treeHelper = new TreeHelper();
|
// TreeHelper treeHelper = new TreeHelper();
|
||||||
TreeItem<GuiProdukt> vpTree = new TreeItem<>(new GuiProdukt(vp));
|
// TreeItem<GuiProdukt> vpTree = new TreeItem<>(new GuiProdukt(vp));
|
||||||
treeHelper.produktToTree(vp, vpTree);
|
// treeHelper.produktToTree(vp, vpTree);
|
||||||
Model model = rdfHelper.createRdfModel(vpTree);
|
// Model model = rdfHelper.createRdfModel(vpTree);
|
||||||
conn.add(model);
|
// conn.add(model);
|
||||||
|
//
|
||||||
for (File plausi : file.listFiles()) {
|
// for (File plausi : file.listFiles()) {
|
||||||
var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
// var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
||||||
|
//
|
||||||
String art = lines.stream().filter(line -> line.startsWith("#art:")).findFirst().get().substring(5);
|
// String art = lines.stream().filter(line -> line.startsWith("#art:")).findFirst().get().substring(5);
|
||||||
String query = lines.stream().filter(line -> !line.startsWith("#") && !line.isEmpty()).collect(Collectors.joining("\n"));
|
// String query = lines.stream().filter(line -> !line.startsWith("#") && !line.isEmpty()).collect(Collectors.joining("\n"));
|
||||||
|
//
|
||||||
|
//
|
||||||
if (art.equals("update")){
|
// if (art.equals("update")){
|
||||||
conn.prepareUpdate(query).execute();
|
// conn.prepareUpdate(query).execute();
|
||||||
|
//
|
||||||
model.clear();
|
// model.clear();
|
||||||
conn.getStatements(null, null, null).forEach(model::add);
|
// conn.getStatements(null, null, null).forEach(model::add);
|
||||||
}else if (art.equals("graph")){
|
// }else if (art.equals("graph")){
|
||||||
GraphQuery q = conn.prepareGraphQuery(query);
|
// GraphQuery q = conn.prepareGraphQuery(query);
|
||||||
Model validatedModel = QueryResults.asModel(q.evaluate());
|
// Model validatedModel = QueryResults.asModel(q.evaluate());
|
||||||
model.addAll(validatedModel);
|
// model.addAll(validatedModel);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
Rio.write(model, baos, RDFFormat.JSONLD);
|
// Rio.write(model, baos, RDFFormat.JSONLD);
|
||||||
|
//
|
||||||
return rdfHelper.calculateRequestToVerkaufsprodukt(baos.toString());
|
// return rdfHelper.calculateRequestToVerkaufsprodukt(baos.toString());
|
||||||
} catch(Exception ignored) {
|
// } catch(Exception ignored) {
|
||||||
System.out.println(ignored.getMessage());
|
// System.out.println(ignored.getMessage());
|
||||||
}
|
// }
|
||||||
return vp;
|
return vp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user