@@ -165,16 +165,30 @@ protected Set<Class<?>> registerCustomSerdeScan() {
165165 */
166166 public ElideResponse get (String path , MultivaluedMap <String , String > queryParams ,
167167 User opaqueUser , String apiVersion ) {
168- return handleRequest (true , opaqueUser , dataStore ::beginReadTransaction , (tx , user ) -> {
168+ return get (path , queryParams , opaqueUser , apiVersion , UUID .randomUUID ());
169+ }
170+
171+ /**
172+ * Handle GET.
173+ *
174+ * @param path the path
175+ * @param queryParams the query params
176+ * @param opaqueUser the opaque user
177+ * @param apiVersion the API version
178+ * @param requestId the request ID
179+ * @return Elide response object
180+ */
181+ public ElideResponse get (String path , MultivaluedMap <String , String > queryParams ,
182+ User opaqueUser , String apiVersion , UUID requestId ) {
183+ return handleRequest (true , opaqueUser , dataStore ::beginReadTransaction , requestId , (tx , user ) -> {
169184 JsonApiDocument jsonApiDoc = new JsonApiDocument ();
170185 RequestScope requestScope = new RequestScope (path , apiVersion , jsonApiDoc ,
171- tx , user , queryParams , elideSettings );
186+ tx , user , queryParams , requestId , elideSettings );
172187 requestScope .setEntityProjection (new EntityProjectionMaker (elideSettings .getDictionary (),
173188 requestScope ).parsePath (path ));
174189 BaseVisitor visitor = new GetVisitor (requestScope );
175190 return visit (path , requestScope , visitor );
176191 });
177-
178192 }
179193
180194 /**
@@ -183,13 +197,28 @@ public ElideResponse get(String path, MultivaluedMap<String, String> queryParams
183197 * @param path the path
184198 * @param jsonApiDocument the json api document
185199 * @param opaqueUser the opaque user
200+ * @param apiVersion the API version
186201 * @return Elide response object
187202 */
188203 public ElideResponse post (String path , String jsonApiDocument , User opaqueUser , String apiVersion ) {
189- return handleRequest (false , opaqueUser , dataStore ::beginTransaction , (tx , user ) -> {
204+ return post (path , jsonApiDocument , opaqueUser , apiVersion , UUID .randomUUID ());
205+ }
206+
207+ /**
208+ * Handle POST.
209+ *
210+ * @param path the path
211+ * @param jsonApiDocument the json api document
212+ * @param opaqueUser the opaque user
213+ * @param apiVersion the API version
214+ * @param requestId the request ID
215+ * @return Elide response object
216+ */
217+ public ElideResponse post (String path , String jsonApiDocument , User opaqueUser , String apiVersion , UUID requestId ) {
218+ return handleRequest (false , opaqueUser , dataStore ::beginTransaction , requestId , (tx , user ) -> {
190219 JsonApiDocument jsonApiDoc = mapper .readJsonApiDocument (jsonApiDocument );
191220 RequestScope requestScope = new RequestScope (path , apiVersion ,
192- jsonApiDoc , tx , user , null , elideSettings );
221+ jsonApiDoc , tx , user , null , requestId , elideSettings );
193222 requestScope .setEntityProjection (new EntityProjectionMaker (elideSettings .getDictionary (),
194223 requestScope ).parsePath (path ));
195224 BaseVisitor visitor = new PostVisitor (requestScope );
@@ -205,15 +234,36 @@ public ElideResponse post(String path, String jsonApiDocument, User opaqueUser,
205234 * @param path the path
206235 * @param jsonApiDocument the json api document
207236 * @param opaqueUser the opaque user
237+ * @param apiVersion the API version
238+ * @return Elide response object
239+ */
240+ public ElideResponse patch (String contentType , String accept ,
241+ String path , String jsonApiDocument ,
242+ User opaqueUser , String apiVersion ) {
243+ return patch (contentType , accept , path , jsonApiDocument , opaqueUser , apiVersion , UUID .randomUUID ());
244+ }
245+
246+ /**
247+ * Handle PATCH.
248+ *
249+ * @param contentType the content type
250+ * @param accept the accept
251+ * @param path the path
252+ * @param jsonApiDocument the json api document
253+ * @param opaqueUser the opaque user
254+ * @param apiVersion the API version
255+ * @param requestId the request ID
208256 * @return Elide response object
209257 */
210258 public ElideResponse patch (String contentType , String accept ,
211- String path , String jsonApiDocument , User opaqueUser , String apiVersion ) {
259+ String path , String jsonApiDocument ,
260+ User opaqueUser , String apiVersion , UUID requestId ) {
212261
213262 Handler <DataStoreTransaction , User , HandlerResult > handler ;
214263 if (JsonApiPatch .isPatchExtension (contentType ) && JsonApiPatch .isPatchExtension (accept )) {
215264 handler = (tx , user ) -> {
216- PatchRequestScope requestScope = new PatchRequestScope (path , apiVersion , tx , user , elideSettings );
265+ PatchRequestScope requestScope = new PatchRequestScope (path , apiVersion , tx ,
266+ user , requestId , elideSettings );
217267 try {
218268 Supplier <Pair <Integer , JsonNode >> responder =
219269 JsonApiPatch .processJsonPatch (dataStore , path , jsonApiDocument , requestScope );
@@ -226,15 +276,29 @@ public ElideResponse patch(String contentType, String accept,
226276 handler = (tx , user ) -> {
227277 JsonApiDocument jsonApiDoc = mapper .readJsonApiDocument (jsonApiDocument );
228278 RequestScope requestScope = new RequestScope (path , apiVersion , jsonApiDoc ,
229- tx , user , null , elideSettings );
279+ tx , user , null , requestId , elideSettings );
230280 requestScope .setEntityProjection (new EntityProjectionMaker (elideSettings .getDictionary (),
231281 requestScope ).parsePath (path ));
232282 BaseVisitor visitor = new PatchVisitor (requestScope );
233283 return visit (path , requestScope , visitor );
234284 };
235285 }
236286
237- return handleRequest (false , opaqueUser , dataStore ::beginTransaction , handler );
287+ return handleRequest (false , opaqueUser , dataStore ::beginTransaction , requestId , handler );
288+ }
289+
290+ /**
291+ * Handle DELETE.
292+ *
293+ * @param path the path
294+ * @param jsonApiDocument the json api document
295+ * @param opaqueUser the opaque user
296+ * @param apiVersion the API version
297+ * @return Elide response object
298+ */
299+ public ElideResponse delete (String path , String jsonApiDocument ,
300+ User opaqueUser , String apiVersion ) {
301+ return delete (path , jsonApiDocument , opaqueUser , apiVersion , UUID .randomUUID ());
238302 }
239303
240304 /**
@@ -243,15 +307,18 @@ public ElideResponse patch(String contentType, String accept,
243307 * @param path the path
244308 * @param jsonApiDocument the json api document
245309 * @param opaqueUser the opaque user
310+ * @param apiVersion the API version
311+ * @param requestId the request ID
246312 * @return Elide response object
247313 */
248- public ElideResponse delete (String path , String jsonApiDocument , User opaqueUser , String apiVersion ) {
249- return handleRequest (false , opaqueUser , dataStore ::beginTransaction , (tx , user ) -> {
314+ public ElideResponse delete (String path , String jsonApiDocument ,
315+ User opaqueUser , String apiVersion , UUID requestId ) {
316+ return handleRequest (false , opaqueUser , dataStore ::beginTransaction , requestId , (tx , user ) -> {
250317 JsonApiDocument jsonApiDoc = StringUtils .isEmpty (jsonApiDocument )
251318 ? new JsonApiDocument ()
252319 : mapper .readJsonApiDocument (jsonApiDocument );
253320 RequestScope requestScope = new RequestScope (path , apiVersion , jsonApiDoc ,
254- tx , user , null , elideSettings );
321+ tx , user , null , requestId , elideSettings );
255322 requestScope .setEntityProjection (new EntityProjectionMaker (elideSettings .getDictionary (),
256323 requestScope ).parsePath (path ));
257324 BaseVisitor visitor = new DeleteVisitor (requestScope );
@@ -274,16 +341,15 @@ public HandlerResult visit(String path, RequestScope requestScope, BaseVisitor v
274341 * @param isReadOnly if the transaction is read only
275342 * @param user the user object from the container
276343 * @param transaction a transaction supplier
344+ * @param requestId the Request ID
277345 * @param handler a function that creates the request scope and request handler
278346 * @return the response
279347 */
280348 protected ElideResponse handleRequest (boolean isReadOnly , User user ,
281- Supplier <DataStoreTransaction > transaction ,
349+ Supplier <DataStoreTransaction > transaction , UUID requestId ,
282350 Handler <DataStoreTransaction , User , HandlerResult > handler ) {
283351 boolean isVerbose = false ;
284- UUID requestId = null ;
285352 try (DataStoreTransaction tx = transaction .get ()) {
286- requestId = tx .getRequestId ();
287353 transactionRegistry .addRunningTransaction (requestId , tx );
288354 HandlerResult result = handler .handle (tx , user );
289355 RequestScope requestScope = result .getRequestScope ();
@@ -313,29 +379,23 @@ protected ElideResponse handleRequest(boolean isReadOnly, User user,
313379
314380 } catch (WebApplicationException e ) {
315381 throw e ;
316-
317382 } catch (ForbiddenAccessException e ) {
318383 if (log .isDebugEnabled ()) {
319384 log .debug ("{}" , e .getLoggedMessage ());
320385 }
321386 return buildErrorResponse (e , isVerbose );
322-
323387 } catch (JsonPatchExtensionException e ) {
324388 log .debug ("JSON patch extension exception caught" , e );
325389 return buildErrorResponse (e , isVerbose );
326-
327390 } catch (HttpStatusException e ) {
328391 log .debug ("Caught HTTP status exception" , e );
329392 return buildErrorResponse (e , isVerbose );
330-
331393 } catch (IOException e ) {
332394 log .error ("IO Exception uncaught by Elide" , e );
333395 return buildErrorResponse (new TransactionException (e ), isVerbose );
334-
335396 } catch (ParseCancellationException e ) {
336397 log .debug ("Parse cancellation exception uncaught by Elide (i.e. invalid URL)" , e );
337398 return buildErrorResponse (new InvalidURLException (e ), isVerbose );
338-
339399 } catch (ConstraintViolationException e ) {
340400 log .debug ("Constraint violation exception caught" , e );
341401 String message = "Constraint violation" ;
@@ -351,7 +411,6 @@ protected ElideResponse handleRequest(boolean isReadOnly, User user,
351411 }
352412 log .error ("Error or exception uncaught by Elide" , e );
353413 throw e ;
354-
355414 } finally {
356415 transactionRegistry .removeRunningTransaction (requestId );
357416 auditLogger .clear ();
0 commit comments