Class BaseScimResource
- java.lang.Object
-
- com.unboundid.scim2.common.BaseScimResource
-
- All Implemented Interfaces:
ScimResource
- Direct Known Subclasses:
ErrorResponse
,GroupResource
,ListResponse
,PatchRequest
,ResourceTypeResource
,SchemaResource
,SearchRequest
,ServiceProviderConfigResource
,UserResource
public abstract class BaseScimResource extends Object implements ScimResource
The base SCIM object. This object contains all of the attributes required of SCIM objects.
BaseScimResource is used when the schema is known ahead of time. In that case a developer can derive a class from BaseScimResource and annotate the class. The class should be a Java bean. This will make it easier to work with the SCIM object since you will just have plain old getters and setters for core attributes. Extension attributes cannot be bound to members of the class but they can still be accessed using the
getExtensionObjectNode()
method or thegetExtensionValues(java.lang.String)
,replaceExtensionValue(java.lang.String, com.fasterxml.jackson.databind.JsonNode)
, andaddExtensionValue(java.lang.String, com.fasterxml.jackson.databind.node.ArrayNode)
methods.If you have a BaseScimResource derived object, you can always get a
GenericScimResource
by callingasGenericScimResource()
. You could also go the other way by callingGenericScimResource.getObjectNode()
, followed byJsonUtils.nodeToValue(JsonNode, Class)
.- See Also:
GenericScimResource
-
-
Constructor Summary
Constructors Constructor Description BaseScimResource()
Constructs a new BaseScimResource object, and sets the urn if the class extending this one is annotated.BaseScimResource(String id)
Constructs a new BaseScimResource object, and sets the urn if the class extending this one is annotated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExtensionValue(Path path, com.fasterxml.jackson.databind.node.ArrayNode values)
Add new values to the extension attribute at the provided path.void
addExtensionValue(String path, com.fasterxml.jackson.databind.node.ArrayNode values)
Add new values for the extension attribute at the provided path.GenericScimResource
asGenericScimResource()
Returns the GenericScimResource representation of this ScimResource.boolean
equals(Object o)
protected Map<String,Object>
getAny()
Used to get values that were deserialized from json where there was no matching field in the class.<T> T
getExtension(Class<T> clazz)
Retrieve a SCIM extension based on the annotations of the class provided.com.fasterxml.jackson.databind.node.ObjectNode
getExtensionObjectNode()
Gets theObjectNode
that contains all extension attributes.List<com.fasterxml.jackson.databind.JsonNode>
getExtensionValues(Path path)
Retrieve all JSON nodes of the extension attribute referenced by the provided path.List<com.fasterxml.jackson.databind.JsonNode>
getExtensionValues(String path)
Retrieve all JSON nodes of the extension attribute referenced by the provided path.String
getExternalId()
Gets the objects external id.String
getId()
Gets the id of the object.Meta
getMeta()
Gets metadata about the object.Set<String>
getSchemaUrns()
Gets the schema urns for this object.int
hashCode()
<T> boolean
removeExtension(Class<T> clazz)
Removes a SCIM extension.boolean
removeExtensionValues(Path path)
Removes values of the extension attribute at the provided path.boolean
removeExtensionValues(String path)
Removes values of the extension attribute at the provided path.void
replaceExtensionValue(Path path, com.fasterxml.jackson.databind.JsonNode value)
Update the value of the extension attribute at the provided path.void
replaceExtensionValue(String path, com.fasterxml.jackson.databind.JsonNode value)
Update the value of the extension attribute at the provided path.protected void
setAny(String key, com.fasterxml.jackson.databind.JsonNode value)
This method is used during json deserialization.<T> void
setExtension(T extension)
Sets a SCIM extension to the given value based on the annotations of the class provided.void
setExternalId(String externalId)
Sets the object's external id.void
setId(String id)
Sets the id of the object.void
setMeta(Meta meta)
Sets metadata for the object.void
setSchemaUrns(String schemaUrn, String... schemaUrns)
An alternate version ofScimResource.setSchemaUrns(Collection)
.void
setSchemaUrns(Collection<String> schemaUrns)
Sets the schema urns for this object.String
toString()
-
-
-
Constructor Detail
-
BaseScimResource
public BaseScimResource()
Constructs a new BaseScimResource object, and sets the urn if the class extending this one is annotated.
-
BaseScimResource
public BaseScimResource(String id)
Constructs a new BaseScimResource object, and sets the urn if the class extending this one is annotated.- Parameters:
id
- The ID fo the object.
-
-
Method Detail
-
getExtensionObjectNode
public com.fasterxml.jackson.databind.node.ObjectNode getExtensionObjectNode()
Gets theObjectNode
that contains all extension attributes.- Returns:
- a
ObjectNode
.
-
getMeta
public Meta getMeta()
Gets metadata about the object.- Specified by:
getMeta
in interfaceScimResource
- Returns:
Meta
containing metadata about the object.
-
setMeta
public void setMeta(Meta meta)
Sets metadata for the object.- Specified by:
setMeta
in interfaceScimResource
- Parameters:
meta
-Meta
containing metadata for the object.
-
getId
public String getId()
Gets the id of the object.- Specified by:
getId
in interfaceScimResource
- Returns:
- the id of the object.
-
setId
public void setId(String id)
Sets the id of the object.- Specified by:
setId
in interfaceScimResource
- Parameters:
id
- The object's id.
-
getExternalId
public String getExternalId()
Gets the objects external id.- Specified by:
getExternalId
in interfaceScimResource
- Returns:
- The external id of the object.
-
setExternalId
public void setExternalId(String externalId)
Sets the object's external id.- Specified by:
setExternalId
in interfaceScimResource
- Parameters:
externalId
- The external id of the object.
-
getSchemaUrns
public Set<String> getSchemaUrns()
Gets the schema urns for this object. This includes the one for the class that extends this class (taken from the annotation), as well as any that are present in the extensions.- Specified by:
getSchemaUrns
in interfaceScimResource
- Returns:
- the schema urns for this object.
-
setSchemaUrns
public void setSchemaUrns(Collection<String> schemaUrns)
Sets the schema urns for this object. This set should contain all schema urns including the one for this object and all extensions. The value must not benull
.- Specified by:
setSchemaUrns
in interfaceScimResource
- Parameters:
schemaUrns
- A Collection containing the schema urns for this object.
-
setSchemaUrns
public void setSchemaUrns(String schemaUrn, String... schemaUrns)
An alternate version ofScimResource.setSchemaUrns(Collection)
.- Specified by:
setSchemaUrns
in interfaceScimResource
- Parameters:
schemaUrn
- A schema URN that will be listed first. This must not benull
.schemaUrns
- An optional parameter for additional schema URNs. Anynull
values will be ignored.
-
setAny
protected void setAny(String key, com.fasterxml.jackson.databind.JsonNode value) throws ScimException
This method is used during json deserialization. It will be called in the event that a value is given for an field that is not defined in the class.- Parameters:
key
- name of the field.value
- value of the field.- Throws:
ScimException
- if the key is not an extension attribute namespace (the key name doesn't start with "urn:
").
-
getAny
protected Map<String,Object> getAny()
Used to get values that were deserialized from json where there was no matching field in the class.- Returns:
- the value of the field.
-
getExtensionValues
public List<com.fasterxml.jackson.databind.JsonNode> getExtensionValues(String path) throws ScimException
Retrieve all JSON nodes of the extension attribute referenced by the provided path. Equivalent to using theJsonUtils.findMatchingPaths(Path, ObjectNode)
method: JsonUtils.getValues(Path.fromString(path), getExtensionObjectNode()). TheJsonUtils.nodeToValue(JsonNode, Class)
method may be used to bind the retrieved JSON node into specific value type instances.- Parameters:
path
- The path to the attribute whose value to retrieve.- Returns:
- List of all JSON nodes referenced by the provided path.
- Throws:
ScimException
- If the path is invalid.
-
getExtensionValues
public List<com.fasterxml.jackson.databind.JsonNode> getExtensionValues(Path path) throws ScimException
Retrieve all JSON nodes of the extension attribute referenced by the provided path. Equivalent to using theJsonUtils.findMatchingPaths(Path, ObjectNode)
method: JsonUtils.getValues(path, getExtensionObjectNode()). TheJsonUtils.nodeToValue(JsonNode, Class)
method may be used to bind the retrieved JSON node into specific value type instances.- Parameters:
path
- The path to the attribute whose value to retrieve.- Returns:
- List of all JSON nodes referenced by the provided path.
- Throws:
ScimException
- If the path is invalid.
-
replaceExtensionValue
public void replaceExtensionValue(String path, com.fasterxml.jackson.databind.JsonNode value) throws ScimException
Update the value of the extension attribute at the provided path. Equivalent to using theJsonUtils.replaceValue(Path, ObjectNode, JsonNode)
method: JsonUtils.replaceValues(Path.fromString(path), getExtensionObjectNode(), value). TheJsonUtils.valueToNode(Object)
method may be used to convert the given value instance to a JSON node.- Parameters:
path
- The path to the attribute whose value to set.value
- The value(s) to set.- Throws:
ScimException
- If the path is invalid.
-
replaceExtensionValue
public void replaceExtensionValue(Path path, com.fasterxml.jackson.databind.JsonNode value) throws ScimException
Update the value of the extension attribute at the provided path. Equivalent to using theJsonUtils.replaceValue(Path, ObjectNode, JsonNode)
method: JsonUtils.replaceValues(path, getExtensionObjectNode(), value). TheJsonUtils.valueToNode(Object)
method may be used to convert the given value instance to a JSON node.- Parameters:
path
- The path to the attribute whose value to set.value
- The value(s) to set.- Throws:
ScimException
- If the path is invalid.
-
getExtension
public <T> T getExtension(Class<T> clazz)
Retrieve a SCIM extension based on the annotations of the class provided. The returned value will be converted to a POJO of the type specified.- Type Parameters:
T
- the type of object to return.- Parameters:
clazz
- The class used to determine the type of the object returned and the schema of the extension.- Returns:
- The matching extension object, or
null
if no extension of that type exists.
-
setExtension
public <T> void setExtension(T extension)
Sets a SCIM extension to the given value based on the annotations of the class provided. The value will be set for an extension named based on the annotations of the class supplied.- Type Parameters:
T
- the type of object.- Parameters:
extension
- The value to set. This also is used to determine what the extension's urn is.
-
removeExtension
public <T> boolean removeExtension(Class<T> clazz)
Removes a SCIM extension. The extension urn is based on the annotations of the class provided.- Type Parameters:
T
- the type of the class object.- Parameters:
clazz
- the class used to determine the schema urn.- Returns:
- true if the extension was removed, or false if the extension was not present.
-
addExtensionValue
public void addExtensionValue(String path, com.fasterxml.jackson.databind.node.ArrayNode values) throws ScimException
Add new values for the extension attribute at the provided path. Equivalent to using theJsonUtils.addValue(Path, ObjectNode, JsonNode)
method: JsonUtils.addValue(Path.fromString(path), getExtensionObjectNode(), values). TheJsonUtils.valueToNode(Object)
method may be used to convert the given value instance to a JSON node.- Parameters:
path
- The path to the attribute whose values to add.values
- The value(s) to add.- Throws:
ScimException
- If the path is invalid.
-
addExtensionValue
public void addExtensionValue(Path path, com.fasterxml.jackson.databind.node.ArrayNode values) throws ScimException
Add new values to the extension attribute at the provided path. Equivalent to using theJsonUtils.addValue(Path, ObjectNode, JsonNode)
method: JsonUtils.addValue(path, getObjectNode(), values). TheJsonUtils.valueToNode(Object)
method may be used to convert the given value instance to a JSON node.- Parameters:
path
- The path to the attribute whose values to add.values
- The value(s) to add.- Throws:
ScimException
- If the path is invalid.
-
removeExtensionValues
public boolean removeExtensionValues(String path) throws ScimException
Removes values of the extension attribute at the provided path. Equivalent to using theJsonUtils.removeValues(Path, ObjectNode)
method: JsonUtils.removeValue(Path.fromString(path), getObjectNode(), values).- Parameters:
path
- The path to the attribute whose values to remove.- Returns:
- Whether one or more values where removed.
- Throws:
ScimException
- If the path is invalid.
-
removeExtensionValues
public boolean removeExtensionValues(Path path) throws ScimException
Removes values of the extension attribute at the provided path. Equivalent to using theJsonUtils.removeValues(Path, ObjectNode)
method: JsonUtils.removeValue(Path.fromString(path), getObjectNode(), values).- Parameters:
path
- The path to the attribute whose values to remove.- Returns:
- Whether one or more values where removed.
- Throws:
ScimException
- If the path is invalid.
-
asGenericScimResource
public GenericScimResource asGenericScimResource()
Returns the GenericScimResource representation of this ScimResource. If this ScimResource is already a GenericScimResource, this same instance will be returned.- Specified by:
asGenericScimResource
in interfaceScimResource
- Returns:
- The GenericScimResource representation of this ScimResource.
-
-