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 \
|
||||
&& mvn clean install -DskipTests
|
||||
|
||||
COPY src ./src
|
||||
COPY . .
|
||||
|
||||
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.Rio;
|
||||
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.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.eclipse.rdf4j.model.util.Values.iri;
|
||||
|
||||
@Service
|
||||
public class AprioriService {
|
||||
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
public String getProductsResponse(ProductsRequest productsRequest) {
|
||||
Repository repo = new SailRepository(new MemoryStore());
|
||||
repo.init();
|
||||
|
||||
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 = """
|
||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||
@@ -104,7 +115,8 @@ public class AprioriService {
|
||||
repo.init();
|
||||
|
||||
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 = """
|
||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||
@@ -146,7 +158,8 @@ public class AprioriService {
|
||||
repo.init();
|
||||
|
||||
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 = """
|
||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||
@@ -188,7 +201,8 @@ public class AprioriService {
|
||||
repo.init();
|
||||
|
||||
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 = """
|
||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||
@@ -226,7 +240,8 @@ public class AprioriService {
|
||||
repo.init();
|
||||
|
||||
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 = """
|
||||
PREFIX vvo: <http://vvo.pisanoapi.at/>
|
||||
@@ -265,15 +280,35 @@ public class AprioriService {
|
||||
IRI beschreibungIri = iri("http://vvo.pisanoapi.at/beschreibung");
|
||||
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;
|
||||
for (File plausi : Arrays.stream(file.listFiles()).sorted().collect(Collectors.toList())) {
|
||||
var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
||||
List<Resource> sortedResources = Arrays.stream(resources)
|
||||
.sorted(Comparator.comparing(Resource::getFilename))
|
||||
.toList();
|
||||
|
||||
String beschreibung = lines.stream().filter(line -> line.startsWith("#beschreibung:")).findFirst().get().substring(14);
|
||||
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"));
|
||||
for (Resource plausiResource : sortedResources) {
|
||||
List<String> lines;
|
||||
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);
|
||||
|
||||
@@ -284,6 +319,5 @@ public class AprioriService {
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,44 +66,44 @@ public class CalculateService {
|
||||
|
||||
private VerkaufsproduktType pruefePlausis(VerkaufsproduktType vp) throws IOException {
|
||||
|
||||
File file = new File("src/main/resources/data/plausis");
|
||||
|
||||
Repository repo = new SailRepository(new MemoryStore());
|
||||
repo.init();
|
||||
|
||||
try (RepositoryConnection conn = repo.getConnection()) {
|
||||
TreeHelper treeHelper = new TreeHelper();
|
||||
TreeItem<GuiProdukt> vpTree = new TreeItem<>(new GuiProdukt(vp));
|
||||
treeHelper.produktToTree(vp, vpTree);
|
||||
Model model = rdfHelper.createRdfModel(vpTree);
|
||||
conn.add(model);
|
||||
|
||||
for (File plausi : file.listFiles()) {
|
||||
var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
||||
|
||||
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"));
|
||||
|
||||
|
||||
if (art.equals("update")){
|
||||
conn.prepareUpdate(query).execute();
|
||||
|
||||
model.clear();
|
||||
conn.getStatements(null, null, null).forEach(model::add);
|
||||
}else if (art.equals("graph")){
|
||||
GraphQuery q = conn.prepareGraphQuery(query);
|
||||
Model validatedModel = QueryResults.asModel(q.evaluate());
|
||||
model.addAll(validatedModel);
|
||||
}
|
||||
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Rio.write(model, baos, RDFFormat.JSONLD);
|
||||
|
||||
return rdfHelper.calculateRequestToVerkaufsprodukt(baos.toString());
|
||||
} catch(Exception ignored) {
|
||||
System.out.println(ignored.getMessage());
|
||||
}
|
||||
// File file = new File("src/main/resources/data/plausis");
|
||||
//
|
||||
// Repository repo = new SailRepository(new MemoryStore());
|
||||
// repo.init();
|
||||
//
|
||||
// try (RepositoryConnection conn = repo.getConnection()) {
|
||||
// TreeHelper treeHelper = new TreeHelper();
|
||||
// TreeItem<GuiProdukt> vpTree = new TreeItem<>(new GuiProdukt(vp));
|
||||
// treeHelper.produktToTree(vp, vpTree);
|
||||
// Model model = rdfHelper.createRdfModel(vpTree);
|
||||
// conn.add(model);
|
||||
//
|
||||
// for (File plausi : file.listFiles()) {
|
||||
// var lines = Files.lines(plausi.toPath()).map(String::trim).toList();
|
||||
//
|
||||
// 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"));
|
||||
//
|
||||
//
|
||||
// if (art.equals("update")){
|
||||
// conn.prepareUpdate(query).execute();
|
||||
//
|
||||
// model.clear();
|
||||
// conn.getStatements(null, null, null).forEach(model::add);
|
||||
// }else if (art.equals("graph")){
|
||||
// GraphQuery q = conn.prepareGraphQuery(query);
|
||||
// Model validatedModel = QueryResults.asModel(q.evaluate());
|
||||
// model.addAll(validatedModel);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
// Rio.write(model, baos, RDFFormat.JSONLD);
|
||||
//
|
||||
// return rdfHelper.calculateRequestToVerkaufsprodukt(baos.toString());
|
||||
// } catch(Exception ignored) {
|
||||
// System.out.println(ignored.getMessage());
|
||||
// }
|
||||
return vp;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user