Skip to content

Commit

Permalink
Reusable server code split up and moved to the com.atomgraph.server
Browse files Browse the repository at this point in the history
… artifact (which `com.atomgraph.processor` now depends on)

ResourceBase constructor catches `QueryParseException` and wraps it into `OntologyException`
Removed unused classes
  • Loading branch information
namedgraph committed Jul 9, 2023
1 parent e6e1b15 commit 9bc7fd9
Show file tree
Hide file tree
Showing 46 changed files with 72 additions and 1,677 deletions.
16 changes: 3 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<packaging>${packaging.type}</packaging>

<name>AtomGraph Processor</name>
<description>Ontology-driven Linked Data processor and server for SPARQL backends</description>
<description>Ontology-driven Linked Data processor</description>
<url>https://github.com/AtomGraph/Processor</url>
<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -78,18 +78,8 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>twirl</artifactId>
<version>1.0.32</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-shacl</artifactId>
<version>4.7.0</version>
<artifactId>server</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -54,7 +54,7 @@
* @see <a href="http://www.w3.org/TR/sparql11-query/#solutionModifiers">15 Solution Sequences and Modifiers</a>
*/
@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);

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -42,7 +42,7 @@
* @see com.atomgraph.core.model.GraphStore
* @see <a href="http://www.w3.org/TR/sparql11-http-rdf-update/#direct-graph-identification">4.1 Direct Graph Identification</a>
*/
public class Item extends ResourceBase // TO-DO: extends GraphStore
public class Item extends ResourceBase
{

private static final Logger log = LoggerFactory.getLogger(Item.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9bc7fd9

Please sign in to comment.