Class BasicExpressionFunctions
- java.lang.Object
-
- com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions
-
public class BasicExpressionFunctions extends Object
Library of standard midPoint functions. These functions are made available to all midPoint expressions.The functions should be written to support scripting-like comfort. It means that they all needs to be null-safe, automatically convert data types as necessary and so on.
- Author:
- Radovan Semancik
-
-
Field Summary
Fields Modifier and Type Field Description static Trace
LOGGER
static XMLGregorianCalendar
LONG_AGO
Special value that is too far in the past.static String
NAME_SEPARATOR
-
Constructor Summary
Constructors Constructor Description BasicExpressionFunctions(PrismContext prismContext, Protector protector, Clock clock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XMLGregorianCalendar
addDuration(XMLGregorianCalendar now, String duration)
XMLGregorianCalendar
addDuration(XMLGregorianCalendar now, Duration duration)
XMLGregorianCalendar
addMillis(XMLGregorianCalendar now, long duration)
static String
composeDn(Object... components)
Creates a valid LDAP distinguished name from the wide range of components.static String
composeDnWithSuffix(Object... components)
Creates a valid LDAP distinguished name from the wide range of components assuming that the last component is a suffix.String
concatName(Object... components)
Concatenates the arguments to create a name.boolean
contains(Object object, Object search)
boolean
containsIgnoreCase(Object object, Object search)
XMLGregorianCalendar
currentDateTime()
static String
debugDump(Object o)
static String
debugDump(Object o, int indent)
String
decrypt(ProtectedStringType protectedString)
String
determineLdapSingleAttributeValue(String dn, String attributeName, Collection<?> values)
String
determineLdapSingleAttributeValue(Collection<String> dns, String attributeName, PrismProperty attribute)
String
determineLdapSingleAttributeValue(Collection<String> dns, String attributeName, Collection<String> values)
ProtectedStringType
encrypt(String string)
boolean
endsWith(PolyString polyString, String value)
Checks whether the given normalized string ends with the specified valueboolean
endsWith(String string, String value)
Checks whether the given normalized string ends with the specified value by first normalizing it.String
formatDateTime(String format, Long millis)
String
formatDateTime(String format, XMLGregorianCalendar xmlCal)
XMLGregorianCalendar
fromNow(String timeSpec)
Collection<String>
getAttributeStringValues(ShadowType shadow, groovy.xml.QName attributeQname)
Collection<String>
getAttributeStringValues(ShadowType shadow, String attributeNamespace, String attributeLocalPart)
Collection<String>
getAttributeStringValues(ShadowType shadow, QName attributeQname)
<T> T
getAttributeValue(ShadowType shadow, groovy.xml.QName attributeQname)
<T> T
getAttributeValue(ShadowType shadow, String attributeLocalPart)
<T> T
getAttributeValue(ShadowType shadow, String attributeNamespace, String attributeLocalPart)
<T> T
getAttributeValue(ShadowType shadow, QName attributeQname)
<T> Collection<T>
getAttributeValues(ShadowType shadow, groovy.xml.QName attributeQname)
<T> Collection<T>
getAttributeValues(ShadowType shadow, String attributeLocalPart)
<T> Collection<T>
getAttributeValues(ShadowType shadow, String attributeNamespace, String attributeLocalPart)
<T> Collection<T>
getAttributeValues(ShadowType shadow, QName attributeQname)
<T> T
getExtensionPropertyValue(Containerable containerable, groovy.xml.QName propertyQname)
<T> T
getExtensionPropertyValue(Containerable containerable, String localPart)
<T> T
getExtensionPropertyValue(Containerable containerable, String namespace, String localPart)
<T> T
getExtensionPropertyValue(Containerable containerable, QName propertyQname)
<T> Collection<T>
getExtensionPropertyValues(Containerable object, groovy.xml.QName propertyQname)
<T> Collection<T>
getExtensionPropertyValues(Containerable containerable, String namespace, String localPart)
<T> Collection<T>
getExtensionPropertyValues(Containerable object, QName propertyQname)
Referencable
getExtensionReferenceValue(ObjectType object, String namespace, String localPart)
Referencable
getExtensionReferenceValue(ObjectType object, QName propertyQname)
<T> T
getIdentifierValue(ShadowType shadow)
@NotNull Collection<?>
getMetadataExtensionValues(PrismValue value, String itemLocalPart)
Simplified version of getMetadataValue aimed at fetching single-segment extension paths.@NotNull Collection<?>
getMetadataValues(PrismValue value, Object... pathSegments)
Generic method to extract all metadata values pointed-to by given item path (specified as segments).@NotNull Collection<?>
getMetadataValues(PrismValue value, String path)
Collection<String>
getOids(ObjectReferenceType refs)
Collection<String>
getOids(ObjectType refs)
Collection<String>
getOids(Collection<ObjectReferenceType> refs)
PrismContext
getPrismContext()
<T> T
getPropertyValue(Containerable c, ItemPathType path)
<T> T
getPropertyValue(Containerable c, String path)
<T> T
getPropertyValue(PrismContainerValue<?> pcv, ItemPathType path)
<T> T
getPropertyValue(PrismContainerValue<?> pcv, String path)
<T> Collection<T>
getPropertyValues(Containerable c, ItemPathType path)
<T> Collection<T>
getPropertyValues(Containerable c, String path)
<T> Collection<T>
getPropertyValues(PrismContainerValue<?> pcv, ItemPathType path)
<T> Collection<T>
getPropertyValues(PrismContainerValue<?> pcv, String path)
<T> T
getResourceIcfConfigurationPropertyValue(ResourceType resource, String propertyLocalPart)
<T> T
getResourceIcfConfigurationPropertyValue(ResourceType resource, QName propertyQname)
<T> T
getSecondaryIdentifierValue(ShadowType shadow)
String
hashLdapPassword(byte[] clearBytes, String alg)
Hashes cleartext password in an (unofficial) LDAP password format.String
hashLdapPassword(ProtectedStringType protectedString, String alg)
Hashes cleartext password in an (unofficial) LDAP password format.String
hashLdapPassword(String clearString, String alg)
Hashes cleartext password in an (unofficial) LDAP password format.boolean
isEmpty(Object whatever)
static String
lc(String orig)
Convert string to lower case.XMLGregorianCalendar
longAgo()
String
norm(PolyString orig)
Normalize a PolyString value.String
norm(PolyStringType orig)
Normalize a PolyStringType value.String
norm(String orig)
Normalize a string value.String
parseAdditionalName(Object fullName)
XMLGregorianCalendar
parseDateTime(String format, String stringDate)
String
parseFamilyName(Object fullName)
String
parseGivenName(Object fullName)
String
parseHonorificPrefix(Object fullName)
String
parseHonorificSuffix(Object fullName)
String
parseNickName(Object fullName)
static String
readFile(String filename)
XMLGregorianCalendar
roundDownToMidnight(XMLGregorianCalendar in)
XMLGregorianCalendar
roundUpToEndOfDay(XMLGregorianCalendar in)
void
setExtensionRealValues(PrismContainerValue<?> containerValue, Map<String,Object> map)
void
setTaskWorkerThreads(TaskType task, Integer value)
boolean
startsWith(PolyString polyString, String value)
Checks whether the given normalized string begins with the specified value.boolean
startsWith(String string, String value)
Checks whether the given normalized string begins with the specified value by first normalizing it.String
stringify(Object whatever)
Converts whatever it gets to a string.String
toAscii(Object input)
<T> T
toSingle(Collection<T> values)
static String
trim(String orig)
Remove whitespaces at the beginning and at the end of the string.static String
uc(String orig)
Convert string to upper case.
-
-
-
Field Detail
-
NAME_SEPARATOR
public static final String NAME_SEPARATOR
- See Also:
- Constant Field Values
-
LOGGER
public static final Trace LOGGER
-
LONG_AGO
public static final XMLGregorianCalendar LONG_AGO
Special value that is too far in the past. It can be returned from time-based expressions to make sure that the expression is always executed.
-
-
Constructor Detail
-
BasicExpressionFunctions
public BasicExpressionFunctions(PrismContext prismContext, Protector protector, Clock clock)
-
-
Method Detail
-
trim
public static String trim(String orig)
Remove whitespaces at the beginning and at the end of the string.
-
concatName
public String concatName(Object... components)
Concatenates the arguments to create a name. Each argument is stringified, trimmed and the result is concatenated by spaces.
-
startsWith
public boolean startsWith(String string, String value)
Checks whether the given normalized string begins with the specified value by first normalizing it.- Parameters:
string
- the stringvalue
- the value- Returns:
- true/false
-
startsWith
public boolean startsWith(PolyString polyString, String value)
Checks whether the given normalized string begins with the specified value.- Parameters:
polyString
- the stringvalue
- the value- Returns:
- true/false
-
endsWith
public boolean endsWith(String string, String value)
Checks whether the given normalized string ends with the specified value by first normalizing it.- Parameters:
string
- the stringvalue
- the value- Returns:
- true/false
-
endsWith
public boolean endsWith(PolyString polyString, String value)
Checks whether the given normalized string ends with the specified value- Parameters:
polyString
- the stringvalue
- the value- Returns:
- true/false
-
norm
public String norm(String orig)
Normalize a string value. It follows the default normalization algorithm used for PolyString values.- Parameters:
orig
- original value to normalize- Returns:
- normalized value
-
norm
public String norm(PolyString orig)
Normalize a PolyString value.- Parameters:
orig
- original value to normalize- Returns:
- normalized value
-
norm
public String norm(PolyStringType orig)
Normalize a PolyStringType value.- Parameters:
orig
- original value to normalize- Returns:
- normalized value
-
stringify
public String stringify(Object whatever)
Converts whatever it gets to a string. But it does it in a sensitive way. E.g. it tries to detect collections and returns the first element (if there is only one). Never returns null. Returns empty string instead.
-
getOids
public Collection<String> getOids(Collection<ObjectReferenceType> refs)
-
getOids
public Collection<String> getOids(ObjectReferenceType refs)
-
getOids
public Collection<String> getOids(ObjectType refs)
-
isEmpty
public boolean isEmpty(Object whatever)
-
getPrismContext
public PrismContext getPrismContext()
-
getExtensionPropertyValues
public <T> Collection<T> getExtensionPropertyValues(Containerable containerable, String namespace, String localPart)
-
getExtensionPropertyValues
public <T> Collection<T> getExtensionPropertyValues(Containerable object, groovy.xml.QName propertyQname)
-
getExtensionPropertyValues
public <T> Collection<T> getExtensionPropertyValues(Containerable object, QName propertyQname)
-
getExtensionPropertyValue
public <T> T getExtensionPropertyValue(Containerable containerable, String localPart) throws SchemaException
- Throws:
SchemaException
-
getExtensionPropertyValue
public <T> T getExtensionPropertyValue(Containerable containerable, String namespace, String localPart) throws SchemaException
- Throws:
SchemaException
-
getExtensionReferenceValue
public Referencable getExtensionReferenceValue(ObjectType object, String namespace, String localPart) throws SchemaException
- Throws:
SchemaException
-
getExtensionPropertyValue
public <T> T getExtensionPropertyValue(Containerable containerable, groovy.xml.QName propertyQname) throws SchemaException
- Throws:
SchemaException
-
getExtensionPropertyValue
public <T> T getExtensionPropertyValue(Containerable containerable, QName propertyQname) throws SchemaException
- Throws:
SchemaException
-
getExtensionReferenceValue
public Referencable getExtensionReferenceValue(ObjectType object, QName propertyQname) throws SchemaException
- Throws:
SchemaException
-
getPropertyValue
public <T> T getPropertyValue(Containerable c, String path) throws SchemaException
- Throws:
SchemaException
-
getPropertyValues
public <T> Collection<T> getPropertyValues(Containerable c, String path)
-
getPropertyValue
public <T> T getPropertyValue(Containerable c, ItemPathType path) throws SchemaException
- Throws:
SchemaException
-
getPropertyValues
public <T> Collection<T> getPropertyValues(Containerable c, ItemPathType path)
-
getPropertyValue
public <T> T getPropertyValue(PrismContainerValue<?> pcv, String path) throws SchemaException
- Throws:
SchemaException
-
getPropertyValue
public <T> T getPropertyValue(PrismContainerValue<?> pcv, ItemPathType path) throws SchemaException
- Throws:
SchemaException
-
getPropertyValues
public <T> Collection<T> getPropertyValues(PrismContainerValue<?> pcv, String path)
-
getPropertyValues
public <T> Collection<T> getPropertyValues(PrismContainerValue<?> pcv, ItemPathType path)
-
getAttributeValues
public <T> Collection<T> getAttributeValues(ShadowType shadow, String attributeNamespace, String attributeLocalPart)
-
getAttributeValues
public <T> Collection<T> getAttributeValues(ShadowType shadow, String attributeLocalPart)
-
getAttributeValues
public <T> Collection<T> getAttributeValues(ShadowType shadow, groovy.xml.QName attributeQname)
-
getAttributeValues
public <T> Collection<T> getAttributeValues(ShadowType shadow, QName attributeQname)
-
getAttributeValue
public <T> T getAttributeValue(ShadowType shadow, String attributeNamespace, String attributeLocalPart) throws SchemaException
- Throws:
SchemaException
-
getAttributeValue
public <T> T getAttributeValue(ShadowType shadow, String attributeLocalPart) throws SchemaException
- Throws:
SchemaException
-
getAttributeValue
public <T> T getAttributeValue(ShadowType shadow, groovy.xml.QName attributeQname) throws SchemaException
- Throws:
SchemaException
-
getAttributeValue
public <T> T getAttributeValue(ShadowType shadow, QName attributeQname) throws SchemaException
- Throws:
SchemaException
-
getAttributeStringValues
public Collection<String> getAttributeStringValues(ShadowType shadow, String attributeNamespace, String attributeLocalPart)
-
getAttributeStringValues
public Collection<String> getAttributeStringValues(ShadowType shadow, groovy.xml.QName attributeQname)
-
getAttributeStringValues
public Collection<String> getAttributeStringValues(ShadowType shadow, QName attributeQname)
-
getMetadataValues
@Experimental @NotNull public @NotNull Collection<?> getMetadataValues(PrismValue value, Object... pathSegments)
Generic method to extract all metadata values pointed-to by given item path (specified as segments). Note: does not support multivalued containers withing the path (e.g. collecting transformation/source/name, where transformation/source is a multivalued container).
-
getMetadataValues
@Experimental @NotNull public @NotNull Collection<?> getMetadataValues(PrismValue value, String path)
-
getMetadataExtensionValues
@Experimental @NotNull public @NotNull Collection<?> getMetadataExtensionValues(PrismValue value, String itemLocalPart)
Simplified version of getMetadataValue aimed at fetching single-segment extension paths.
-
setExtensionRealValues
public void setExtensionRealValues(PrismContainerValue<?> containerValue, Map<String,Object> map) throws SchemaException
- Throws:
SchemaException
-
getIdentifierValue
public <T> T getIdentifierValue(ShadowType shadow) throws SchemaException
- Throws:
SchemaException
-
getSecondaryIdentifierValue
public <T> T getSecondaryIdentifierValue(ShadowType shadow) throws SchemaException
- Throws:
SchemaException
-
determineLdapSingleAttributeValue
public String determineLdapSingleAttributeValue(Collection<String> dns, String attributeName, PrismProperty attribute) throws NamingException
- Throws:
NamingException
-
getResourceIcfConfigurationPropertyValue
public <T> T getResourceIcfConfigurationPropertyValue(ResourceType resource, QName propertyQname) throws SchemaException
- Throws:
SchemaException
-
getResourceIcfConfigurationPropertyValue
public <T> T getResourceIcfConfigurationPropertyValue(ResourceType resource, String propertyLocalPart) throws SchemaException
- Throws:
SchemaException
-
determineLdapSingleAttributeValue
public String determineLdapSingleAttributeValue(Collection<String> dns, String attributeName, Collection<String> values) throws NamingException
- Throws:
NamingException
-
determineLdapSingleAttributeValue
public String determineLdapSingleAttributeValue(String dn, String attributeName, Collection<?> values) throws NamingException
- Throws:
NamingException
-
toSingle
public <T> T toSingle(Collection<T> values) throws SchemaException
- Throws:
SchemaException
-
readFile
public static String readFile(String filename) throws IOException
- Throws:
IOException
-
formatDateTime
public String formatDateTime(String format, XMLGregorianCalendar xmlCal)
-
parseDateTime
public XMLGregorianCalendar parseDateTime(String format, String stringDate) throws ParseException
- Throws:
ParseException
-
currentDateTime
public XMLGregorianCalendar currentDateTime()
-
fromNow
public XMLGregorianCalendar fromNow(String timeSpec)
-
addDuration
public XMLGregorianCalendar addDuration(XMLGregorianCalendar now, Duration duration)
-
addDuration
public XMLGregorianCalendar addDuration(XMLGregorianCalendar now, String duration)
-
addMillis
public XMLGregorianCalendar addMillis(XMLGregorianCalendar now, long duration)
-
roundDownToMidnight
public XMLGregorianCalendar roundDownToMidnight(XMLGregorianCalendar in)
-
roundUpToEndOfDay
public XMLGregorianCalendar roundUpToEndOfDay(XMLGregorianCalendar in)
-
longAgo
public XMLGregorianCalendar longAgo()
-
decrypt
public String decrypt(ProtectedStringType protectedString)
-
encrypt
public ProtectedStringType encrypt(String string)
-
composeDn
public static String composeDn(Object... components) throws InvalidNameException
Creates a valid LDAP distinguished name from the wide range of components. The method can be invoked in many ways, e.g.:composeDn("cn","foo","o","bar") composeDn("cn","foo",new Rdn("o","bar")) composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar")) composeDn(new Rdn("cn","foo"),"ou","baz","o","bar") composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar")) composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
Note: the DN is not normalized. The case of the attribute names and white spaces are preserved.
- Throws:
InvalidNameException
-
composeDnWithSuffix
public static String composeDnWithSuffix(Object... components) throws InvalidNameException
Creates a valid LDAP distinguished name from the wide range of components assuming that the last component is a suffix. The method can be invoked in many ways, e.g.:composeDn("cn","foo","o=bar") composeDn(new Rdn("cn","foo"),"ou=baz,o=bar") composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar")) composeDn("cn","foo",new LdapName("ou=baz,o=bar"))
The last element is a complete suffix represented either as String or LdapName.
Note: the DN is not normalized. The case of the attribute names and white spaces are preserved.
- Throws:
InvalidNameException
-
hashLdapPassword
public String hashLdapPassword(ProtectedStringType protectedString, String alg) throws NoSuchAlgorithmException, EncryptionException
Hashes cleartext password in an (unofficial) LDAP password format. Supported algorithms: SSHA, SHA and MD5.
-
hashLdapPassword
public String hashLdapPassword(String clearString, String alg) throws NoSuchAlgorithmException
Hashes cleartext password in an (unofficial) LDAP password format. Supported algorithms: SSHA, SHA and MD5.- Throws:
NoSuchAlgorithmException
-
hashLdapPassword
public String hashLdapPassword(byte[] clearBytes, String alg) throws NoSuchAlgorithmException
Hashes cleartext password in an (unofficial) LDAP password format. Supported algorithms: SSHA, SHA and MD5.- Throws:
NoSuchAlgorithmException
-
setTaskWorkerThreads
public void setTaskWorkerThreads(TaskType task, Integer value) throws SchemaException
- Throws:
SchemaException
-
-