Skip to content

Commit

Permalink
GraphStoreProvider/SPARQLClientProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Martynas committed Oct 12, 2016
1 parent c0110d4 commit ada8bbf
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 75 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/atomgraph/core/Application.java
Expand Up @@ -35,9 +35,14 @@
import com.atomgraph.core.provider.ApplicationProvider;
import com.atomgraph.core.provider.ClientProvider;
import com.atomgraph.core.provider.DatasetProvider;
import com.atomgraph.core.provider.GraphStoreClientProvider;
import com.atomgraph.core.provider.GraphStoreProvider;
import com.atomgraph.core.provider.MediaTypesProvider;
import com.atomgraph.core.provider.SPARQLClientProvider;
import com.atomgraph.core.provider.SPARQLEndpointProvider;
import com.atomgraph.core.riot.RDFLanguages;
import com.atomgraph.core.riot.lang.RDFPostReaderFactory;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -73,8 +78,11 @@ public Application(@Context ServletConfig servletConfig)
// add RDF/POST serialization
RDFLanguages.register(RDFLanguages.RDFPOST);
RDFParserRegistry.registerLangTriples(RDFLanguages.RDFPOST, new RDFPostReaderFactory());
//IO_Jena.registerForModelRead(RDFLanguages.strLangRDFPOST, RDFPostReaderAdapter.class);

}

@PostConstruct
public void init()
{
classes.add(QueriedResourceBase.class); // handles all
classes.add(SPARQLEndpointProxyBase.class); // handles /sparql queries
classes.add(GraphStoreProxyBase.class); // handles /service requests
Expand All @@ -85,7 +93,11 @@ public Application(@Context ServletConfig servletConfig)
singletons.add(new QueryParamProvider());
singletons.add(new UpdateRequestReader());
singletons.add(new DataManagerProvider());
singletons.add(new ApplicationProvider(servletConfig));
singletons.add(new ApplicationProvider(getServletConfig()));
singletons.add(new SPARQLClientProvider(getServletConfig()));
singletons.add(new SPARQLEndpointProvider(getServletConfig()));
singletons.add(new GraphStoreClientProvider());
singletons.add(new GraphStoreProvider(getServletConfig()));
singletons.add(new ClientProvider());
singletons.add(new MediaTypesProvider());
singletons.add(new ClientExceptionMapper());
Expand Down Expand Up @@ -135,7 +147,7 @@ public boolean getBooleanParam(ServletConfig servletConfig, Property property)

boolean value = false;
if (servletConfig.getInitParameter(property.getURI()) != null)
value = Boolean.parseBoolean(servletConfig.getInitParameter(property.getURI()).toString());
value = Boolean.parseBoolean(servletConfig.getInitParameter(property.getURI()));
return value;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/atomgraph/core/model/Service.java
Expand Up @@ -27,11 +27,11 @@ public interface Service

org.apache.jena.rdf.model.Resource getSPARQLEndpoint();

WebResource getSPARQLEndpointOrigin(Client client);
// WebResource getSPARQLEndpointOrigin(Client client);

org.apache.jena.rdf.model.Resource getGraphStore();

WebResource getGraphStoreOrigin(Client client);
// WebResource getGraphStoreOrigin(Client client);

String getAuthUser();

Expand Down
Expand Up @@ -29,6 +29,7 @@ public class ApplicationImpl implements Application

public ApplicationImpl(Service service)
{
if (service == null) throw new IllegalArgumentException("Service cannot be null");
this.service = service;
}

Expand Down
Expand Up @@ -24,9 +24,7 @@
import javax.ws.rs.core.Request;
import com.atomgraph.core.MediaTypes;
import com.atomgraph.core.client.GraphStoreClient;
import com.atomgraph.core.model.Application;
import com.atomgraph.core.model.GraphStoreProxy;
import com.sun.jersey.api.client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,25 +39,21 @@ public class GraphStoreProxyBase extends GraphStoreBase implements GraphStorePro
{
private static final Logger log = LoggerFactory.getLogger(GraphStoreProxyBase.class);

//private final GraphStoreOrigin origin;
private final GraphStoreClient graphStoreClient;
//private final javax.ws.rs.core.MediaType[] readableMediaTypes;

/**
* Constructs Graph Store proxy from request metadata and origin.
*
* @param request request
* @param servletConfig servlet config
* @param mediaTypes supported media types
* @param client HTTP client
* @param application LDT application
* @param graphStoreClient graph store client
*/
public GraphStoreProxyBase(@Context Request request, @Context ServletConfig servletConfig, @Context MediaTypes mediaTypes,
@Context Client client, @Context Application application)
@Context GraphStoreClient graphStoreClient)
{
super(request, servletConfig, mediaTypes);
if (application == null) throw new IllegalArgumentException("Application cannot be null");
graphStoreClient = GraphStoreClient.create(application.getService().getSPARQLEndpointOrigin(client), mediaTypes);
this.graphStoreClient = graphStoreClient;
}

@Override
Expand Down
Expand Up @@ -31,9 +31,7 @@
import com.atomgraph.core.MediaTypes;
import com.atomgraph.core.client.SPARQLClient;
import com.atomgraph.core.exception.NotFoundException;
import com.atomgraph.core.model.Application;
import com.atomgraph.core.model.QueriedResource;
import com.sun.jersey.api.client.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -49,8 +47,8 @@ public class QueriedResourceBase extends ResourceBase implements QueriedResource
{
private static final Logger log = LoggerFactory.getLogger(QueriedResourceBase.class);

private final Client client;
private final Application application;
//private final Client client;
//private final Application application;
private final SPARQLClient sparqlClient;

/**
Expand All @@ -60,21 +58,20 @@ public class QueriedResourceBase extends ResourceBase implements QueriedResource
* @param uriInfo URI information of the request
* @param request current request object
* @param servletConfig webapp context
* @param application LDT application
* @param client
* @param mediaTypes supported media types
* @param sparqlClient SPARQL client
* @see <a href="http://docs.oracle.com/javaee/6/api/javax/ws/rs/core/UriInfo.html">JAX-RS UriInfo</a>
* @see <a href="http://docs.oracle.com/javaee/7/api/javax/servlet/ServletContext.html">ServletContext</a>
* @see <a href="https://jersey.java.net/nonav/apidocs/1.16/jersey/com/sun/jersey/api/core/ResourceContext.html">Jersey ResourceContext</a>
*/
public QueriedResourceBase(@Context UriInfo uriInfo, @Context Request request, @Context ServletConfig servletConfig, @Context MediaTypes mediaTypes,
@Context Client client, @Context Application application)
@Context SPARQLClient sparqlClient)
{
super(uriInfo, request, servletConfig, mediaTypes);
if (application == null) throw new IllegalArgumentException("Application cannot be null");
this.client = client;
this.application = application;
this.sparqlClient = SPARQLClient.create(application.getService().getSPARQLEndpointOrigin(client));
if (sparqlClient == null) throw new IllegalArgumentException("SPARQLClient cannot be null");
//this.client = client;
//this.application = application;
this.sparqlClient = sparqlClient;
}

/**
Expand Down Expand Up @@ -174,19 +171,23 @@ public Query getQuery(URI uri)
return QueryFactory.create("DESCRIBE <" + uri.toString() + ">");
}

/*
public Client getClient()
{
return client;
}
*/

public SPARQLClient getSPARQLClient()
{
return sparqlClient;
}

/*
public Application getApplication()
{
return application;
}

*/

}
Expand Up @@ -46,7 +46,7 @@ public class SPARQLEndpointProxyBase extends SPARQLEndpointBase implements SPARQ
{
private static final Logger log = LoggerFactory.getLogger(SPARQLEndpointProxyBase.class);

private final Application application;
//private final Application application;
private final SPARQLClient sparqlClient;

/**
Expand All @@ -59,15 +59,11 @@ public class SPARQLEndpointProxyBase extends SPARQLEndpointBase implements SPARQ
* @param application LDT application
*/
public SPARQLEndpointProxyBase(@Context Request request, @Context ServletConfig servletConfig, @Context MediaTypes mediaTypes,
@Context Client client, @Context Application application)
@Context SPARQLClient sparqlClient)
{
super(request, servletConfig, mediaTypes);
if (application == null) throw new IllegalArgumentException("Application cannot be null");
this.application = application;

Integer maxGetRequestSize = getMaxGetRequestSize(servletConfig, A.maxGetRequestSize);
if (maxGetRequestSize != null) sparqlClient = SPARQLClient.create(application.getService().getSPARQLEndpointOrigin(client), mediaTypes, maxGetRequestSize);
else sparqlClient = SPARQLClient.create(application.getService().getSPARQLEndpointOrigin(client), mediaTypes);
if (sparqlClient == null) throw new IllegalArgumentException("Application cannot be null");
this.sparqlClient = sparqlClient;
}

@Override
Expand All @@ -76,10 +72,12 @@ public SPARQLClient getSPARQLClient()
return sparqlClient;
}

/*
public Application getApplication()
{
return application;
}
*/

@Override
public Model loadModel(Query query)
Expand Down Expand Up @@ -113,15 +111,4 @@ public void update(UpdateRequest updateRequest)
getSPARQLClient().update(updateRequest);
}

public final Integer getMaxGetRequestSize(ServletConfig servletConfig, DatatypeProperty property)
{
if (servletConfig == null) throw new IllegalArgumentException("ServletConfig cannot be null");
if (property == null) throw new IllegalArgumentException("Property cannot be null");

Object sizeValue = servletConfig.getInitParameter(property.getURI());
if (sizeValue != null) return Integer.parseInt(sizeValue.toString());

return null;
}

}
29 changes: 0 additions & 29 deletions src/main/java/com/atomgraph/core/model/impl/ServiceImpl.java
Expand Up @@ -16,9 +16,6 @@
package com.atomgraph.core.model.impl;

import com.atomgraph.core.model.Service;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import org.apache.jena.rdf.model.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -56,39 +53,13 @@ public Resource getSPARQLEndpoint()
{
return sparqlEndpoint;
}

@Override
public WebResource getSPARQLEndpointOrigin(Client client)
{
if (client == null) throw new IllegalArgumentException("Client must be not null");

WebResource origin = client.resource(getSPARQLEndpoint().getURI());

if (getAuthUser() != null && getAuthPwd() != null)
origin.addFilter(new HTTPBasicAuthFilter(getAuthUser(), getAuthPwd()));

return origin;
}

@Override
public Resource getGraphStore()
{
return graphStore;
}

@Override
public WebResource getGraphStoreOrigin(Client client)
{
if (client == null) throw new IllegalArgumentException("Client must be not null");

WebResource origin = client.resource(getGraphStore().getURI());

if (getAuthUser() != null && getAuthPwd() != null)
origin.addFilter(new HTTPBasicAuthFilter(getAuthUser(), getAuthPwd()));

return origin;
}

@Override
public String getAuthUser()
{
Expand Down

0 comments on commit ada8bbf

Please sign in to comment.