use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class PrismObject method getNamePropertyStringValue.
private String getNamePropertyStringValue() {
PrismProperty<PolyString> nameProperty = getNameProperty();
if (nameProperty == null) {
return null;
}
PolyString realValue = nameProperty.getRealValue();
if (realValue == null) {
return null;
}
return realValue.getOrig();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class XPathScriptEvaluator method convertScalar.
/*
if (type.equals(String.class))
{
return XPathConstants.STRING;
}
if (type.equals(Double.class) || type.equals(double.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Integer.class) || type.equals(int.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Long.class) || type.equals(long.class)) {
return XPathConstants.NUMBER;
}
if (type.equals(Boolean.class) || type.equals(boolean.class)) {
return XPathConstants.BOOLEAN;
}
if (type.equals(NodeList.class)) {
if (expressionType.getReturnType() == ScriptExpressionReturnTypeType.SCALAR) {
// FIXME: is this OK?
return XPathConstants.STRING;
} else {
return XPathConstants.NODESET;
}
}
if (type.equals(Node.class)) {
return XPathConstants.NODE;
}
if (type.equals(PolyString.class) || type.equals(PolyStringType.class)) {
return XPathConstants.STRING;
}
throw new ExpressionEvaluationException("Unsupported return type " + type);
}
*/
private <T, V extends PrismValue> V convertScalar(Class<T> type, QName returnType, Object value, String contextDescription) throws ExpressionEvaluationException {
if (value instanceof ObjectReferenceType) {
return (V) ((ObjectReferenceType) value).asReferenceValue();
}
if (type.isAssignableFrom(value.getClass())) {
return (V) new PrismPropertyValue<T>((T) value);
}
try {
T resultValue = null;
if (value instanceof String) {
resultValue = XmlTypeConverter.toJavaValue((String) value, type);
} else if (value instanceof Boolean) {
resultValue = (T) value;
} else if (value instanceof Element) {
resultValue = XmlTypeConverter.convertValueElementAsScalar((Element) value, type);
} else {
throw new ExpressionEvaluationException("Unexpected scalar return type " + value.getClass().getName());
}
if (returnType.equals(PrismConstants.POLYSTRING_TYPE_QNAME) && resultValue instanceof String) {
resultValue = (T) new PolyString((String) resultValue);
}
PrismUtil.recomputeRealValue(resultValue, prismContext);
return (V) new PrismPropertyValue<T>(resultValue);
} catch (SchemaException e) {
throw new ExpressionEvaluationException("Error converting result of " + contextDescription + ": " + e.getMessage(), e);
} catch (IllegalArgumentException e) {
throw new ExpressionEvaluationException("Error converting result of " + contextDescription + ": " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class AbstractValueTransformationExpressionEvaluator method evaluateScriptExpression.
private Collection<V> evaluateScriptExpression(Collection<Source<?, ?>> sources, ExpressionVariables variables, String contextDescription, boolean useNew, ExpressionEvaluationContext params, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
ExpressionVariables scriptVariables = new ExpressionVariables();
if (useNew) {
scriptVariables.addVariableDefinitionsNew(variables);
} else {
scriptVariables.addVariableDefinitionsOld(variables);
}
if (sources != null) {
// Add sources to variables
for (Source<?, ?> source : sources) {
LOGGER.trace("source: {}", source);
QName name = source.getName();
if (name == null) {
if (sources.size() == 1) {
name = ExpressionConstants.VAR_INPUT;
} else {
throw new ExpressionSyntaxException("No name definition for source in " + contextDescription);
}
}
Object value = null;
if (useNew) {
value = getRealContent(source.getItemNew(), source.getResidualPath());
} else {
value = getRealContent(source.getItemOld(), source.getResidualPath());
}
scriptVariables.addVariableDefinition(name, value);
}
}
List<V> scriptResults = transformSingleValue(scriptVariables, null, useNew, params, (useNew ? "(new) " : "(old) ") + contextDescription, task, result);
if (scriptResults == null || scriptResults.isEmpty()) {
return null;
}
Collection<V> outputSet = new ArrayList<V>(scriptResults.size());
for (V pval : scriptResults) {
if (pval instanceof PrismPropertyValue<?>) {
if (((PrismPropertyValue<?>) pval).getValue() == null) {
continue;
}
Object realValue = ((PrismPropertyValue<?>) pval).getValue();
if (realValue instanceof String) {
if (((String) realValue).isEmpty()) {
continue;
}
}
if (realValue instanceof PolyString) {
if (((PolyString) realValue).isEmpty()) {
continue;
}
}
}
outputSet.add(pval);
}
return outputSet;
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class BasicExpressionFunctions method norm.
/**
* Normalize a string value. It follows the default normalization algorithm
* used for PolyString values.
*
* @param orig original value to normalize
* @return normalized value
*/
public String norm(String orig) {
if (orig == null) {
return null;
}
PolyString polyString = new PolyString(orig);
polyString.recompute(prismContext.getDefaultPolyStringNormalizer());
return polyString.getNorm();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class BasicExpressionFunctions method composeDn.
/**
* 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.
*/
public static String composeDn(Object... components) throws InvalidNameException {
if (components == null) {
return null;
}
if (components.length == 0) {
return null;
}
if (components.length == 1 && components[0] == null) {
return null;
}
if (components.length == 1 && (components[0] instanceof String) && StringUtils.isBlank((String) (components[0]))) {
return null;
}
LinkedList<Rdn> rdns = new LinkedList<>();
String attrName = null;
for (Object component : components) {
if (attrName != null && !(component instanceof String || component instanceof PolyString || component instanceof PolyStringType)) {
throw new InvalidNameException("Invalid input to composeDn() function: expected string after '" + attrName + "' argument, but got " + component.getClass());
}
if (component instanceof Rdn) {
rdns.addFirst((Rdn) component);
} else if (component instanceof PolyString) {
component = ((PolyString) component).toString();
} else if (component instanceof PolyStringType) {
component = ((PolyStringType) component).toString();
}
if (component instanceof String) {
if (attrName == null) {
attrName = (String) component;
} else {
rdns.addFirst(new Rdn(attrName, (String) component));
attrName = null;
}
}
if (component instanceof LdapName) {
rdns.addAll(0, ((LdapName) component).getRdns());
}
}
LdapName dn = new LdapName(rdns);
return dn.toString();
}
Aggregations