mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUACAMOLE-926: Remove patch update functionality. It's needed for batch import, and it's a can of worms.
This commit is contained in:
@@ -417,12 +417,12 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
|
||||
|
||||
/**
|
||||
* Applies the given object patches, updating the underlying directory
|
||||
* accordingly. This operation supports addition, update, and removal of
|
||||
* objects through the "add", "replace", 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.
|
||||
* 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.
|
||||
@@ -461,9 +461,8 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
|
||||
"The patch cannot be executed.");
|
||||
|
||||
// Keep a list of all objects that have been successfully
|
||||
// added, updated, or removed
|
||||
// added or removed
|
||||
Collection<InternalType> addedObjects = new ArrayList<>();
|
||||
Collection<InternalType> updatedObjects = new ArrayList<>();
|
||||
Collection<String> removedIdentifiers = new ArrayList<>();
|
||||
|
||||
// A list of all responses associated with the successful
|
||||
@@ -527,64 +526,6 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
|
||||
|
||||
}
|
||||
|
||||
else if (patch.getOp() == APIPatch.Operation.replace) {
|
||||
|
||||
// Filter/sanitize object contents
|
||||
InternalType internal = filterAndTranslate(patch.getValue());
|
||||
|
||||
try {
|
||||
|
||||
// Set the model to the supplied identifier from the PATH
|
||||
String identifier = path.substring(1);
|
||||
|
||||
if (identifier == null)
|
||||
throw new GuacamoleClientException(
|
||||
"An identifier is required when updating.");
|
||||
|
||||
// If there's an identiifer provided in the value,
|
||||
// make sure it matches the one from the path
|
||||
String valueId = internal.getIdentifier();
|
||||
if (valueId != null && !valueId.equals(identifier))
|
||||
throw new GuacamoleClientException(
|
||||
"Identifier mismatch between path and value.");
|
||||
|
||||
internal.setIdentifier(identifier);
|
||||
|
||||
// Attempt to update the object
|
||||
directory.update(internal);
|
||||
|
||||
// Add the object to the list if the update was successful
|
||||
updatedObjects.add(internal);
|
||||
|
||||
// Add a success outcome describing the object update
|
||||
APIPatchOutcome response = new APIPatchOutcome(
|
||||
patch.getOp(), internal.getIdentifier(), path);
|
||||
patchOutcomes.add(response);
|
||||
creationSuccesses.add(response);
|
||||
}
|
||||
|
||||
catch (GuacamoleException | RuntimeException | Error e) {
|
||||
failed = true;
|
||||
fireDirectoryFailureEvent(
|
||||
DirectoryEvent.Operation.UPDATE,
|
||||
internal.getIdentifier(), internal, e);
|
||||
|
||||
/*
|
||||
* If the failure represents an understood issue,
|
||||
* create a failure outcome for this failed patch.
|
||||
*/
|
||||
if (e instanceof GuacamoleException)
|
||||
patchOutcomes.add(new APIPatchError(
|
||||
patch.getOp(), internal.getIdentifier(), path,
|
||||
((GuacamoleException) e).getMessage()));
|
||||
|
||||
// If an unexpected failure occurs, fall through to the
|
||||
// standard API error handling
|
||||
else
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Append each identifier to the list, to be removed atomically
|
||||
else if (patch.getOp() == APIPatch.Operation.remove) {
|
||||
|
||||
@@ -625,6 +566,14 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
throw new GuacamoleUnsupportedException(
|
||||
"Unsupported patch operation \""
|
||||
+ patch.getOp() + "\". "
|
||||
+ "Only add and remove are supported.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -655,24 +604,13 @@ public abstract class DirectoryResource<InternalType extends Identifiable, Exter
|
||||
|
||||
}
|
||||
|
||||
// Fire directory success events for each updated object
|
||||
Iterator<InternalType> updatedIterator = updatedObjects.iterator();
|
||||
while (updatedIterator.hasNext()) {
|
||||
|
||||
InternalType internal = updatedIterator.next();
|
||||
fireDirectorySuccessEvent(
|
||||
DirectoryEvent.Operation.UPDATE,
|
||||
internal.getIdentifier(), internal);
|
||||
|
||||
}
|
||||
|
||||
// Fire directory success events for each removed object
|
||||
Iterator<String> removedIterator = removedIdentifiers.iterator();
|
||||
while (removedIterator.hasNext()) {
|
||||
|
||||
String identifier = removedIterator.next();
|
||||
fireDirectorySuccessEvent(
|
||||
DirectoryEvent.Operation.UPDATE,
|
||||
DirectoryEvent.Operation.REMOVE,
|
||||
identifier, null);
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user