jmuehlner commented on code in PR #809:
URL: https://github.com/apache/guacamole-client/pull/809#discussion_r1159089459
##########
guacamole/src/main/java/org/apache/guacamole/rest/directory/DirectoryResource.java:
##########
@@ -386,46 +417,211 @@ public Map<String, ExternalType> getObjects(
/**
* Applies the given object patches, updating the underlying directory
- * accordingly. This operation currently only supports deletion of objects
- * through the "remove" patch operation. The path of each patch operation
is
- * of the form "/ID" where ID is the identifier of the object being
- * modified.
+ * accordingly. This operation supports addition and removal of objects
+ * through the "add" and "remove" patch operation. The path of each patch
+ * operation is of the form "/ID" where ID is the identifier of the object
+ * being modified. In the case of object creation, the identifier is
+ * ignored, as the identifier will be automatically provided. This
operation
+ * is atomic.
*
* @param patches
* The patches to apply for this request.
*
* @throws GuacamoleException
- * If an error occurs while deleting the objects.
+ * If an error occurs while adding, updating, or removing objects.
+ *
+ * @return
+ * A response describing the outcome of each patch. Only the identifier
+ * of each patched object will be included in the response, not the
+ * full object.
*/
@PATCH
- public void patchObjects(List<APIPatch<String>> patches)
+ public APIPatchResponse patchObjects(List<APIPatch<ExternalType>> patches)
throws GuacamoleException {
- // Apply each operation specified within the patch
- for (APIPatch<String> patch : patches) {
+ // An outcome for each patch included in the request. This list
+ // may include both success and failure responses, though the
+ // presence of any failure would indicated that the entire
+ // request has failed and no changes have been made.
+ List<APIPatchOutcome> patchOutcomes = new ArrayList<>();
- // Only remove is supported
- if (patch.getOp() != APIPatch.Operation.remove)
- throw new GuacamoleUnsupportedException("Only the \"remove\" "
- + "operation is supported.");
+ // Perform all requested operations atomically
+ directory.tryAtomically(new AtomicDirectoryOperation<InternalType>() {
- // Retrieve and validate path
- String path = patch.getPath();
- if (!path.startsWith("/"))
- throw new GuacamoleClientException("Patch paths must start
with \"/\".");
+ @Override
+ public void executeOperation(boolean atomic,
Directory<InternalType> directory)
+ throws GuacamoleException {
+
+ // If the underlying directory implentation does not support
+ // atomic operations, abort the patch operation. This REST
+ // endpoint requires that operations be performed atomically.
+ if (!atomic)
+ throw new GuacamoleUnsupportedException(
+ "Atomic operations are not supported. " +
+ "The patch cannot be executed.");
Review Comment:
How does this look?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]