MARMOTTA-556: minor details in the ldf module
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/ec0b8196 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/ec0b8196 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/ec0b8196 Branch: refs/heads/MARMOTTA-556 Commit: ec0b81967b46126035c3edaeebf836557be7b697 Parents: 22d16b3 Author: Sergio Fernández <[email protected]> Authored: Mon Oct 27 09:01:18 2014 +0100 Committer: Sergio Fernández <[email protected]> Committed: Mon Oct 27 09:01:18 2014 +0100 ---------------------------------------------------------------------- .../marmotta/platform/ldf/api/LdfService.java | 8 +-- .../platform/ldf/services/LdfServiceImpl.java | 8 +-- .../platform/ldf/sesame/LdfRDFHandler.java | 55 +++++++++++--------- .../src/main/resources/META-INF/beans.xml | 28 ++++++++++ .../src/main/resources/kiwi-module.properties | 28 ++++++++++ 5 files changed, 95 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/ec0b8196/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/api/LdfService.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/api/LdfService.java b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/api/LdfService.java index a1d2dce..c2d7dff 100644 --- a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/api/LdfService.java +++ b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/api/LdfService.java @@ -46,7 +46,7 @@ public interface LdfService { * @param format RDF serialization * @param out output stream where write the fragment */ - void writeFragment(String subject, String predicate, String object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException; + void writeFragment(String subject, String predicate, String object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException; /** * Writes a fragment matching the specified triple fragment pattern @@ -59,7 +59,7 @@ public interface LdfService { * @param format RDF serialization * @param out output stream where write the fragment */ - void writeFragment(URI subject, URI predicate, Value object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException; + void writeFragment(URI subject, URI predicate, Value object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException; /** * Writes a fragment matching the specified quad fragment pattern @@ -73,7 +73,7 @@ public interface LdfService { * @param format RDF serialization * @param out output stream where write the fragment */ - void writeFragment(String subject, String predicate, String object, String context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException; + void writeFragment(String subject, String predicate, String object, String context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException; /** * Writes a fragment matching the specified quad fragment pattern @@ -87,6 +87,6 @@ public interface LdfService { * @param format RDF serialization * @param out output stream where write the fragment */ - void writeFragment(URI subject, URI predicate, Value object, Resource context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException; + void writeFragment(URI subject, URI predicate, Value object, Resource context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException; } http://git-wip-us.apache.org/repos/asf/marmotta/blob/ec0b8196/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/services/LdfServiceImpl.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/services/LdfServiceImpl.java b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/services/LdfServiceImpl.java index 580cb25..4ccdfeb 100644 --- a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/services/LdfServiceImpl.java +++ b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/services/LdfServiceImpl.java @@ -48,17 +48,17 @@ public class LdfServiceImpl implements LdfService { private SesameService sesameService; @Override - public void writeFragment(String subjectStr, String predicateStr, String objectStr, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException { + public void writeFragment(String subjectStr, String predicateStr, String objectStr, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException { writeFragment(subjectStr, predicateStr, objectStr, null, page, format, out); } @Override - public void writeFragment(URI subject, URI predicate, Value object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException { + public void writeFragment(URI subject, URI predicate, Value object, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException { writeFragment(subject, predicate, object, null, page, format, out); } @Override - public void writeFragment(String subjectStr, String predicateStr, String objectStr, String contextStr, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException { + public void writeFragment(String subjectStr, String predicateStr, String objectStr, String contextStr, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException { final ValueFactoryImpl vf = new ValueFactoryImpl(); URI subject = null; @@ -105,7 +105,7 @@ public class LdfServiceImpl implements LdfService { } @Override - public void writeFragment(URI subject, URI predicate, Value object, Resource context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException { + public void writeFragment(URI subject, URI predicate, Value object, Resource context, int page, RDFFormat format, OutputStream out) throws RepositoryException, RDFHandlerException, IllegalArgumentException { final RepositoryConnection conn = sesameService.getConnection(); try { conn.begin(); http://git-wip-us.apache.org/repos/asf/marmotta/blob/ec0b8196/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/sesame/LdfRDFHandler.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/sesame/LdfRDFHandler.java b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/sesame/LdfRDFHandler.java index 5164705..34ed85b 100644 --- a/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/sesame/LdfRDFHandler.java +++ b/platform/marmotta-ldf/src/main/java/org/apache/marmotta/platform/ldf/sesame/LdfRDFHandler.java @@ -29,6 +29,7 @@ import org.openrdf.model.Statement; import org.openrdf.model.impl.StatementImpl; import org.openrdf.model.impl.ValueFactoryImpl; import org.openrdf.model.vocabulary.RDF; +import org.openrdf.model.vocabulary.RDFS; import org.openrdf.rio.RDFHandler; import org.openrdf.rio.RDFHandlerException; @@ -104,6 +105,8 @@ public class LdfRDFHandler implements RDFHandler { @Override public void endRDF() throws RDFHandlerException { + final ValueFactoryImpl vf = new ValueFactoryImpl(); + //first order by a fixed criteria Collections.sort(statements, new Comparator<Statement>() { @Override @@ -128,33 +131,37 @@ public class LdfRDFHandler implements RDFHandler { final int size = statements.size(); final int offset = LdfService.PAGE_SIZE * (page - 1); if (offset > size) { - throw new RDFHandlerException("page " + page + " can't be generated"); - } - final int limit = LdfService.PAGE_SIZE < size-offset ? LdfService.PAGE_SIZE : size-offset; - List<Statement> filteredStatements = statements.subList(offset, limit); - - //send statements to delegate writer - for (Statement statement : filteredStatements) { - handler.handleStatement(statement); - } - - //add ldf metadata - final ValueFactoryImpl vf = new ValueFactoryImpl(); + //throw new RDFHandlerException("page " + page + " can't be generated"); + Resource error = this.context != null ? this.context : vf.createBNode(); + handler.handleStatement(new StatementImpl(error, RDF.TYPE, HYDRA.Error)); + handler.handleStatement(new StatementImpl(error, RDFS.COMMENT, vf.createLiteral("page " + page + " can't be generated", "en"))); + } else { + final int limit = LdfService.PAGE_SIZE < size - offset ? LdfService.PAGE_SIZE : size - offset; + List<Statement> filteredStatements = statements.subList(offset, limit); + + //send statements to delegate writer + for (Statement statement : filteredStatements) { + handler.handleStatement(statement); + } - Resource dataset = this.context != null ? this.context : vf.createBNode(); - handler.handleStatement(new StatementImpl(dataset, RDF.TYPE, VOID.Dataset)); - handler.handleStatement(new StatementImpl(dataset, RDF.TYPE, HYDRA.Collection)); + //add ldf metadata + Resource dataset = this.context != null ? this.context : vf.createBNode(); + handler.handleStatement(new StatementImpl(dataset, RDF.TYPE, VOID.Dataset)); + handler.handleStatement(new StatementImpl(dataset, RDF.TYPE, HYDRA.Collection)); - Resource fragment = vf.createBNode(); //TODO - handler.handleStatement(new StatementImpl(dataset, VOID.subset, fragment)); - handler.handleStatement(new StatementImpl(fragment, RDF.TYPE, HYDRA.Collection)); - if (offset != 0 && limit != size) handler.handleStatement(new StatementImpl(fragment, RDF.TYPE, HYDRA.PagedCollection)); - handler.handleStatement(new StatementImpl(fragment, VOID.triples, vf.createLiteral(Integer.toString(filteredStatements.size()), XSD.Integer))); - handler.handleStatement(new StatementImpl(fragment, HYDRA.totalItems, vf.createLiteral(Integer.toString(filteredStatements.size()), XSD.Integer))); - handler.handleStatement(new StatementImpl(fragment, HYDRA.itemsPerPage, vf.createLiteral(Integer.toString(LdfService.PAGE_SIZE), XSD.Integer))); - //TODO: HYDRA_FIRSTPAGE, HYDRA_PREVIOUSPAGE, HYDRA_NEXTPAGE + Resource fragment = vf.createBNode(); //TODO + handler.handleStatement(new StatementImpl(dataset, VOID.subset, fragment)); + handler.handleStatement(new StatementImpl(fragment, RDF.TYPE, HYDRA.Collection)); + if (offset != 0 && limit != size) { + handler.handleStatement(new StatementImpl(fragment, RDF.TYPE, HYDRA.PagedCollection)); + } + handler.handleStatement(new StatementImpl(fragment, VOID.triples, vf.createLiteral(Integer.toString(filteredStatements.size()), XSD.Integer))); + handler.handleStatement(new StatementImpl(fragment, HYDRA.totalItems, vf.createLiteral(Integer.toString(filteredStatements.size()), XSD.Integer))); + handler.handleStatement(new StatementImpl(fragment, HYDRA.itemsPerPage, vf.createLiteral(Integer.toString(LdfService.PAGE_SIZE), XSD.Integer))); + //TODO: HYDRA_FIRSTPAGE, HYDRA_PREVIOUSPAGE, HYDRA_NEXTPAGE - //TODO: hydra controls + //TODO: hydra controls + } //and actually end the rdf handler.endRDF(); http://git-wip-us.apache.org/repos/asf/marmotta/blob/ec0b8196/platform/marmotta-ldf/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldf/src/main/resources/META-INF/beans.xml b/platform/marmotta-ldf/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..6a9575d --- /dev/null +++ b/platform/marmotta-ldf/src/main/resources/META-INF/beans.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans + xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://java.sun.com/xml/ns/javaee + http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> + +</beans> http://git-wip-us.apache.org/repos/asf/marmotta/blob/ec0b8196/platform/marmotta-ldf/src/main/resources/kiwi-module.properties ---------------------------------------------------------------------- diff --git a/platform/marmotta-ldf/src/main/resources/kiwi-module.properties b/platform/marmotta-ldf/src/main/resources/kiwi-module.properties new file mode 100644 index 0000000..ee47136 --- /dev/null +++ b/platform/marmotta-ldf/src/main/resources/kiwi-module.properties @@ -0,0 +1,28 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name=LDF +weight = 60 +container = Query and Update +container.weight = 12 + +baseurl=/ldf + +subtitle = Linked Data Fragments + +webservices=org.apache.marmotta.platform.ldf.webservices.LdfWebService
