Skip to content

Commit 74ffa78

Browse files
committed
Replaced LinkedDataClient with GraphStoreClient
Server and Web-Client bumps `InstallPackage` and `UnistallPackage` use GSP `PATCH` method to add/remove `owl:imports` triple
1 parent 2b33eb5 commit 74ffa78

23 files changed

+275
-191
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@
130130
<dependency>
131131
<groupId>${project.groupId}</groupId>
132132
<artifactId>server</artifactId>
133-
<version>4.1.12</version>
133+
<version>4.1.13-SNAPSHOT</version>
134134
</dependency>
135135
<dependency>
136136
<groupId>${project.groupId}</groupId>
137137
<artifactId>client</artifactId>
138-
<version>4.2.7</version>
138+
<version>4.2.8-SNAPSHOT</version>
139139
<classifier>classes</classifier>
140140
</dependency>
141141
<dependency>
142142
<groupId>${project.groupId}</groupId>
143143
<artifactId>client</artifactId>
144-
<version>4.2.7</version>
144+
<version>4.2.8-SNAPSHOT</version>
145145
<type>war</type>
146146
</dependency>
147147
<!-- required by jsonld-java - version same as Jersey's HTTP Client -->

src/main/java/com/atomgraph/linkeddatahub/Application.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import com.atomgraph.linkeddatahub.writer.factory.xslt.XsltExecutableSupplier;
6868
import com.atomgraph.linkeddatahub.writer.factory.XsltExecutableSupplierFactory;
6969
import com.atomgraph.client.util.XsltResolver;
70-
import com.atomgraph.linkeddatahub.client.LinkedDataClient;
70+
import com.atomgraph.linkeddatahub.client.GraphStoreClient;
7171
import com.atomgraph.linkeddatahub.client.filter.ClientUriRewriteFilter;
7272
import com.atomgraph.linkeddatahub.client.filter.grddl.YouTubeGRDDLFilter;
7373
import com.atomgraph.linkeddatahub.imports.ImportExecutor;
@@ -732,7 +732,7 @@ public Application(final ServletConfig servletConfig, final MediaTypes mediaType
732732

733733
// TO-DO: config property for cacheModelLoads
734734
endUserOntModelSpecs = new HashMap<>();
735-
dataManager = new DataManagerImpl(locationMapper, new HashMap<>(), LinkedDataClient.create(client, mediaTypes), cacheModelLoads, preemptiveAuth, resolvingUncached);
735+
dataManager = new DataManagerImpl(locationMapper, new HashMap<>(), GraphStoreClient.create(client, mediaTypes), cacheModelLoads, preemptiveAuth, resolvingUncached);
736736
ontModelSpec = OntModelSpec.OWL_MEM_RDFS_INF;
737737
ontModelSpec.setImportModelGetter(dataManager);
738738
OntDocumentManager.getInstance().setFileManager((FileManager)dataManager);
@@ -807,7 +807,7 @@ protected PasswordAuthentication getPasswordAuthentication()
807807

808808
xsltComp = xsltProc.newXsltCompiler();
809809
xsltComp.setParameter(new QName("ldh", LDH.base.getNameSpace(), LDH.base.getLocalName()), new XdmAtomicValue(baseURI));
810-
xsltComp.setURIResolver(new XsltResolver(LocationMapper.get(), new HashMap<>(), LinkedDataClient.create(client, mediaTypes), false, false, true)); // default Xerces parser does not support HTTPS
810+
xsltComp.setURIResolver(new XsltResolver(LocationMapper.get(), new HashMap<>(), GraphStoreClient.create(client, mediaTypes), false, false, true)); // default Xerces parser does not support HTTPS
811811
xsltExec = xsltComp.compile(stylesheet);
812812
}
813813
catch (FileNotFoundException ex)
@@ -1199,7 +1199,7 @@ public void handleAuthorizationCreated(AuthorizationCreated event) throws Messag
11991199
{
12001200
Resource agent = auth.getPropertyResourceValue(ACL.agent);
12011201
// make sure the client has WebID delegation enabled, otherwise it will not have authenticated access
1202-
Model agentModel = event.getLinkedDataClient().getModel(agent.getURI());
1202+
Model agentModel = event.getGraphStoreClient().getModel(agent.getURI());
12031203
if (!agentModel.containsResource(agent)) throw new IllegalStateException("Could not load agent's <" + agent.getURI() + "> description");
12041204
agent = agentModel.getResource(agent.getURI());
12051205

@@ -1420,11 +1420,11 @@ public Map<Integer, Resource> getLengthMap(Map<URI, Resource> apps)
14201420
* @param service current SPARQL service
14211421
* @param adminService current admin SPARQL service
14221422
* @param baseURI application's base URI
1423-
* @param ldc Linked Data client
1423+
* @param gsc Graph Store client
14241424
*/
1425-
public void submitImport(CSVImport csvImport, com.atomgraph.linkeddatahub.apps.model.Application app, Service service, Service adminService, String baseURI, LinkedDataClient ldc)
1425+
public void submitImport(CSVImport csvImport, com.atomgraph.linkeddatahub.apps.model.Application app, Service service, Service adminService, String baseURI, GraphStoreClient gsc)
14261426
{
1427-
new ImportExecutor(importThreadPool).start(service, adminService, baseURI, ldc, csvImport);
1427+
new ImportExecutor(importThreadPool).start(service, adminService, baseURI, gsc, csvImport);
14281428
}
14291429

14301430
/**
@@ -1435,11 +1435,11 @@ public void submitImport(CSVImport csvImport, com.atomgraph.linkeddatahub.apps.m
14351435
* @param service current SPARQL service
14361436
* @param adminService current admin SPARQL service
14371437
* @param baseURI application's base URI
1438-
* @param ldc Linked Data client
1438+
* @param gsc Graph Store client
14391439
*/
1440-
public void submitImport(RDFImport rdfImport, com.atomgraph.linkeddatahub.apps.model.Application app, Service service, Service adminService, String baseURI, LinkedDataClient ldc)
1440+
public void submitImport(RDFImport rdfImport, com.atomgraph.linkeddatahub.apps.model.Application app, Service service, Service adminService, String baseURI, GraphStoreClient gsc)
14411441
{
1442-
new ImportExecutor(importThreadPool).start(service, adminService, baseURI, ldc, rdfImport);
1442+
new ImportExecutor(importThreadPool).start(service, adminService, baseURI, gsc, rdfImport);
14431443
}
14441444

14451445
/**
@@ -1716,8 +1716,7 @@ public OntModelSpec getOntModelSpec(EndUserApplication app)
17161716
{
17171717
OntModelSpec appOntModelSpec = new OntModelSpec(OntModelSpec.OWL_MEM_RDFS_INF);
17181718
appOntModelSpec.setDocumentManager(new OntDocumentManager());
1719-
appOntModelSpec.getDocumentManager().setFileManager(
1720-
new DataManagerImpl(LocationMapper.get(), new HashMap<>(), LinkedDataClient.create(getClient(), getMediaTypes()), true, isPreemptiveAuth(), isResolvingUncached()));
1719+
appOntModelSpec.getDocumentManager().setFileManager(new DataManagerImpl(LocationMapper.get(), new HashMap<>(), GraphStoreClient.create(getClient(), getMediaTypes()), true, isPreemptiveAuth(), isResolvingUncached()));
17211720

17221721
getEndUserOntModelSpecs().put(app.getURI(), appOntModelSpec);
17231722
}

src/main/java/com/atomgraph/linkeddatahub/client/LinkedDataClient.java renamed to src/main/java/com/atomgraph/linkeddatahub/client/GraphStoreClient.java

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,27 @@
2626
import java.net.URI;
2727
import jakarta.ws.rs.client.Client;
2828
import jakarta.ws.rs.client.Entity;
29-
import static jakarta.ws.rs.client.Entity.entity;
3029
import jakarta.ws.rs.client.WebTarget;
3130
import jakarta.ws.rs.core.HttpHeaders;
3231
import jakarta.ws.rs.core.MediaType;
3332
import jakarta.ws.rs.core.MultivaluedMap;
3433
import jakarta.ws.rs.core.Response;
3534
import org.apache.jena.rdf.model.Model;
35+
import org.apache.jena.update.UpdateRequest;
3636
import org.slf4j.Logger;
3737
import org.slf4j.LoggerFactory;
3838

3939
/**
40-
* Linked Data client that supports WebID and OIDC delegation.
40+
* Graph Store client that supports WebID and OIDC delegation.
4141
* Sends <code>User-Agent</code> header to impersonate a web browser.
4242
* Respects <code>Retry-After</code> response headers.
4343
*
4444
* @author {@literal Martynas Jusevičius <martynas@atomgraph.com>}
4545
*/
46-
public class LinkedDataClient extends com.atomgraph.core.client.LinkedDataClient
46+
public class GraphStoreClient extends com.atomgraph.core.client.GraphStoreClient
4747
{
4848

49-
private static final Logger log = LoggerFactory.getLogger(LinkedDataClient.class);
49+
private static final Logger log = LoggerFactory.getLogger(GraphStoreClient.class);
5050

5151
/**
5252
* <samp>User-Agent</samp> request header value used by this HTTP client.
@@ -57,29 +57,42 @@ public class LinkedDataClient extends com.atomgraph.core.client.LinkedDataClient
5757
private AgentContext agentContext;
5858
private long defaultDelayMillis;
5959
private final int maxRetryCount;
60+
61+
/**
62+
* Constructs Graph Store Protocol client.
63+
*
64+
* @param client HTTP client
65+
* @param mediaTypes registry of supported readable/writable media types
66+
*/
67+
protected GraphStoreClient(Client client, MediaTypes mediaTypes)
68+
{
69+
this(client, mediaTypes, null);
70+
}
6071

6172
/**
62-
* Constructs Linked Data client from HTTP client and media types.
73+
* Constructs Graph Store Protocol client.
6374
*
6475
* @param client HTTP client
6576
* @param mediaTypes registry of supported readable/writable media types
77+
* @param endpoint endpoint URL (optional)
6678
*/
67-
protected LinkedDataClient(Client client, MediaTypes mediaTypes)
79+
protected GraphStoreClient(Client client, MediaTypes mediaTypes, URI endpoint)
6880
{
69-
this(client, mediaTypes, 5000L, 3);
81+
this(client, mediaTypes, endpoint, 5000L, 3);
7082
}
7183

7284
/**
73-
* Constructs Linked Data client from HTTP client and media types.
85+
* Constructs Graph Store Protocol client.
7486
*
7587
* @param client HTTP client
7688
* @param mediaTypes registry of supported readable/writable media types
89+
* @param endpoint endpoint URL (optional)
7790
* @param defaultDelayMillis default period the client waits before retrying the request
7891
* @param maxRetryCount maximum number of request retries
7992
*/
80-
protected LinkedDataClient(Client client, MediaTypes mediaTypes, long defaultDelayMillis, int maxRetryCount)
93+
protected GraphStoreClient(Client client, MediaTypes mediaTypes, URI endpoint, long defaultDelayMillis, int maxRetryCount)
8194
{
82-
super(client, mediaTypes);
95+
super(client, mediaTypes, endpoint);
8396
this.defaultDelayMillis = defaultDelayMillis;
8497
this.maxRetryCount = maxRetryCount;
8598
}
@@ -89,25 +102,39 @@ protected LinkedDataClient(Client client, MediaTypes mediaTypes, long defaultDel
89102
*
90103
* @param client HTTP client
91104
* @param mediaTypes registry of supported readable/writable media types
105+
* @param endpoint endpoint URL (optional)
92106
* @param defaultDelayMillis default period the client waits before retrying the request
93107
* @param maxRetryCount max request retry count
94-
* @return Linked Data client instance
108+
* @return Graph Store client instance
95109
*/
96-
public static LinkedDataClient create(Client client, MediaTypes mediaTypes, long defaultDelayMillis, int maxRetryCount)
110+
public static GraphStoreClient create(Client client, MediaTypes mediaTypes, URI endpoint, long defaultDelayMillis, int maxRetryCount)
97111
{
98-
return new LinkedDataClient(client, mediaTypes, defaultDelayMillis, maxRetryCount);
112+
return new GraphStoreClient(client, mediaTypes, endpoint, defaultDelayMillis, maxRetryCount);
99113
}
100114

101115
/**
102116
* Factory method that accepts HTTP client and media types.
103117
*
104118
* @param client HTTP client
105119
* @param mediaTypes registry of supported readable/writable media types
106-
* @return Linked Data client instance
120+
* @param endpoint endpoint URL (optional)
121+
* @return Graph Store client instance
122+
*/
123+
public static GraphStoreClient create(Client client, MediaTypes mediaTypes, URI endpoint)
124+
{
125+
return new GraphStoreClient(client, mediaTypes, endpoint);
126+
}
127+
128+
/**
129+
* Factory method that accepts HTTP client and media types.
130+
*
131+
* @param client HTTP client
132+
* @param mediaTypes registry of supported readable/writable media types
133+
* @return Graph Store client instance
107134
*/
108-
public static LinkedDataClient create(Client client, MediaTypes mediaTypes)
135+
public static GraphStoreClient create(Client client, MediaTypes mediaTypes)
109136
{
110-
return new LinkedDataClient(client, mediaTypes);
137+
return new GraphStoreClient(client, mediaTypes);
111138
}
112139

113140
/**
@@ -118,7 +145,7 @@ public static LinkedDataClient create(Client client, MediaTypes mediaTypes)
118145
* @param agentContext agent's auth context
119146
* @return client instance
120147
*/
121-
public LinkedDataClient delegation(URI baseURI, AgentContext agentContext)
148+
public GraphStoreClient delegation(URI baseURI, AgentContext agentContext)
122149
{
123150
this.baseURI = baseURI;
124151
this.agentContext = agentContext;
@@ -167,15 +194,15 @@ public Response get(URI uri, jakarta.ws.rs.core.MediaType[] acceptedTypes)
167194
}
168195

169196
@Override
170-
public Response post(URI uri, MediaType[] acceptedTypes, Entity entity)
197+
public Response post(URI uri, Entity entity, MediaType[] acceptedTypes)
171198
{
172199
WebTarget webTarget = getWebTarget(uri);
173200
return new RetryAfterHelper(getDefaultDelayMillis(), getMaxRetryCount()).invokeWithRetry(() ->
174201
webTarget.request(acceptedTypes).post(entity));
175202
}
176203

177204
@Override
178-
public Response put(URI uri, MediaType[] acceptedTypes, Entity entity)
205+
public Response put(URI uri, Entity entity, MediaType[] acceptedTypes)
179206
{
180207
WebTarget webTarget = getWebTarget(uri);
181208
return new RetryAfterHelper(getDefaultDelayMillis(), getMaxRetryCount()).invokeWithRetry(() ->
@@ -206,10 +233,28 @@ public Response delete(URI uri)
206233
return new RetryAfterHelper(getDefaultDelayMillis(), getMaxRetryCount()).invokeWithRetry(() ->
207234
webTarget.request().delete());
208235
}
209-
236+
237+
/**
238+
* Sends a PATCH request with SPARQL UPDATE to the specified graph URI.
239+
*
240+
* @param uri the target graph URI
241+
* @param updateRequest the SPARQL UPDATE request
242+
* @return the HTTP response
243+
*/
244+
public Response patch(URI uri, UpdateRequest updateRequest)
245+
{
246+
if (updateRequest == null) throw new IllegalArgumentException("UpdateRequest cannot be null");
247+
248+
WebTarget webTarget = getWebTarget(uri);
249+
String updateString = updateRequest.toString();
250+
251+
return new RetryAfterHelper(getDefaultDelayMillis(), getMaxRetryCount()).invokeWithRetry(() ->
252+
webTarget.request().method("PATCH", Entity.entity(updateString, "application/sparql-update")));
253+
}
254+
210255
/**
211256
* Returns the application's base URI.
212-
*
257+
*
213258
* @return base URI
214259
*/
215260
public URI getBaseURI()

0 commit comments

Comments
 (0)