Search in sources :

Example 46 with PolyString

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();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 47 with PolyString

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);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) Element(org.w3c.dom.Element) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 48 with PolyString

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;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 49 with PolyString

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();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 50 with PolyString

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();
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) InvalidNameException(javax.naming.InvalidNameException) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Rdn(javax.naming.ldap.Rdn) LinkedList(java.util.LinkedList) LdapName(javax.naming.ldap.LdapName)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8