2626import java .net .URI ;
2727import jakarta .ws .rs .client .Client ;
2828import jakarta .ws .rs .client .Entity ;
29- import static jakarta .ws .rs .client .Entity .entity ;
3029import jakarta .ws .rs .client .WebTarget ;
3130import jakarta .ws .rs .core .HttpHeaders ;
3231import jakarta .ws .rs .core .MediaType ;
3332import jakarta .ws .rs .core .MultivaluedMap ;
3433import jakarta .ws .rs .core .Response ;
3534import org .apache .jena .rdf .model .Model ;
35+ import org .apache .jena .update .UpdateRequest ;
3636import org .slf4j .Logger ;
3737import 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