Package org.forgerock.json.resource
Class PatchOperation
- java.lang.Object
- 
- org.forgerock.json.resource.PatchOperation
 
- 
 public final class PatchOperation extends Object An individual patch operation which is to be performed against a field within a resource. This class defines four core types of operation. The core operations are defined below and their behavior depends on the type of the field being targeted by the operation:- an object (Java Map) or primitive (JavaString,Boolean, orNumber): these are considered to be single-valued fields
- an array (Java List): these are considered to be multi-valued fields exhibiting either:- list semantics - an ordered collection of potentially non-unique values, or
- set semantics - a collection of unique values whose ordering is implementation defined.
 
 - add- ensures that the targeted field contains the provided value(s). Missing parent fields will be created as needed. If the targeted field is already present and it is single-valued (i.e. not an array) then the existing value will be replaced. If the targeted field is already present and it is multi-valued (i.e. an array) then the behavior depends on whether the field is a list or a set:- list - the provided array of values will be appended to the existing list of values,
- set - the provided array of values will be merged with the existing set of values and duplicates removed.
 
- remove- ensures that the targeted field does not contain the provided value(s) if present. If no values are provided with the remove operation then the entire field will be removed if it is present. If the remove operation targets a single-valued field and a patch value is provided then it must match the existing value for it to be removed, otherwise the field is left unchanged. If the remove operation targets a multi-valued field then the behavior depends on whether the field is a list or a set:- list - the provided array of values will be removed from the existing list of values. Each value in the remove operation will result in at most one value being removed from the existing list. In other words, if the existing list contains a pair of duplicate values and both of them need to be removed, then the values must be include twice in the remove operation,
- set - the provided array of values will be removed from the existing set of values.
 
- replace- removes any existing value(s) of the targeted field and replaces them with the provided value(s). A replace operation is semantically equivalent to a- removefollowed by an- add, except that indexed updates are not permitted regardless of whether or not the field is a list.
- increment- increments or decrements the targeted numerical field value(s) by the specified amount. If the amount is negative then the value(s) are decremented. It is an error to attempt to increment a field which does not contain a number or an array of numbers. It is also an error if the patch value is not a single value.
 NOTE: this class does not define how field values will be matched, nor does it define whether a resource supports indexed based modifications, nor whether fields are single or multi-valued. Instead these matters are the responsibility of the resource provider and, in particular, the JSON schema being enforced for the targeted resource. 
- an object (Java 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringFIELD_FIELDThe name of the field which contains the target field in the JSON representation.static StringFIELD_FROMThe name of the source field for copy and move operations.static StringFIELD_OPERATIONThe name of the field which contains the type of patch operation in the JSON representation.static StringFIELD_VALUEThe name of the field which contains the operation value in the JSON representation.static StringOPERATION_ADDThe identifier used for "add" operations.static StringOPERATION_COPYThe identifier used for "copy" operations.static StringOPERATION_INCREMENTThe identifier used for "increment" operations.static StringOPERATION_MOVEThe identifier used for "move" operations.static StringOPERATION_REMOVEThe identifier used for "remove" operations.static StringOPERATION_REPLACEThe identifier used for "replace" operations.static StringOPERATION_TRANSFORMThe identifier used for "transform" operations.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PatchOperationadd(String field, Object value)Creates a new "add" patch operation which will add the provided value(s) to the specified field.static PatchOperationadd(JsonPointer field, Object value)Creates a new "add" patch operation which will add the provided value(s) to the specified field.static PatchOperationcopy(String from, String field)Creates a new "copy" patch operation which will copy the value found at `from` to `path`.static PatchOperationcopy(JsonPointer from, JsonPointer field)Creates a new "copy" patch operation which will copy the value found at `from` to `path`.static PatchOperationcopyOf(PatchOperation operation)Returns a deep copy of the provided patch operation.JsonPointergetField()Returns the field targeted by the patch operation.JsonPointergetFrom()Returns the source field for move and copy operations.StringgetOperation()Returns the type of patch operation to be performed.JsonValuegetValue()Returns the value for the patch operation.static PatchOperationincrement(String field, Number amount)Creates a new "increment" patch operation which will increment the value(s) of the specified field by the amount provided.static PatchOperationincrement(JsonPointer field, Number amount)Creates a new "increment" patch operation which will increment the value(s) of the specified field by the amount provided.booleanisAdd()Returnstrueif this is an "add" patch operation.booleanisCopy()Returnstrueif this is a "copy" patch operation.booleanisIncrement()Returnstrueif this is an "increment" patch operation.booleanisMove()Returnstrueif this is a "move" patch operation.booleanisRemove()Returnstrueif this is an "remove" patch operation.booleanisReplace()Returnstrueif this is an "replace" patch operation.booleanisTransform()Returnstrueif this is a "transform" patch operation.static PatchOperationmove(String from, String field)Creates a new "move" patch operation which will move the value found at `from` to `path`.static PatchOperationmove(JsonPointer from, JsonPointer field)Creates a new "move" patch operation which will move the value found at `from` to `path`.static PatchOperationoperation(String operation, String field, Object value)Creates a new patch operation having the specified operation type, field, and value(s).static PatchOperationoperation(String operation, JsonPointer field, Object value)Creates a new patch operation having the specified operation type, field, and value(s).static PatchOperationremove(String field)Creates a new "remove" patch operation which will remove the specified field.static PatchOperationremove(String field, Object value)Creates a new "remove" patch operation which will remove the provided value(s) from the specified field.static PatchOperationremove(JsonPointer field)Creates a new "remove" patch operation which will remove the specified field.static PatchOperationremove(JsonPointer field, Object value)Creates a new "remove" patch operation which will remove the provided value(s) from the specified field.static PatchOperationreplace(String field, Object value)Creates a new "replace" patch operation which will replace the value(s) of the specified field with the provided value(s).static PatchOperationreplace(JsonPointer field, Object value)Creates a new "replace" patch operation which will replace the value(s) of the specified field with the provided value(s).JsonValuetoJsonValue()Returns a JSON value representation of this patch operation.StringtoString()static PatchOperationtransform(String field, Object transform)Creates a new "transform" patch operation which sets the value at field based on a transformation.static PatchOperationtransform(JsonPointer field, Object transform)Creates a new "transform" patch operation which sets the value at field based on a transformation.static PatchOperationvalueOf(JsonValue json)Parses the provided JSON content as a patch operation.static List<PatchOperation>valueOfList(JsonValue json)Parses the provided JSON content as a list of patch operations.
 
- 
- 
- 
Field Detail- 
FIELD_FIELDpublic static final String FIELD_FIELD The name of the field which contains the target field in the JSON representation.- See Also:
- Constant Field Values
 
 - 
FIELD_FROMpublic static final String FIELD_FROM The name of the source field for copy and move operations.- See Also:
- Constant Field Values
 
 - 
FIELD_OPERATIONpublic static final String FIELD_OPERATION The name of the field which contains the type of patch operation in the JSON representation.- See Also:
- Constant Field Values
 
 - 
FIELD_VALUEpublic static final String FIELD_VALUE The name of the field which contains the operation value in the JSON representation.- See Also:
- Constant Field Values
 
 - 
OPERATION_ADDpublic static final String OPERATION_ADD The identifier used for "add" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_INCREMENTpublic static final String OPERATION_INCREMENT The identifier used for "increment" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_REMOVEpublic static final String OPERATION_REMOVE The identifier used for "remove" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_REPLACEpublic static final String OPERATION_REPLACE The identifier used for "replace" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_MOVEpublic static final String OPERATION_MOVE The identifier used for "move" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_COPYpublic static final String OPERATION_COPY The identifier used for "copy" operations.- See Also:
- Constant Field Values
 
 - 
OPERATION_TRANSFORMpublic static final String OPERATION_TRANSFORM The identifier used for "transform" operations. This is similar to an "add" or "replace" but the value may be treated as something other than a raw object.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
addpublic static PatchOperation add(JsonPointer field, Object value) Creates a new "add" patch operation which will add the provided value(s) to the specified field.- Parameters:
- field- The field to be added.
- value- The new value(s) to be added, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the value is- null.
 
 - 
addpublic static PatchOperation add(String field, Object value) Creates a new "add" patch operation which will add the provided value(s) to the specified field.- Parameters:
- field- The field to be added.
- value- The new value(s) to be added, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the value is- null.
 
 - 
incrementpublic static PatchOperation increment(JsonPointer field, Number amount) Creates a new "increment" patch operation which will increment the value(s) of the specified field by the amount provided.- Parameters:
- field- The field to be incremented.
- amount- The amount to be added or removed (if negative) from the field's value(s).
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the amount is- null.
 
 - 
incrementpublic static PatchOperation increment(String field, Number amount) Creates a new "increment" patch operation which will increment the value(s) of the specified field by the amount provided.- Parameters:
- field- The field to be incremented.
- amount- The amount to be added or removed (if negative) from the field's value(s).
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the amount is- null.
 
 - 
removepublic static PatchOperation remove(JsonPointer field) Creates a new "remove" patch operation which will remove the specified field.- Parameters:
- field- The field to be removed.
- Returns:
- The new patch operation.
 
 - 
removepublic static PatchOperation remove(JsonPointer field, Object value) Creates a new "remove" patch operation which will remove the provided value(s) from the specified field.- Parameters:
- field- The field to be removed.
- value- The value(s) to be removed, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
removepublic static PatchOperation remove(String field) Creates a new "remove" patch operation which will remove the specified field.- Parameters:
- field- The field to be removed.
- Returns:
- The new patch operation.
 
 - 
removepublic static PatchOperation remove(String field, Object value) Creates a new "remove" patch operation which will remove the provided value(s) from the specified field.- Parameters:
- field- The field to be removed.
- value- The value(s) to be removed, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
replacepublic static PatchOperation replace(JsonPointer field, Object value) Creates a new "replace" patch operation which will replace the value(s) of the specified field with the provided value(s).- Parameters:
- field- The field to be replaced.
- value- The new value(s) for the field, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
replacepublic static PatchOperation replace(String field, Object value) Creates a new "replace" patch operation which will replace the value(s) of the specified field with the provided value(s).- Parameters:
- field- The field to be replaced.
- value- The new value(s) for the field, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
movepublic static PatchOperation move(JsonPointer from, JsonPointer field) Creates a new "move" patch operation which will move the value found at `from` to `path`.- Parameters:
- from- The field to be moved.
- field- The destination path for the moved value
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the from or path is- null.
 
 - 
movepublic static PatchOperation move(String from, String field) Creates a new "move" patch operation which will move the value found at `from` to `path`.- Parameters:
- from- The field to be moved.
- field- The destination path for the moved value
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the from or path is- null.
 
 - 
copypublic static PatchOperation copy(JsonPointer from, JsonPointer field) Creates a new "copy" patch operation which will copy the value found at `from` to `path`.- Parameters:
- from- The field to be copied.
- field- The destination path for the copied value
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the from or path is- null.
 
 - 
copypublic static PatchOperation copy(String from, String field) Creates a new "copy" patch operation which will copy the value found at `from` to `path`.- Parameters:
- from- The field to be copied.
- field- The destination path for the copied value
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the from or path is- null.
 
 - 
transformpublic static PatchOperation transform(JsonPointer field, Object transform) Creates a new "transform" patch operation which sets the value at field based on a transformation.- Parameters:
- field- The field to be set.
- transform- The transform to be used to set the field value.
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the transform is- null.
 
 - 
transformpublic static PatchOperation transform(String field, Object transform) Creates a new "transform" patch operation which sets the value at field based on a transformation.- Parameters:
- field- The field to be set.
- transform- The transform to be used to set the field value.
- Returns:
- The new patch operation.
- Throws:
- NullPointerException- If the transform is- null.
 
 - 
operationpublic static PatchOperation operation(String operation, JsonPointer field, Object value) Creates a new patch operation having the specified operation type, field, and value(s).- Parameters:
- operation- The type of patch operation to be performed.
- field- The field targeted by the patch operation.
- value- The possibly- nullvalue for the patch operation, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
operationpublic static PatchOperation operation(String operation, String field, Object value) Creates a new patch operation having the specified operation type, field, and value(s).- Parameters:
- operation- The type of patch operation to be performed.
- field- The field targeted by the patch operation.
- value- The possibly- nullvalue for the patch operation, which may be a- JsonValueor a JSON object, such as a- String,- Map, etc.
- Returns:
- The new patch operation.
 
 - 
copyOfpublic static PatchOperation copyOf(PatchOperation operation) Returns a deep copy of the provided patch operation. This method may be used in cases where the immutability of the underlying JSON value cannot be guaranteed.- Parameters:
- operation- The patch operation to be defensively copied.
- Returns:
- A deep copy of the provided patch operation.
 
 - 
valueOfpublic static PatchOperation valueOf(JsonValue json) throws BadRequestException Parses the provided JSON content as a patch operation.- Parameters:
- json- The patch operation to be parsed.
- Returns:
- The parsed patch operation.
- Throws:
- BadRequestException- If the JSON value is not a JSON patch operation.
 
 - 
valueOfListpublic static List<PatchOperation> valueOfList(JsonValue json) throws BadRequestException Parses the provided JSON content as a list of patch operations.- Parameters:
- json- The list of patch operations to be parsed.
- Returns:
- The list of parsed patch operations.
- Throws:
- BadRequestException- If the JSON value is not a list of JSON patch operations.
 
 - 
getFieldpublic JsonPointer getField() Returns the field targeted by the patch operation.- Returns:
- The field targeted by the patch operation.
 
 - 
getFrompublic JsonPointer getFrom() Returns the source field for move and copy operations.- Returns:
- The source field for move and copy operations.
 
 - 
getOperationpublic String getOperation() Returns the type of patch operation to be performed.- Returns:
- The type of patch operation to be performed.
 
 - 
getValuepublic JsonValue getValue() Returns the value for the patch operation. The return value may be a JSON value whose value isnull.- Returns:
- The nullable value for the patch operation.
 
 - 
isAddpublic boolean isAdd() Returnstrueif this is an "add" patch operation.- Returns:
- trueif this is an "add" patch operation.
 
 - 
isIncrementpublic boolean isIncrement() Returnstrueif this is an "increment" patch operation.- Returns:
- trueif this is an "increment" patch operation.
 
 - 
isRemovepublic boolean isRemove() Returnstrueif this is an "remove" patch operation.- Returns:
- trueif this is an "remove" patch operation.
 
 - 
isReplacepublic boolean isReplace() Returnstrueif this is an "replace" patch operation.- Returns:
- trueif this is an "replace" patch operation.
 
 - 
isMovepublic boolean isMove() Returnstrueif this is a "move" patch operation.- Returns:
- trueif this is a "move" patch operation.
 
 - 
isCopypublic boolean isCopy() Returnstrueif this is a "copy" patch operation.- Returns:
- trueif this is a "copy" patch operation.
 
 - 
isTransformpublic boolean isTransform() Returnstrueif this is a "transform" patch operation.- Returns:
- trueif this is a "transform" patch operation.
 
 - 
toJsonValuepublic JsonValue toJsonValue() Returns a JSON value representation of this patch operation.- Returns:
- A JSON value representation of this patch operation.
 
 
- 
 
-