diff --git a/pom.xml b/pom.xml index 6a2160aa..ac5f4f80 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ ${packaging.type} AtomGraph Processor - Ontology-driven Linked Data processor and server for SPARQL backends + Ontology-driven Linked Data processor https://github.com/AtomGraph/Processor 2015 @@ -78,18 +78,8 @@ ${project.groupId} - twirl - 1.0.32 - - - ${project.groupId} - core - 4.0.3 - - - org.apache.jena - jena-shacl - 4.7.0 + server + ${project.version} diff --git a/src/main/java/com/atomgraph/processor/exception/OntologyException.java b/src/main/java/com/atomgraph/processor/exception/OntologyException.java deleted file mode 100644 index 198fa229..00000000 --- a/src/main/java/com/atomgraph/processor/exception/OntologyException.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2015 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.processor.exception; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class OntologyException extends RuntimeException -{ - - public OntologyException() - { - } - - public OntologyException(String message) - { - super(message); - } - - public OntologyException(String message, Throwable cause) - { - super(message, cause); - } - - public OntologyException(Throwable cause) - { - super(cause); - } - - public OntologyException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) - { - super(message, cause, enableSuppression, writableStackTrace); - } - -} diff --git a/src/main/java/com/atomgraph/server/factory/OntologyFactory.java b/src/main/java/com/atomgraph/processor/factory/OntologyFactory.java similarity index 97% rename from src/main/java/com/atomgraph/server/factory/OntologyFactory.java rename to src/main/java/com/atomgraph/processor/factory/OntologyFactory.java index a8c28520..2c589437 100644 --- a/src/main/java/com/atomgraph/server/factory/OntologyFactory.java +++ b/src/main/java/com/atomgraph/processor/factory/OntologyFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.atomgraph.server.factory; +package com.atomgraph.processor.factory; import java.util.Optional; import jakarta.ws.rs.ext.Provider; diff --git a/src/main/java/com/atomgraph/server/factory/TemplateCallFactory.java b/src/main/java/com/atomgraph/processor/factory/TemplateCallFactory.java similarity index 98% rename from src/main/java/com/atomgraph/server/factory/TemplateCallFactory.java rename to src/main/java/com/atomgraph/processor/factory/TemplateCallFactory.java index 58c1f1c3..dd8cea87 100644 --- a/src/main/java/com/atomgraph/server/factory/TemplateCallFactory.java +++ b/src/main/java/com/atomgraph/processor/factory/TemplateCallFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.atomgraph.server.factory; +package com.atomgraph.processor.factory; import com.atomgraph.processor.model.Template; import com.atomgraph.processor.model.TemplateCall; diff --git a/src/main/java/com/atomgraph/processor/model/impl/TemplateImpl.java b/src/main/java/com/atomgraph/processor/model/impl/TemplateImpl.java index ceeecad6..cf741ff1 100644 --- a/src/main/java/com/atomgraph/processor/model/impl/TemplateImpl.java +++ b/src/main/java/com/atomgraph/processor/model/impl/TemplateImpl.java @@ -33,7 +33,7 @@ import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.vocabulary.RDF; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.model.Template; import com.atomgraph.processor.vocabulary.LDT; import org.apache.jena.rdf.model.RDFList; diff --git a/src/main/java/com/atomgraph/server/Application.java b/src/main/java/com/atomgraph/processor/server/Application.java similarity index 96% rename from src/main/java/com/atomgraph/server/Application.java rename to src/main/java/com/atomgraph/processor/server/Application.java index 8099c8fa..6e0a7593 100644 --- a/src/main/java/com/atomgraph/server/Application.java +++ b/src/main/java/com/atomgraph/processor/server/Application.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server; +package com.atomgraph.processor.server; import com.atomgraph.core.MediaTypes; import com.atomgraph.core.exception.ConfigurationException; @@ -26,7 +26,7 @@ import org.apache.jena.enhanced.BuiltinPersonalities; import org.apache.jena.util.LocationMapper; import com.atomgraph.core.factory.DataManagerFactory; -import com.atomgraph.server.model.impl.ResourceBase; +import com.atomgraph.processor.server.model.impl.ResourceBase; import com.atomgraph.core.provider.QueryParamProvider; import com.atomgraph.core.io.ResultSetProvider; import com.atomgraph.core.io.UpdateRequestProvider; @@ -35,7 +35,7 @@ import com.atomgraph.server.mapper.ConfigurationExceptionMapper; import com.atomgraph.server.mapper.ModelExceptionMapper; import com.atomgraph.server.mapper.NotFoundExceptionMapper; -import com.atomgraph.server.mapper.ParameterExceptionMapper; +import com.atomgraph.processor.server.mapper.ParameterExceptionMapper; import com.atomgraph.server.mapper.jena.DatatypeFormatExceptionMapper; import com.atomgraph.server.mapper.jena.QueryParseExceptionMapper; import com.atomgraph.server.mapper.jena.RiotExceptionMapper; @@ -44,8 +44,8 @@ import com.atomgraph.processor.model.impl.TemplateImpl; import com.atomgraph.processor.vocabulary.AP; import com.atomgraph.server.mapper.OntologyExceptionMapper; -import com.atomgraph.server.util.OntologyLoader; -import com.atomgraph.server.io.SkolemizingModelProvider; +import com.atomgraph.processor.util.OntologyLoader; +import com.atomgraph.processor.server.io.SkolemizingModelProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atomgraph.processor.model.Parameter; @@ -62,12 +62,12 @@ import com.atomgraph.core.util.jena.DataManagerImpl; import com.atomgraph.processor.model.TemplateCall; import com.atomgraph.processor.model.impl.ApplicationImpl; -import com.atomgraph.server.factory.OntologyFactory; +import com.atomgraph.processor.factory.OntologyFactory; import com.atomgraph.server.mapper.BadGatewayExceptionMapper; import com.atomgraph.server.mapper.NotAcceptableExceptionMapper; import com.atomgraph.server.mapper.NotSupportedExceptionMapper; -import com.atomgraph.server.factory.TemplateCallFactory; -import com.atomgraph.server.filter.response.ResponseHeaderFilter; +import com.atomgraph.processor.factory.TemplateCallFactory; +import com.atomgraph.processor.server.filter.response.ResponseHeaderFilter; import com.atomgraph.server.mapper.SHACLConstraintViolationExceptionMapper; import com.atomgraph.spinrdf.vocabulary.SP; import java.util.HashMap; diff --git a/src/main/java/com/atomgraph/server/filter/response/ResponseHeaderFilter.java b/src/main/java/com/atomgraph/processor/server/filter/response/ResponseHeaderFilter.java similarity index 97% rename from src/main/java/com/atomgraph/server/filter/response/ResponseHeaderFilter.java rename to src/main/java/com/atomgraph/processor/server/filter/response/ResponseHeaderFilter.java index 2752a1c8..fe33828d 100644 --- a/src/main/java/com/atomgraph/server/filter/response/ResponseHeaderFilter.java +++ b/src/main/java/com/atomgraph/processor/server/filter/response/ResponseHeaderFilter.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.filter.response; +package com.atomgraph.processor.server.filter.response; import com.atomgraph.core.util.Link; import com.atomgraph.processor.model.TemplateCall; diff --git a/src/main/java/com/atomgraph/server/io/SkolemizingDatasetProvider.java b/src/main/java/com/atomgraph/processor/server/io/SkolemizingDatasetProvider.java similarity index 96% rename from src/main/java/com/atomgraph/server/io/SkolemizingDatasetProvider.java rename to src/main/java/com/atomgraph/processor/server/io/SkolemizingDatasetProvider.java index 08614e0e..b27d6669 100644 --- a/src/main/java/com/atomgraph/server/io/SkolemizingDatasetProvider.java +++ b/src/main/java/com/atomgraph/processor/server/io/SkolemizingDatasetProvider.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.atomgraph.server.io; +package com.atomgraph.processor.server.io; import com.atomgraph.processor.util.Skolemizer; import com.atomgraph.server.exception.SkolemizationException; +import com.atomgraph.server.io.ValidatingDatasetProvider; import java.util.Iterator; import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.Request; diff --git a/src/main/java/com/atomgraph/server/io/SkolemizingModelProvider.java b/src/main/java/com/atomgraph/processor/server/io/SkolemizingModelProvider.java similarity index 96% rename from src/main/java/com/atomgraph/server/io/SkolemizingModelProvider.java rename to src/main/java/com/atomgraph/processor/server/io/SkolemizingModelProvider.java index 2f6ca543..7a9dde64 100644 --- a/src/main/java/com/atomgraph/server/io/SkolemizingModelProvider.java +++ b/src/main/java/com/atomgraph/processor/server/io/SkolemizingModelProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.io; +package com.atomgraph.processor.server.io; import org.apache.jena.ontology.Ontology; import org.apache.jena.rdf.model.Model; @@ -23,6 +23,7 @@ import jakarta.ws.rs.core.UriBuilder; import com.atomgraph.server.exception.SkolemizationException; import com.atomgraph.processor.util.Skolemizer; +import com.atomgraph.server.io.ValidatingModelProvider; import jakarta.ws.rs.HttpMethod; import org.apache.jena.rdf.model.ResIterator; import org.apache.jena.rdf.model.Resource; diff --git a/src/main/java/com/atomgraph/server/mapper/ParameterExceptionMapper.java b/src/main/java/com/atomgraph/processor/server/mapper/ParameterExceptionMapper.java similarity index 93% rename from src/main/java/com/atomgraph/server/mapper/ParameterExceptionMapper.java rename to src/main/java/com/atomgraph/processor/server/mapper/ParameterExceptionMapper.java index da284949..1d85b8c1 100644 --- a/src/main/java/com/atomgraph/server/mapper/ParameterExceptionMapper.java +++ b/src/main/java/com/atomgraph/processor/server/mapper/ParameterExceptionMapper.java @@ -14,13 +14,14 @@ * limitations under the License. */ -package com.atomgraph.server.mapper; +package com.atomgraph.processor.server.mapper; import com.atomgraph.core.MediaTypes; import org.apache.jena.rdf.model.ResourceFactory; import jakarta.ws.rs.core.Response; import jakarta.ws.rs.ext.ExceptionMapper; import com.atomgraph.processor.exception.ParameterException; +import com.atomgraph.server.mapper.ExceptionMapperBase; import jakarta.inject.Inject; /** diff --git a/src/main/java/com/atomgraph/server/model/QueriedResource.java b/src/main/java/com/atomgraph/processor/server/model/QueriedResource.java similarity index 85% rename from src/main/java/com/atomgraph/server/model/QueriedResource.java rename to src/main/java/com/atomgraph/processor/server/model/QueriedResource.java index b71d5952..11ea9cf4 100644 --- a/src/main/java/com/atomgraph/server/model/QueriedResource.java +++ b/src/main/java/com/atomgraph/processor/server/model/QueriedResource.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.model; +package com.atomgraph.processor.server.model; import org.apache.jena.update.UpdateRequest; @@ -27,9 +27,9 @@ public interface QueriedResource extends com.atomgraph.core.model.QueriedResourc { /** - * Returns the SPARQL query that is used to retrieve RDF description of this resource. + * Returns the SPARQL update that is used to update the RDF description of this resource. * - * @return query builder + * @return update request */ public UpdateRequest getUpdate(); diff --git a/src/main/java/com/atomgraph/server/model/Resource.java b/src/main/java/com/atomgraph/processor/server/model/Resource.java similarity index 95% rename from src/main/java/com/atomgraph/server/model/Resource.java rename to src/main/java/com/atomgraph/processor/server/model/Resource.java index 9361b783..04faa3d6 100644 --- a/src/main/java/com/atomgraph/server/model/Resource.java +++ b/src/main/java/com/atomgraph/processor/server/model/Resource.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.model; +package com.atomgraph.processor.server.model; import com.atomgraph.processor.model.Application; import com.atomgraph.processor.model.TemplateCall; diff --git a/src/main/java/com/atomgraph/server/model/impl/ResourceBase.java b/src/main/java/com/atomgraph/processor/server/model/impl/ResourceBase.java similarity index 88% rename from src/main/java/com/atomgraph/server/model/impl/ResourceBase.java rename to src/main/java/com/atomgraph/processor/server/model/impl/ResourceBase.java index 17898be6..ab6e11e8 100644 --- a/src/main/java/com/atomgraph/server/model/impl/ResourceBase.java +++ b/src/main/java/com/atomgraph/processor/server/model/impl/ResourceBase.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.atomgraph.server.model.impl; +package com.atomgraph.processor.server.model.impl; import com.atomgraph.core.MediaTypes; import org.apache.jena.ontology.*; @@ -28,9 +28,9 @@ import jakarta.ws.rs.core.*; import com.atomgraph.core.model.Service; import com.atomgraph.core.model.impl.QueriedResourceBase; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.model.TemplateCall; -import com.atomgraph.server.util.InsertDataBuilder; +import com.atomgraph.processor.util.InsertDataBuilder; import com.atomgraph.spinrdf.vocabulary.SPIN; import java.io.IOException; import java.util.Collections; @@ -54,7 +54,7 @@ * @see 15 Solution Sequences and Modifiers */ @Path("/") -public class ResourceBase extends QueriedResourceBase implements com.atomgraph.server.model.Resource, com.atomgraph.server.model.QueriedResource +public class ResourceBase extends QueriedResourceBase implements com.atomgraph.processor.server.model.Resource, com.atomgraph.processor.server.model.QueriedResource { private static final Logger log = LoggerFactory.getLogger(ResourceBase.class); @@ -125,16 +125,24 @@ protected ResourceBase(final UriInfo uriInfo, final Request request, final Media queryResource = templateCall.get().getTemplate().getQuery(); if (queryResource != null) { - if (queryResource.canAs(com.atomgraph.spinrdf.model.TemplateCall.class)) - query = new ParameterizedSparqlString(queryResource.as(com.atomgraph.spinrdf.model.TemplateCall.class).getTemplate().getBody().getText(), - querySolutionMap, uriInfo.getBaseUri().toString()).asQuery(); - else + try { - if (queryResource.canAs(com.atomgraph.spinrdf.model.Query.class)) - query = new ParameterizedSparqlString(queryResource.as(com.atomgraph.spinrdf.model.Query.class).getText(), + if (queryResource.canAs(com.atomgraph.spinrdf.model.TemplateCall.class)) + query = new ParameterizedSparqlString(queryResource.as(com.atomgraph.spinrdf.model.TemplateCall.class).getTemplate().getBody().getText(), querySolutionMap, uriInfo.getBaseUri().toString()).asQuery(); else - query = null; + { + if (queryResource.canAs(com.atomgraph.spinrdf.model.Query.class)) + query = new ParameterizedSparqlString(queryResource.as(com.atomgraph.spinrdf.model.Query.class).getText(), + querySolutionMap, uriInfo.getBaseUri().toString()).asQuery(); + else + query = null; + } + } + catch (QueryParseException ex) + { + if (log.isDebugEnabled()) log.debug("Query resource contains an invalid SPARQL string: {}", queryResource); + throw new OntologyException(ex); } } else @@ -143,16 +151,24 @@ protected ResourceBase(final UriInfo uriInfo, final Request request, final Media updateResource = templateCall.get().getTemplate().getUpdate(); if (updateResource != null) { - if (updateResource.canAs(com.atomgraph.spinrdf.model.TemplateCall.class)) - update = new ParameterizedSparqlString(updateResource.as(com.atomgraph.spinrdf.model.TemplateCall.class).getTemplate().getBody().getText(), - querySolutionMap, uriInfo.getBaseUri().toString()).asUpdate(); - else + try { - if (updateResource.canAs(com.atomgraph.spinrdf.model.update.Update.class)) - update = new ParameterizedSparqlString(updateResource.as(com.atomgraph.spinrdf.model.update.Update.class).getText(), + if (updateResource.canAs(com.atomgraph.spinrdf.model.TemplateCall.class)) + update = new ParameterizedSparqlString(updateResource.as(com.atomgraph.spinrdf.model.TemplateCall.class).getTemplate().getBody().getText(), querySolutionMap, uriInfo.getBaseUri().toString()).asUpdate(); else - update = null; + { + if (updateResource.canAs(com.atomgraph.spinrdf.model.update.Update.class)) + update = new ParameterizedSparqlString(updateResource.as(com.atomgraph.spinrdf.model.update.Update.class).getText(), + querySolutionMap, uriInfo.getBaseUri().toString()).asUpdate(); + else + update = null; + } + } + catch (QueryParseException ex) + { + if (log.isDebugEnabled()) log.debug("Update resource contains an invalid SPARQL string: {}", updateResource); + throw new OntologyException(ex); } } else diff --git a/src/main/java/com/atomgraph/server/resource/graph/Item.java b/src/main/java/com/atomgraph/processor/server/resource/graph/Item.java similarity index 96% rename from src/main/java/com/atomgraph/server/resource/graph/Item.java rename to src/main/java/com/atomgraph/processor/server/resource/graph/Item.java index be0504b6..dcfd7816 100644 --- a/src/main/java/com/atomgraph/server/resource/graph/Item.java +++ b/src/main/java/com/atomgraph/processor/server/resource/graph/Item.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.resource.graph; +package com.atomgraph.processor.server.resource.graph; import com.atomgraph.core.MediaTypes; import org.apache.jena.ontology.Ontology; @@ -25,7 +25,7 @@ import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.UriInfo; import com.atomgraph.core.model.Service; -import com.atomgraph.server.model.impl.ResourceBase; +import com.atomgraph.processor.server.model.impl.ResourceBase; import com.atomgraph.processor.model.TemplateCall; import java.util.Optional; import jakarta.inject.Inject; @@ -42,7 +42,7 @@ * @see com.atomgraph.core.model.GraphStore * @see 4.1 Direct Graph Identification */ -public class Item extends ResourceBase // TO-DO: extends GraphStore +public class Item extends ResourceBase { private static final Logger log = LoggerFactory.getLogger(Item.class); diff --git a/src/main/java/com/atomgraph/server/util/InsertDataBuilder.java b/src/main/java/com/atomgraph/processor/util/InsertDataBuilder.java similarity index 98% rename from src/main/java/com/atomgraph/server/util/InsertDataBuilder.java rename to src/main/java/com/atomgraph/processor/util/InsertDataBuilder.java index f27156ef..583b1e37 100644 --- a/src/main/java/com/atomgraph/server/util/InsertDataBuilder.java +++ b/src/main/java/com/atomgraph/processor/util/InsertDataBuilder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.atomgraph.server.util; +package com.atomgraph.processor.util; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/com/atomgraph/server/util/OntologyLoader.java b/src/main/java/com/atomgraph/processor/util/OntologyLoader.java similarity index 95% rename from src/main/java/com/atomgraph/server/util/OntologyLoader.java rename to src/main/java/com/atomgraph/processor/util/OntologyLoader.java index c66052c7..b4762735 100644 --- a/src/main/java/com/atomgraph/server/util/OntologyLoader.java +++ b/src/main/java/com/atomgraph/processor/util/OntologyLoader.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.atomgraph.server.util; +package com.atomgraph.processor.util; import com.atomgraph.core.util.jena.DataManager; import org.apache.jena.ontology.OntDocumentManager; @@ -26,8 +26,7 @@ import java.util.HashMap; import java.util.Map; import org.apache.jena.rdf.model.ModelFactory; -import com.atomgraph.processor.exception.OntologyException; -import com.atomgraph.processor.util.OntModelReadOnly; +import com.atomgraph.server.exception.OntologyException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,8 +123,8 @@ public Ontology getOntology() OntModelSpec loadSpec = new OntModelSpec(OntModelSpec.OWL_MEM); // attempt to use DataManager to retrieve owl:import Models - if (getOntDocumentManager().getFileManager() instanceof DataManager) - loadSpec.setImportModelGetter((DataManager)getOntDocumentManager().getFileManager()); + if (getOntDocumentManager().getFileManager() instanceof DataManager dataManager) + loadSpec.setImportModelGetter(dataManager); return getOntDocumentManager().getOntology(getOntologyURI(), loadSpec).getOntology(getOntologyURI()); } diff --git a/src/main/java/com/atomgraph/processor/util/Skolemizer.java b/src/main/java/com/atomgraph/processor/util/Skolemizer.java index 5512a9e9..9d4612c3 100644 --- a/src/main/java/com/atomgraph/processor/util/Skolemizer.java +++ b/src/main/java/com/atomgraph/processor/util/Skolemizer.java @@ -16,7 +16,7 @@ package com.atomgraph.processor.util; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import org.apache.jena.ontology.Ontology; import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Model; diff --git a/src/main/java/com/atomgraph/processor/util/TemplateMatcher.java b/src/main/java/com/atomgraph/processor/util/TemplateMatcher.java index a6c53e09..34962272 100644 --- a/src/main/java/com/atomgraph/processor/util/TemplateMatcher.java +++ b/src/main/java/com/atomgraph/processor/util/TemplateMatcher.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.model.Template; import com.atomgraph.processor.vocabulary.LDT; import java.util.Comparator; diff --git a/src/main/java/com/atomgraph/processor/util/Validator.java b/src/main/java/com/atomgraph/processor/util/Validator.java deleted file mode 100644 index a987cb21..00000000 --- a/src/main/java/com/atomgraph/processor/util/Validator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2015 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.processor.util; - -import org.apache.jena.ontology.OntModel; -import org.apache.jena.rdf.model.Model; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.atomgraph.spinrdf.constraints.ConstraintViolation; -import com.atomgraph.spinrdf.constraints.SPINConstraints; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class Validator -{ - private static final Logger log = LoggerFactory.getLogger(Validator.class); - - private final OntModel ontModel; - - public Validator(OntModel ontModel) - { - if (ontModel == null) throw new IllegalArgumentException("OntModel cannot be null"); - this.ontModel = ontModel; - } - - public List validate(Model model) - { - if (model == null) throw new IllegalArgumentException("Model cannot be null"); - - return SPINConstraints.check(model, getOntModel()); - } - - public OntModel getOntModel() - { - return ontModel; - } - -} diff --git a/src/main/java/com/atomgraph/processor/vocabulary/DH.java b/src/main/java/com/atomgraph/processor/vocabulary/DH.java deleted file mode 100644 index 2715d7dc..00000000 --- a/src/main/java/com/atomgraph/processor/vocabulary/DH.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.processor.vocabulary; - -import org.apache.jena.ontology.DatatypeProperty; -import org.apache.jena.ontology.ObjectProperty; -import org.apache.jena.ontology.OntClass; -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class DH -{ - - /**

The RDF model that holds the vocabulary terms

*/ - private static OntModel m_model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); - - /**

The namespace of the vocabulary as a string

*/ - public static final String NS = "https://www.w3.org/ns/ldt/document-hierarchy#"; - - /**

The namespace of the vocabulary as a string

- * @see #NS */ - public static String getURI() - { - return NS; - } - - /**

The namespace of the vocabulary as a resource

*/ - public static final Resource NAMESPACE = m_model.createResource( NS ); - - public static final OntClass Document = m_model.createClass( NS + "Document" ); - - public static final OntClass Container = m_model.createClass( NS + "Container" ); - - public static final OntClass Item = m_model.createClass( NS + "Item" ); - - public static final DatatypeProperty slug = m_model.createDatatypeProperty( NS + "slug" ); - - public static final ObjectProperty select = m_model.createObjectProperty( NS + "select"); - -} diff --git a/src/main/java/com/atomgraph/processor/vocabulary/NGT.java b/src/main/java/com/atomgraph/processor/vocabulary/NGT.java deleted file mode 100644 index f509d78c..00000000 --- a/src/main/java/com/atomgraph/processor/vocabulary/NGT.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2017 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.processor.vocabulary; - -import org.apache.jena.ontology.OntClass; -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class NGT -{ - - /**

The RDF model that holds the vocabulary terms

*/ - private static OntModel m_model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); - - /**

The namespace of the vocabulary as a string

*/ - public static final String NS = "https://www.w3.org/ns/ldt/named-graphs/templates#"; - - /**

The namespace of the vocabulary as a string

- * @see #NS */ - public static String getURI() - { - return NS; - } - - /**

The namespace of the vocabulary as a resource

*/ - public static final Resource NAMESPACE = m_model.createResource( NS ); - - public static final OntClass Container = m_model.createClass( NS + "Container" ); - - public static final OntClass Item = m_model.createClass( NS + "Item" ); - -} diff --git a/src/main/java/com/atomgraph/server/exception/ModelException.java b/src/main/java/com/atomgraph/server/exception/ModelException.java deleted file mode 100644 index b8ae5e3f..00000000 --- a/src/main/java/com/atomgraph/server/exception/ModelException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.exception; - -import org.apache.jena.rdf.model.Model; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class ModelException extends RuntimeException -{ - - private final Model model; - - public ModelException(Model model) - { - this.model = model; - } - - public ModelException(Throwable throwable, Model model) - { - super(throwable); - this.model = model; - } - - public Model getModel() - { - return model; - } - -} \ No newline at end of file diff --git a/src/main/java/com/atomgraph/server/exception/SHACLConstraintViolationException.java b/src/main/java/com/atomgraph/server/exception/SHACLConstraintViolationException.java deleted file mode 100644 index 585f0ac0..00000000 --- a/src/main/java/com/atomgraph/server/exception/SHACLConstraintViolationException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2021 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.exception; - -import org.apache.jena.rdf.model.Model; -import org.apache.jena.shacl.ValidationReport; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class SHACLConstraintViolationException extends ModelException -{ - - private final ValidationReport report; - - public SHACLConstraintViolationException(ValidationReport report, Model model) - { - super(model); - this.report = report; - } - - public ValidationReport getValidationReport() - { - return report; - } - -} diff --git a/src/main/java/com/atomgraph/server/exception/SPINConstraintViolationException.java b/src/main/java/com/atomgraph/server/exception/SPINConstraintViolationException.java deleted file mode 100644 index 59723b41..00000000 --- a/src/main/java/com/atomgraph/server/exception/SPINConstraintViolationException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2013 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.exception; - -import org.apache.jena.rdf.model.Model; -import java.util.List; -import com.atomgraph.spinrdf.constraints.ConstraintViolation; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class SPINConstraintViolationException extends ModelException -{ - private final List cvs; - - public SPINConstraintViolationException(List cvs, Model model, String graphURI) - { - super(model); - this.cvs = cvs; - } - - public SPINConstraintViolationException(List cvs, Model model) - { - this(cvs, model, null); - } - - public List getConstraintViolations() - { - return cvs; - } - -} diff --git a/src/main/java/com/atomgraph/server/exception/SkolemizationException.java b/src/main/java/com/atomgraph/server/exception/SkolemizationException.java deleted file mode 100644 index 3a12ba90..00000000 --- a/src/main/java/com/atomgraph/server/exception/SkolemizationException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.exception; - -import org.apache.jena.rdf.model.Model; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class SkolemizationException extends ModelException -{ - - public SkolemizationException(IllegalArgumentException ex, Model model) - { - super(ex, model); - } - -} diff --git a/src/main/java/com/atomgraph/server/io/BasedModelProvider.java b/src/main/java/com/atomgraph/server/io/BasedModelProvider.java deleted file mode 100644 index ba86d734..00000000 --- a/src/main/java/com/atomgraph/server/io/BasedModelProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2017 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.io; - -import com.atomgraph.core.io.ModelProvider; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.core.UriInfo; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.riot.Lang; -import org.apache.jena.riot.RDFLanguages; -import org.apache.jena.shared.NoReaderForLangException; -import org.apache.jena.shared.NoWriterForLangException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * A provider that reads/writes model and resolves relative URIs against request base URI. - * - * @author Martynas Jusevičius {@literal } - */ -public class BasedModelProvider extends ModelProvider -{ - - private static final Logger log = LoggerFactory.getLogger(BasedModelProvider.class); - - @Context UriInfo uriInfo; - - @Override - public Model readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException - { - if (log.isTraceEnabled()) log.trace("Reading Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType); - - Model model = ModelFactory.createDefaultModel(); - - MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param - Lang lang = RDFLanguages.contentTypeToLang(formatType.toString()); - if (lang == null) - { - if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType); - throw new NoReaderForLangException("MediaType not supported: " + formatType); - } - if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang); - - return read(model, entityStream, lang, getUriInfo().getAbsolutePath().toString()); - } - - @Override - public void writeTo(Model model, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException - { - if (log.isTraceEnabled()) log.trace("Writing Model with HTTP headers: {} MediaType: {}", httpHeaders, mediaType); - - MediaType formatType = new MediaType(mediaType.getType(), mediaType.getSubtype()); // discard charset param - Lang lang = RDFLanguages.contentTypeToLang(formatType.toString()); - if (lang == null) - { - if (log.isErrorEnabled()) log.error("MediaType '{}' not supported by Jena", formatType); - throw new NoWriterForLangException("MediaType not supported: " + formatType); - } - if (log.isDebugEnabled()) log.debug("RDF language used to read Model: {}", lang); - - write(model, entityStream, lang, getUriInfo().getAbsolutePath().toString()); - } - - public UriInfo getUriInfo() - { - return uriInfo; - } - -} diff --git a/src/main/java/com/atomgraph/server/io/ValidatingDatasetProvider.java b/src/main/java/com/atomgraph/server/io/ValidatingDatasetProvider.java deleted file mode 100644 index a026d422..00000000 --- a/src/main/java/com/atomgraph/server/io/ValidatingDatasetProvider.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2019 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.io; - -import com.atomgraph.core.io.DatasetProvider; -import com.atomgraph.processor.util.Validator; -import com.atomgraph.server.exception.SHACLConstraintViolationException; -import com.atomgraph.server.exception.SPINConstraintViolationException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.Iterator; -import java.util.List; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.ext.Providers; -import org.apache.jena.ontology.Ontology; -import org.apache.jena.query.Dataset; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.atomgraph.spinrdf.constraints.ConstraintViolation; -import java.util.Optional; -import org.apache.jena.shacl.ShaclValidator; -import org.apache.jena.shacl.Shapes; -import org.apache.jena.shacl.ValidationReport; - -/** - * Dataset provider that validates read triples in each graph against SPIN constraints in an ontology. - * - * @author Martynas Jusevičius {@literal } - */ -public class ValidatingDatasetProvider extends DatasetProvider -{ - - private static final Logger log = LoggerFactory.getLogger(ValidatingDatasetProvider.class); - - @Context private Providers providers; - - @Inject jakarta.inject.Provider> ontology; - - @Override - public Dataset readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException - { - return process(super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream)); - } - - public Dataset process(Dataset dataset) - { - return validate(dataset); - } - - public Dataset validate(Dataset dataset) - { - if (getOntology().isPresent()) - { - // SPIN validation - Validator validator = new Validator(getOntology().get().getOntModel()); - List cvs = validator.validate(dataset.getDefaultModel()); - if (!cvs.isEmpty()) - { - if (log.isDebugEnabled()) log.debug("SPIN constraint violations: {}", cvs); - throw new SPINConstraintViolationException(cvs, dataset.getDefaultModel()); - } - - // SHACL validation - Shapes shapes = Shapes.parse(getOntology().get().getOntModel().getGraph()); - ValidationReport report = ShaclValidator.get().validate(shapes, dataset.getDefaultModel().getGraph()); - if (!report.conforms()) - { - if (log.isDebugEnabled()) log.debug("SHACL constraint violations: {}", report); - throw new SHACLConstraintViolationException(report, dataset.getDefaultModel()); - } - - Iterator it = dataset.listNames(); - while (it.hasNext()) - { - String graphURI = it.next(); - - // SPIN validation - cvs = validator.validate(dataset.getNamedModel(graphURI)); - if (!cvs.isEmpty()) - { - if (log.isDebugEnabled()) log.debug("SPIN constraint violations: {}", cvs); - throw new SPINConstraintViolationException(cvs, dataset.getNamedModel(graphURI), graphURI); - } - - // SHACL validation - report = ShaclValidator.get().validate(shapes, dataset.getNamedModel(graphURI).getGraph()); - if (!report.conforms()) - { - if (log.isDebugEnabled()) log.debug("SHACL constraint violations: {}", report); - throw new SHACLConstraintViolationException(report, dataset.getNamedModel(graphURI)); - } - } - } - - return dataset; - } - - public Optional getOntology() - { - return ontology.get(); - } - - public Providers getProviders() - { - return providers; - } - -} diff --git a/src/main/java/com/atomgraph/server/io/ValidatingModelProvider.java b/src/main/java/com/atomgraph/server/io/ValidatingModelProvider.java deleted file mode 100644 index 7576635b..00000000 --- a/src/main/java/com/atomgraph/server/io/ValidatingModelProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2015 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.io; - -import org.apache.jena.ontology.Ontology; -import org.apache.jena.rdf.model.Model; -import java.io.IOException; -import java.io.InputStream; -import java.lang.annotation.Annotation; -import java.lang.reflect.Type; -import java.util.List; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.MultivaluedMap; -import jakarta.ws.rs.ext.Providers; -import com.atomgraph.server.exception.SPINConstraintViolationException; -import com.atomgraph.processor.util.Validator; -import com.atomgraph.server.exception.SHACLConstraintViolationException; -import jakarta.inject.Inject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.atomgraph.spinrdf.constraints.ConstraintViolation; -import java.io.OutputStream; -import java.util.Optional; -import org.apache.jena.shacl.ShaclValidator; -import org.apache.jena.shacl.Shapes; -import org.apache.jena.shacl.ValidationReport; - -/** - * Model provider that validates read triples against SPIN constraints in an ontology. - * - * @author Martynas Jusevičius {@literal } - */ -public class ValidatingModelProvider extends BasedModelProvider -{ - private static final Logger log = LoggerFactory.getLogger(ValidatingModelProvider.class); - - @Context private Providers providers; - - @Inject jakarta.inject.Provider> ontology; - - @Override - public Model readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException - { - return processRead(super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream)); - } - - public Model processRead(Model model) - { - return validate(model); - } - - public Model validate(Model model) - { - if (getOntology().isPresent()) - { - // SPIN validation - List cvs = new Validator(getOntology().get().getOntModel()).validate(model); - if (!cvs.isEmpty()) - { - if (log.isDebugEnabled()) log.debug("SPIN constraint violations: {}", cvs); - throw new SPINConstraintViolationException(cvs, model); - } - - // SHACL validation - Shapes shapes = Shapes.parse(getOntology().get().getOntModel().getGraph()); - ValidationReport report = ShaclValidator.get().validate(shapes, model.getGraph()); - if (!report.conforms()) - { - if (log.isDebugEnabled()) log.debug("SHACL constraint violations: {}", report); - throw new SHACLConstraintViolationException(report, model); - } - } - - return model; - } - - @Override - public void writeTo(Model model, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException - { - super.writeTo(processWrite(model), type, genericType, annotations, mediaType, httpHeaders, entityStream); - } - - public Model processWrite(Model model) - { - return model; - } - - public Optional getOntology() - { - return ontology.get(); - } - - public Providers getProviders() - { - return providers; - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/BadGatewayExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/BadGatewayExceptionMapper.java deleted file mode 100644 index 6ffb15fa..00000000 --- a/src/main/java/com/atomgraph/server/mapper/BadGatewayExceptionMapper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2015 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import com.atomgraph.core.exception.BadGatewayException; -import jakarta.inject.Inject; -import org.apache.jena.rdf.model.ResourceFactory; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.Resource; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class BadGatewayExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public BadGatewayExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(BadGatewayException ex) - { - Resource exRes = toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadGateway")); - - return getResponseBuilder(exRes.getModel()). - status(Response.Status.INTERNAL_SERVER_ERROR). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/ConfigurationExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/ConfigurationExceptionMapper.java deleted file mode 100644 index b796607c..00000000 --- a/src/main/java/com/atomgraph/server/mapper/ConfigurationExceptionMapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2017 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import org.apache.jena.rdf.model.ResourceFactory; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import com.atomgraph.core.exception.ConfigurationException; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class ConfigurationExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public ConfigurationExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(ConfigurationException ex) - { - return getResponseBuilder(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). - getModel()). - status(Response.Status.INTERNAL_SERVER_ERROR). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/ExceptionMapperBase.java b/src/main/java/com/atomgraph/server/mapper/ExceptionMapperBase.java deleted file mode 100644 index 90762430..00000000 --- a/src/main/java/com/atomgraph/server/mapper/ExceptionMapperBase.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2014 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.vocabulary.DCTerms; -import org.apache.jena.vocabulary.RDF; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import jakarta.ws.rs.core.Context; -import jakarta.ws.rs.core.Request; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.core.UriInfo; -import jakarta.ws.rs.core.Variant; -import jakarta.ws.rs.ext.Provider; -import com.atomgraph.core.MediaTypes; -import com.atomgraph.core.util.Link; -import com.atomgraph.core.util.ModelUtils; -import com.atomgraph.processor.vocabulary.LDT; -import com.atomgraph.server.vocabulary.HTTP; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.EntityTag; -import jakarta.ws.rs.core.HttpHeaders; -import jakarta.ws.rs.core.MediaType; - -/** - * Abstract base class for ExceptionMappers that build responses with exceptions as RDF resources. - * - * @author Martynas Jusevičius {@literal } - */ -@Provider -abstract public class ExceptionMapperBase -{ - - @Context private Request request; - @Context private UriInfo uriInfo; - - private final MediaTypes mediaTypes; - - @Inject - public ExceptionMapperBase(MediaTypes mediaTypes) - { - this.mediaTypes = mediaTypes; - } - - public Resource toResource(Exception ex, Response.StatusType status, Resource statusResource) - { - if (ex == null) throw new IllegalArgumentException("Exception cannot be null"); - if (status == null) throw new IllegalArgumentException("Response.Status cannot be null"); - - Resource resource = ModelFactory.createDefaultModel().createResource(). - addProperty(RDF.type, HTTP.Response). - addLiteral(HTTP.statusCodeValue, status.getStatusCode()). - addLiteral(HTTP.reasonPhrase, status.getReasonPhrase()); - - if (statusResource != null) resource.addProperty(HTTP.sc, statusResource); - if (ex.getMessage() != null) resource.addLiteral(DCTerms.title, ex.getMessage()); - - return resource; - } - - // TO-DO: set Link headers in a ContainerResponseFilter instead - public Response.ResponseBuilder getResponseBuilder(Model model) - { - Variant variant = getRequest().selectVariant(getVariants(Model.class)); - if (variant == null) variant = new Variant(com.atomgraph.core.MediaType.TEXT_TURTLE_TYPE, (Locale)null, null); // if still not acceptable, default to Turtle - - return new com.atomgraph.core.model.impl.Response(getRequest(), - model, - null, - new EntityTag(Long.toHexString(ModelUtils.hashModel(model))), - variant). - getResponseBuilder(). - header(HttpHeaders.LINK, new Link(getUriInfo().getBaseUri(), LDT.base.getURI(), null)); - } - - /** - * Builds a list of acceptable response variants for a certain class. - * - * @param clazz class - * @return list of variants - */ - public List getVariants(Class clazz) - { - return getVariants(getWritableMediaTypes(clazz)); - } - - /** - * Builds a list of acceptable response variants. - * - * @param mediaTypes - * @return supported variants - */ - public List getVariants(List mediaTypes) - { - return com.atomgraph.core.model.impl.Response.getVariantListBuilder(mediaTypes, getLanguages(), getEncodings()).add().build(); - } - - /** - * Get writable media types for a certain class. - * - * @param clazz class - * @return list of media types - */ - public List getWritableMediaTypes(Class clazz) - { - return getMediaTypes().getWritable(clazz); - } - - public List getLanguages() - { - return new ArrayList<>(); - } - - public List getEncodings() - { - return new ArrayList<>(); - } - - public Request getRequest() - { - return request; - } - - public MediaTypes getMediaTypes() - { - return mediaTypes; - } - - public UriInfo getUriInfo() - { - return uriInfo; - } - -} \ No newline at end of file diff --git a/src/main/java/com/atomgraph/server/mapper/ModelExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/ModelExceptionMapper.java deleted file mode 100644 index 0ef76de8..00000000 --- a/src/main/java/com/atomgraph/server/mapper/ModelExceptionMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.ResourceFactory; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import com.atomgraph.server.exception.ModelException; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class ModelExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public ModelExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(ModelException ex) - { - Resource exception = toResource(ex, Response.Status.BAD_REQUEST, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); - ex.getModel().add(exception.getModel()); - - return getResponseBuilder(ex.getModel()).status(Response.Status.BAD_REQUEST).build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/NotAcceptableExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/NotAcceptableExceptionMapper.java deleted file mode 100644 index df69687e..00000000 --- a/src/main/java/com/atomgraph/server/mapper/NotAcceptableExceptionMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import jakarta.inject.Inject; -import jakarta.ws.rs.NotAcceptableException; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.ResourceFactory; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class NotAcceptableExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public NotAcceptableExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(NotAcceptableException ex) - { - return getResponseBuilder(toResource(ex, ex.getResponse().getStatusInfo(), - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#NotAcceptable")). - getModel()). - status(ex.getResponse().getStatusInfo()). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/NotFoundExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/NotFoundExceptionMapper.java deleted file mode 100644 index 1857f3aa..00000000 --- a/src/main/java/com/atomgraph/server/mapper/NotFoundExceptionMapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import jakarta.inject.Inject; -import jakarta.ws.rs.NotFoundException; -import org.apache.jena.rdf.model.ResourceFactory; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class NotFoundExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public NotFoundExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(NotFoundException ex) - { - return getResponseBuilder(toResource(ex, ex.getResponse().getStatusInfo(), - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#NotFound")). - getModel()). - status(ex.getResponse().getStatusInfo()). - build(); - } - -} \ No newline at end of file diff --git a/src/main/java/com/atomgraph/server/mapper/NotSupportedExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/NotSupportedExceptionMapper.java deleted file mode 100644 index 20e78e04..00000000 --- a/src/main/java/com/atomgraph/server/mapper/NotSupportedExceptionMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2020 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import jakarta.inject.Inject; -import jakarta.ws.rs.NotSupportedException; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.ResourceFactory; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class NotSupportedExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public NotSupportedExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(NotSupportedException ex) - { - return getResponseBuilder(toResource(ex, ex.getResponse().getStatusInfo(), - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#NotAcceptable")). - getModel()). - status(ex.getResponse().getStatusInfo()). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/OntologyExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/OntologyExceptionMapper.java deleted file mode 100644 index 46b36de2..00000000 --- a/src/main/java/com/atomgraph/server/mapper/OntologyExceptionMapper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import com.atomgraph.processor.exception.OntologyException; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.ResourceFactory; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class OntologyExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public OntologyExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(OntologyException ex) - { - return getResponseBuilder(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). - getModel()). - status(Response.Status.INTERNAL_SERVER_ERROR). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/SHACLConstraintViolationExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/SHACLConstraintViolationExceptionMapper.java deleted file mode 100644 index 806bf11f..00000000 --- a/src/main/java/com/atomgraph/server/mapper/SHACLConstraintViolationExceptionMapper.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2021 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import com.atomgraph.server.exception.SHACLConstraintViolationException; -import jakarta.inject.Inject; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.ResourceFactory; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class SHACLConstraintViolationExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public SHACLConstraintViolationExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(SHACLConstraintViolationException ex) - { - Resource exception = toResource(ex, Response.Status.BAD_REQUEST, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); - ex.getModel().add(exception.getModel()); - - ex.getModel().add(ex.getValidationReport().getModel()); - - return getResponseBuilder(ex.getModel()). - status(422). // 422 Unprocessable Entity - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/SPINConstraintViolationExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/SPINConstraintViolationExceptionMapper.java deleted file mode 100644 index 95de66b8..00000000 --- a/src/main/java/com/atomgraph/server/mapper/SPINConstraintViolationExceptionMapper.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2017 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper; - -import com.atomgraph.core.MediaTypes; -import com.atomgraph.server.exception.SPINConstraintViolationException; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.ResIterator; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.rdf.model.ResourceFactory; -import org.apache.jena.vocabulary.RDF; -import com.atomgraph.spinrdf.constraints.SPINConstraints; -import com.atomgraph.spinrdf.vocabulary.SPIN; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class SPINConstraintViolationExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public SPINConstraintViolationExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(SPINConstraintViolationException ex) - { - Resource exception = toResource(ex, Response.Status.BAD_REQUEST, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")); - ex.getModel().add(exception.getModel()); - - SPINConstraints.addConstraintViolationsRDF(ex.getConstraintViolations(), ex.getModel(), true); - ResIterator it = ex.getModel().listSubjectsWithProperty(RDF.type, SPIN.ConstraintViolation); - try - { - while (it.hasNext()) - { - Resource violation = it.next(); - // connect Response to ConstraintViolations - ex.getModel().add(exception, ResourceFactory.createProperty("http://www.w3.org/ns/prov#wasDerivedFrom"), violation); - } - } - finally - { - it.close(); - } - - return getResponseBuilder(ex.getModel()). - status(422). // 422 Unprocessable Entity - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/jena/DatatypeFormatExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/jena/DatatypeFormatExceptionMapper.java deleted file mode 100644 index a9218d14..00000000 --- a/src/main/java/com/atomgraph/server/mapper/jena/DatatypeFormatExceptionMapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper.jena; - -import com.atomgraph.core.MediaTypes; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.datatypes.DatatypeFormatException; -import org.apache.jena.rdf.model.ResourceFactory; -import com.atomgraph.server.mapper.ExceptionMapperBase; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class DatatypeFormatExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public DatatypeFormatExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(DatatypeFormatException ex) - { - return getResponseBuilder(toResource(ex, Response.Status.BAD_REQUEST, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). - getModel()). - status(Response.Status.BAD_REQUEST). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/jena/QueryParseExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/jena/QueryParseExceptionMapper.java deleted file mode 100644 index 4df4212e..00000000 --- a/src/main/java/com/atomgraph/server/mapper/jena/QueryParseExceptionMapper.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.mapper.jena; - -import com.atomgraph.core.MediaTypes; -import org.apache.jena.query.QueryParseException; -import org.apache.jena.rdf.model.ResourceFactory; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import jakarta.ws.rs.ext.Provider; -import com.atomgraph.server.mapper.ExceptionMapperBase; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -@Provider -public class QueryParseExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public QueryParseExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(QueryParseException ex) - { - return getResponseBuilder(toResource(ex, Response.Status.INTERNAL_SERVER_ERROR, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#InternalServerError")). - getModel()). - status(Response.Status.INTERNAL_SERVER_ERROR). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/mapper/jena/RiotExceptionMapper.java b/src/main/java/com/atomgraph/server/mapper/jena/RiotExceptionMapper.java deleted file mode 100644 index 1b1c8f9e..00000000 --- a/src/main/java/com/atomgraph/server/mapper/jena/RiotExceptionMapper.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016 Martynas Jusevičius . - * - * Licensed 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. - */ -package com.atomgraph.server.mapper.jena; - -import com.atomgraph.core.MediaTypes; -import jakarta.ws.rs.core.Response; -import jakarta.ws.rs.ext.ExceptionMapper; -import org.apache.jena.rdf.model.ResourceFactory; -import org.apache.jena.riot.RiotException; -import com.atomgraph.server.mapper.ExceptionMapperBase; -import jakarta.inject.Inject; - -/** - * - * @author Martynas Jusevičius {@literal } - */ -public class RiotExceptionMapper extends ExceptionMapperBase implements ExceptionMapper -{ - - @Inject - public RiotExceptionMapper(MediaTypes mediaTypes) - { - super(mediaTypes); - } - - @Override - public Response toResponse(RiotException ex) - { - return getResponseBuilder(toResource(ex, Response.Status.BAD_REQUEST, - ResourceFactory.createResource("http://www.w3.org/2011/http-statusCodes#BadRequest")). - getModel()). - status(Response.Status.BAD_REQUEST). - build(); - } - -} diff --git a/src/main/java/com/atomgraph/server/vocabulary/HTTP.java b/src/main/java/com/atomgraph/server/vocabulary/HTTP.java deleted file mode 100644 index e9316e1e..00000000 --- a/src/main/java/com/atomgraph/server/vocabulary/HTTP.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2014 Martynas Jusevičius . - * - * Licensed 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. - */ - -package com.atomgraph.server.vocabulary; - -import org.apache.jena.ontology.DatatypeProperty; -import org.apache.jena.ontology.ObjectProperty; -import org.apache.jena.ontology.OntClass; -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; - -/** - * HTTP Vocabulary in RDF - * - * @author Martynas Jusevičius {@literal } - * @see HTTP Vocabulary in RDF 1.0 - */ -public class HTTP -{ - - /**

The RDF model that holds the vocabulary terms

*/ - private static OntModel m_model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null); - - /**

The namespace of the vocabulary as a string

*/ - public static final String NS = "http://www.w3.org/2011/http#"; - - /**

The namespace of the vocabulary as a string

- * @see #NS */ - public static String getURI() - { - return NS; - } - - /**

The namespace of the vocabulary as a resource

*/ - public static final Resource NAMESPACE = m_model.createResource( NS ); - - public static final OntClass Response = m_model.createClass( NS + "Response" ); - - public static final ObjectProperty sc = m_model.createObjectProperty( NS + "sc" ); - - public static final DatatypeProperty statusCodeValue = m_model.createDatatypeProperty( NS + "statusCodeValue" ); - - public static final DatatypeProperty reasonPhrase = m_model.createDatatypeProperty( NS + "reasonPhrase" ); - - public static final DatatypeProperty absoluteURI = m_model.createDatatypeProperty( NS + "absoluteURI" ); - - public static final DatatypeProperty absolutePath = m_model.createDatatypeProperty( NS + "absolutePath" ); - -} diff --git a/src/main/java/com/atomgraph/server/vocabulary/XHV.java b/src/main/java/com/atomgraph/server/vocabulary/XHV.java deleted file mode 100644 index 38361fed..00000000 --- a/src/main/java/com/atomgraph/server/vocabulary/XHV.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - See lda-top/LICENCE (or http://elda.googlecode.com/hg/LICENCE) - for the licence for this software. - - (c) Copyright 2011 Epimorphics Limited - $Id$ -*/ - -/* - (c) Copyright 2010 Epimorphics Limited - [see end of file] - $Id$ -*/ - -package com.atomgraph.server.vocabulary; - -import org.apache.jena.rdf.model.*; - -public class XHV - { - public static final String ns = "http://www.w3.org/1999/xhtml/vocab#"; - - public static final Property first = property( "first" ); - - public static final Property next = property( "next" ); - - public static final Property prev = property( "prev" ); - - public static String getURI() - { return ns; } - - private static Property property( String localName ) - { return ResourceFactory.createProperty( ns + localName ); } - - } - - -/* - (c) Copyright 2010 Epimorphics Limited - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ \ No newline at end of file diff --git a/src/test/java/com/atomgraph/processor/model/impl/TemplateTest.java b/src/test/java/com/atomgraph/processor/model/impl/TemplateTest.java index b017bf38..b34d91ef 100644 --- a/src/test/java/com/atomgraph/processor/model/impl/TemplateTest.java +++ b/src/test/java/com/atomgraph/processor/model/impl/TemplateTest.java @@ -15,7 +15,7 @@ */ package com.atomgraph.processor.model.impl; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.model.Parameter; import com.atomgraph.processor.model.Template; import com.atomgraph.processor.vocabulary.LDT; diff --git a/src/test/java/com/atomgraph/processor/util/SkolemizerTest.java b/src/test/java/com/atomgraph/processor/util/SkolemizerTest.java index de51674b..930a4e1c 100644 --- a/src/test/java/com/atomgraph/processor/util/SkolemizerTest.java +++ b/src/test/java/com/atomgraph/processor/util/SkolemizerTest.java @@ -15,10 +15,9 @@ */ package com.atomgraph.processor.util; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.vocabulary.LDT; import com.atomgraph.processor.vocabulary.SIOC; -import com.atomgraph.server.util.OntologyLoader; import java.net.URI; import java.util.HashMap; import java.util.Map; diff --git a/src/test/java/com/atomgraph/processor/util/TemplateMatcherTest.java b/src/test/java/com/atomgraph/processor/util/TemplateMatcherTest.java index 854d7086..7b4e5da0 100644 --- a/src/test/java/com/atomgraph/processor/util/TemplateMatcherTest.java +++ b/src/test/java/com/atomgraph/processor/util/TemplateMatcherTest.java @@ -15,11 +15,10 @@ */ package com.atomgraph.processor.util; -import com.atomgraph.processor.exception.OntologyException; +import com.atomgraph.server.exception.OntologyException; import com.atomgraph.processor.model.Template; import com.atomgraph.processor.model.impl.TemplateImpl; import com.atomgraph.processor.vocabulary.LDT; -import com.atomgraph.server.util.OntologyLoader; import static junit.framework.Assert.assertEquals; import org.apache.jena.enhanced.BuiltinPersonalities; import org.apache.jena.ontology.OntDocumentManager;