Search in sources :

Example 1 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class PrismAsserts method assertHasTargetName.

public static void assertHasTargetName(PrismContainerValue<?> pcv, ItemPath path) {
    for (PrismValue value : getValues(pcv, path)) {
        PrismReferenceValue prv = (PrismReferenceValue) value;
        assertHasTargetName(prv);
    }
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 2 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class PrismAsserts method assertHasNoTargetName.

public static void assertHasNoTargetName(PrismContainerValue<?> pcv, ItemPath path) {
    for (PrismValue value : getValues(pcv, path)) {
        PrismReferenceValue prv = (PrismReferenceValue) value;
        assertHasNoTargetName(prv);
    }
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 3 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class LazyXPathVariableResolver method convertToXml.

// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
    try {
        if (variableValue instanceof Objectable) {
            variableValue = ((Objectable) variableValue).asPrismObject();
        }
        if (variableValue instanceof PrismObject) {
            PrismObject<?> prismObject = (PrismObject<?>) variableValue;
            variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
        } else if (variableValue instanceof PrismProperty<?>) {
            PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
            final List<Element> elementList = new ArrayList<Element>();
            for (PrismPropertyValue<?> value : prismProperty.getValues()) {
                Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
                elementList.add(valueElement);
            }
            NodeList nodeList = new AdHocNodeList(elementList);
            variableValue = nodeList;
        } else if (variableValue instanceof PrismValue) {
            PrismValue pval = (PrismValue) variableValue;
            if (pval.getParent() == null) {
                // Set a fake parent to allow serialization
                pval.setParent(new AdHocItemable(prismContext));
            }
            variableValue = prismContext.domSerializer().serialize(pval, variableName);
        }
        if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
            throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
        }
        return variableValue;
    } catch (SchemaException e) {
        if (variableValue != null && variableValue instanceof DebugDumpable) {
            LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
        }
        throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
    } catch (RuntimeException e) {
        if (variableValue != null && variableValue instanceof DebugDumpable) {
            LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
        }
        throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) Objectable(com.evolveum.midpoint.prism.Objectable) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 4 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class MappingEvaluator method computeTargetValues.

private <V extends PrismValue, F extends FocusType> Collection<V> computeTargetValues(VariableBindingDefinitionType target, Object defaultTargetContext, ExpressionVariables variables, ObjectResolver objectResolver, String contextDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    if (target == null) {
        // Is this correct? What about default targets?
        return null;
    }
    ItemPathType itemPathType = target.getPath();
    if (itemPathType == null) {
        // Is this correct? What about default targets?
        return null;
    }
    ItemPath path = itemPathType.getItemPath();
    Object object = ExpressionUtil.resolvePath(path, variables, defaultTargetContext, objectResolver, contextDesc, task, result);
    if (object == null) {
        return new ArrayList<>();
    } else if (object instanceof Item) {
        return ((Item) object).getValues();
    } else if (object instanceof PrismValue) {
        return (List<V>) Collections.singletonList((PrismValue) object);
    } else if (object instanceof ItemDeltaItem) {
        ItemDeltaItem<V, ?> idi = (ItemDeltaItem<V, ?>) object;
        PrismValueDeltaSetTriple<V> triple = idi.toDeltaSetTriple();
        return triple != null ? triple.getNonNegativeValues() : new ArrayList<V>();
    } else {
        throw new IllegalStateException("Unsupported target value(s): " + object.getClass() + " (" + object + ")");
    }
}
Also used : Item(com.evolveum.midpoint.prism.Item) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class ShadowManager method processQueryMatchingRuleFilter.

private <T> void processQueryMatchingRuleFilter(ObjectFilter filter, RefinedObjectClassDefinition objectClassDef) throws SchemaException {
    if (!(filter instanceof EqualFilter)) {
        return;
    }
    EqualFilter<T> eqFilter = (EqualFilter) filter;
    ItemPath parentPath = eqFilter.getParentPath();
    if (parentPath == null || !parentPath.equivalent(SchemaConstants.PATH_ATTRIBUTES)) {
        return;
    }
    QName attrName = eqFilter.getElementName();
    RefinedAttributeDefinition rAttrDef = objectClassDef.findAttributeDefinition(attrName);
    if (rAttrDef == null) {
        throw new SchemaException("Unknown attribute " + attrName + " in filter " + filter);
    }
    QName matchingRuleQName = rAttrDef.getMatchingRuleQName();
    if (matchingRuleQName == null) {
        return;
    }
    Class<?> valueClass = null;
    MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, rAttrDef.getTypeName());
    List<PrismValue> newValues = new ArrayList<PrismValue>();
    if (eqFilter.getValues() != null) {
        for (PrismPropertyValue<T> ppval : eqFilter.getValues()) {
            T normalizedRealValue = matchingRule.normalize(ppval.getValue());
            PrismPropertyValue<T> newPPval = ppval.clone();
            newPPval.setValue(normalizedRealValue);
            newValues.add(newPPval);
            if (normalizedRealValue != null) {
                valueClass = normalizedRealValue.getClass();
            }
        }
        eqFilter.getValues().clear();
        eqFilter.getValues().addAll((Collection) newValues);
        LOGGER.trace("Replacing values for attribute {} in search filter with normalized values because there is a matching rule, normalized values: {}", attrName, newValues);
    }
    if (eqFilter.getMatchingRule() == null) {
        QName supportedMatchingRule = valueClass != null ? repositoryService.getApproximateSupportedMatchingRule(valueClass, matchingRuleQName) : matchingRuleQName;
        eqFilter.setMatchingRule(supportedMatchingRule);
        LOGGER.trace("Setting matching rule to {} (supported by repo as a replacement for {} to search for {})", supportedMatchingRule, matchingRuleQName, valueClass);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PrismValue(com.evolveum.midpoint.prism.PrismValue) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismValue (com.evolveum.midpoint.prism.PrismValue)49 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)15 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)8 Item (com.evolveum.midpoint.prism.Item)7 ArrayList (java.util.ArrayList)7 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)6 QName (javax.xml.namespace.QName)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)4 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)4 MapperContext (com.evolveum.midpoint.repo.sql.helpers.modify.MapperContext)4 SystemException (com.evolveum.midpoint.util.exception.SystemException)4 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)2 Objectable (com.evolveum.midpoint.prism.Objectable)2 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)2