Package io.jans.scim.model.scim2.util
Class ScimResourceUtil
- java.lang.Object
-
- io.jans.scim.model.scim2.util.ScimResourceUtil
-
public class ScimResourceUtil extends Object
This class contains methods to facilitate transformation, and manipulation of data inside SCIM resource objects, as well as some miscellaneous routines.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
adjustNotationInPath(String path, String defaultUrn, List<String> schemas)
static void
adjustPrimarySubAttributes(BaseScimResource resource)
Takes a SCIM resource and "fixes" inconsistencies in "primary" subattribute: in a multivalued attribute setting, only one of the items in the collection can have"primary" : true
.static BaseScimResource
clone(BaseScimResource object)
static BaseScimResource
deleteFromResource(BaseScimResource origin, String path, List<Extension> extensions)
Returns a SCIM resource with the same data found inorigin
object, except for the attribute referenced bypath
being removed from the output.static String
getDefaultSchemaUrn(Class<? extends BaseScimResource> cls)
Returns theurn
associated to the default schema of the SCIM resource whose class is passed as parameter.static Schema
getSchemaAnnotation(Class<? extends BaseScimResource> cls)
Returns theSchema
annotation found in the class passed as parameter.static String
getType(Class<? extends BaseScimResource> cls)
Returns the (human-readable) type of a SCIM resource based on its class.static String[]
splitPath(String path, List<String> urns)
static String
stripDefaultSchema(Class<? extends BaseScimResource> cls, String attribute)
Removes from an attribute path the schemaurn
that might prefix such path.static BaseScimResource
transferToResourceAdd(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions)
This method applies the same copying rules oftransferToResourceReplace
except for the following: When a multi-valued attribute is passed inreplacementDataSource
, the existing data in theoriginalDataSource
object is retained, and the items in the former object are prepended to the existing collection.static BaseScimResource
transferToResourceReplace(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions)
Returns an object which is the result of incorporating the information found in thereplacementDataSource
parameter to the information existing inoriginalDataSource
object by doing replacements.
-
-
-
Method Detail
-
transferToResourceReplace
public static BaseScimResource transferToResourceReplace(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions) throws InvalidAttributeValueException
Returns an object which is the result of incorporating the information found in thereplacementDataSource
parameter to the information existing inoriginalDataSource
object by doing replacements. The transference of data follows these rules:- Ignores changes in readonly attributes
- Ignores null values (for single-valued attributes) in
replacementDataSource
- Nullifies multi-valued attributes when empty array is passed in
replacementDataSource
- Immutable attributes must match in both input objects or else exception is thrown. However, if the value in
originalDataSource
is missing (null), the value coming fromreplacementDataSource
is kept - When a multi-valued attribute is passed in
replacementDataSource
, no existing data in theoriginalDataSource
is retained, that is, the replacement is not partial but thorough: it's not an item-by-item replacement
- Parameters:
replacementDataSource
- Object with the information to be incorporated. Only non-null attributes of this object end up being transfered to the resultoriginalDataSource
- Object (SCIM resource) that provides the original dataextensions
- A list ofExtensions
associated to parameteroriginalDataSource
. This helps to manipulate the transference of custom attributes values.- Returns:
- A new object that contains the result of data transference. Neither
replacementDataSource
nororiginalDataSource
are changed after a call to this method - Throws:
InvalidAttributeValueException
- When recursive traversal ofreplacementDataSource
fails or if the rule of immutable attribute was not fulfilled
-
transferToResourceAdd
public static BaseScimResource transferToResourceAdd(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions) throws InvalidAttributeValueException
This method applies the same copying rules oftransferToResourceReplace
except for the following:- When a multi-valued attribute is passed in
replacementDataSource
, the existing data in theoriginalDataSource
object is retained, and the items in the former object are prepended to the existing collection.
- Parameters:
replacementDataSource
- Object with the information to be incorporated. Only non-null attributes of this object end up being transferred to the resultoriginalDataSource
- Object (SCIM resource) that provides the original dataextensions
- A list ofExtensions
associated to parameteroriginalDataSource
. This helps to manipulate the transference of custom attributes values.- Returns:
- A new object that contains the result of data transference. Neither
replacementDataSource
nororiginalDataSource
are changed after a call to this method - Throws:
InvalidAttributeValueException
- When recursive traversal ofreplacementDataSource
fails or if the rule of immutable attribute was not fulfilled
- When a multi-valued attribute is passed in
-
deleteFromResource
public static BaseScimResource deleteFromResource(BaseScimResource origin, String path, List<Extension> extensions) throws InvalidAttributeValueException
Returns a SCIM resource with the same data found inorigin
object, except for the attribute referenced bypath
being removed from the output. In other words, this method nullifies an attribute.- Parameters:
origin
- The resource having the the original datapath
- An attribute path (in dot notation). Examples could be:displayName, emails.type, addresses, meta.lastModified
.extensions
- A list ofExtension
s associated toorigin
Object- Returns:
- The resulting object: data in origin without the attribute referenced by
path
- Throws:
InvalidAttributeValueException
- If there is an attempt to remove an attribute annotated asrequired
orread-only
-
getSchemaAnnotation
public static Schema getSchemaAnnotation(Class<? extends BaseScimResource> cls)
Returns theSchema
annotation found in the class passed as parameter.- Parameters:
cls
- A class representing a SCIM resource- Returns:
- The annotation found or null if there is no such
-
getDefaultSchemaUrn
public static String getDefaultSchemaUrn(Class<? extends BaseScimResource> cls)
Returns theurn
associated to the default schema of the SCIM resource whose class is passed as parameter.- Parameters:
cls
- A class representing a SCIM resource- Returns:
- The urn (obtained by calling
Schema.id()
on the appropriateSchema
annotation) or null if there is no such annotation in the classcls
-
stripDefaultSchema
public static String stripDefaultSchema(Class<? extends BaseScimResource> cls, String attribute)
Removes from an attribute path the schemaurn
that might prefix such path. Theurn
to remove will correspond to the default schema urn of a SCIM resource type whose class is passed as parameter.- Parameters:
cls
- A class that represents a SCIM resource typeattribute
- An attribute path (potentially prefixed by aurn
)- Returns:
- The attribute with no prefix. As an example,
attribute_name
is returned ifurn:attribute_name
is the value of attribute parameter (as long as urn represent the default urn for this resource)
-
getType
public static String getType(Class<? extends BaseScimResource> cls)
Returns the (human-readable) type of a SCIM resource based on its class. In practice this will be something like "User" or "Group". The type is obtained by callingSchema.name()
of the respective class annotation.- Parameters:
cls
- A class that represents a SCIM resource type- Returns:
- A string with the proper value, or null if there is no
Schema
annotation found
-
adjustNotationInPath
public static String adjustNotationInPath(String path, String defaultUrn, List<String> schemas)
-
adjustPrimarySubAttributes
public static void adjustPrimarySubAttributes(BaseScimResource resource)
Takes a SCIM resource and "fixes" inconsistencies in "primary" subattribute: in a multivalued attribute setting, only one of the items in the collection can have"primary" : true
. Thus, for every collection involved (e.g. addresses, emails... inUserResource
), it switches all occurrences where "primary" is currentlytrue
tofalse
, except for the first one found.- Parameters:
resource
- SCIM resource object
-
clone
public static BaseScimResource clone(BaseScimResource object)
-
-