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 StringadjustNotationInPath(String path, String defaultUrn, List<String> schemas)static voidadjustPrimarySubAttributes(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 BaseScimResourceclone(BaseScimResource object)static BaseScimResourcedeleteFromResource(BaseScimResource origin, String path, List<Extension> extensions)Returns a SCIM resource with the same data found inoriginobject, except for the attribute referenced bypathbeing removed from the output.static StringgetDefaultSchemaUrn(Class<? extends BaseScimResource> cls)Returns theurnassociated to the default schema of the SCIM resource whose class is passed as parameter.static SchemagetSchemaAnnotation(Class<? extends BaseScimResource> cls)Returns theSchemaannotation found in the class passed as parameter.static StringgetType(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 StringstripDefaultSchema(Class<? extends BaseScimResource> cls, String attribute)Removes from an attribute path the schemaurnthat might prefix such path.static BaseScimResourcetransferToResourceAdd(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions)This method applies the same copying rules oftransferToResourceReplaceexcept for the following: When a multi-valued attribute is passed inreplacementDataSource, the existing data in theoriginalDataSourceobject is retained, and the items in the former object are prepended to the existing collection.static BaseScimResourcetransferToResourceReplace(BaseScimResource replacementDataSource, BaseScimResource originalDataSource, List<Extension> extensions)Returns an object which is the result of incorporating the information found in thereplacementDataSourceparameter to the information existing inoriginalDataSourceobject 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 thereplacementDataSourceparameter to the information existing inoriginalDataSourceobject 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
originalDataSourceis missing (null), the value coming fromreplacementDataSourceis kept - When a multi-valued attribute is passed in
replacementDataSource, no existing data in theoriginalDataSourceis 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 ofExtensionsassociated to parameteroriginalDataSource. This helps to manipulate the transference of custom attributes values.- Returns:
- A new object that contains the result of data transference. Neither
replacementDataSourcenororiginalDataSourceare changed after a call to this method - Throws:
InvalidAttributeValueException- When recursive traversal ofreplacementDataSourcefails 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 oftransferToResourceReplaceexcept for the following:- When a multi-valued attribute is passed in
replacementDataSource, the existing data in theoriginalDataSourceobject 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 ofExtensionsassociated to parameteroriginalDataSource. This helps to manipulate the transference of custom attributes values.- Returns:
- A new object that contains the result of data transference. Neither
replacementDataSourcenororiginalDataSourceare changed after a call to this method - Throws:
InvalidAttributeValueException- When recursive traversal ofreplacementDataSourcefails 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 inoriginobject, except for the attribute referenced bypathbeing 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 ofExtensions associated tooriginObject- 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 asrequiredorread-only
-
getSchemaAnnotation
public static Schema getSchemaAnnotation(Class<? extends BaseScimResource> cls)
Returns theSchemaannotation 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 theurnassociated 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 appropriateSchemaannotation) 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 schemaurnthat might prefix such path. Theurnto 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_nameis returned ifurn:attribute_nameis 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
Schemaannotation 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 currentlytruetofalse, except for the first one found.- Parameters:
resource- SCIM resource object
-
clone
public static BaseScimResource clone(BaseScimResource object)
-
-