Search in sources :

Example 36 with PrismValue

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

the class ObjectFilterAsserter method assertEq.

public ObjectFilterAsserter<RA> assertEq(ItemPath expectedItemPath, Object expectedValue) {
    assertClass(EqualFilter.class);
    ItemPath actualItemPath = ((EqualFilter) filter).getPath();
    AssertJUnit.assertTrue("Wrong path in eq clause, expected " + expectedItemPath + ", but was " + actualItemPath + "; in " + desc(), expectedItemPath.equivalent(actualItemPath));
    PrismValue actualPVal = ((EqualFilter) filter).getSingleValue();
    Object actualValue = actualPVal.getRealValue();
    AssertJUnit.assertTrue("Wrong value in eq clause, expected " + expectedValue + ", but was " + actualValue + "; in " + desc(), expectedValue.equals(actualValue));
    return this;
}
Also used : EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 37 with PrismValue

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

the class AuditHelper method evaluateRecordingExpression.

public <F extends ObjectType> AuditEventRecord evaluateRecordingExpression(ExpressionType expression, AuditEventRecord auditRecord, PrismObject<? extends ObjectType> primaryObject, ModelContext<F> context, Task task, OperationResult parentResult) {
    OperationResult result = parentResult.createMinorSubresult(OP_EVALUATE_RECORDING_SCRIPT);
    try {
        VariablesMap variables = new VariablesMap();
        variables.put(ExpressionConstants.VAR_TARGET, primaryObject, PrismObject.class);
        variables.put(ExpressionConstants.VAR_AUDIT_RECORD, auditRecord, AuditEventRecord.class);
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(context, null, task, result));
        try {
            PrismValue returnValue = ExpressionUtil.evaluateExpression(variables, null, expression, context != null ? context.getPrivilegedExpressionProfile() : null, expressionFactory, OP_EVALUATE_RECORDING_SCRIPT, task, result);
            return returnValue != null ? (AuditEventRecord) returnValue.getRealValue() : null;
        } finally {
            ModelExpressionThreadLocalHolder.popExpressionEnvironment();
        }
    } catch (Throwable t) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't evaluate audit recording expression", t);
        // Copied from evaluateAuditRecordProperty: Intentionally not throwing the exception. The error is marked as partial.
        // (It would be better to mark it as fatal and to derive overall result as partial, but we aren't that far yet.)
        result.recordPartialError(t);
    } finally {
        result.recordSuccessIfUnknown();
    }
    // modified by some part of the script too - this we have to suffer.
    return auditRecord;
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 38 with PrismValue

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

the class TransformationBuiltinMapping method markNotTransient.

/**
 * The value can contain transient values e.g. because during its computation the transformation metadata was
 * marked as transient. But there can be situations when transformation metadata for the current value are
 * non-transient. Then we could want to store them completely, i.e. with transformation metadata of source values.
 * So we must mark them as not transient.
 */
private void markNotTransient(PrismValue rootValue) {
    rootValue.accept(visitable -> {
        if (visitable instanceof PrismValue) {
            PrismValue value = (PrismValue) visitable;
            value.setTransient(false);
            value.getValueMetadataAsContainer().valuesStream().forEach(this::markNotTransient);
        }
    });
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 39 with PrismValue

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

the class CaseExpressionEvaluationHelper method evaluateExpression.

@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, VariablesMap variables, String contextDescription, Class<T> clazz, QName typeName, boolean multiValued, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    MutableItemDefinition<?> resultDef;
    ItemName resultName = new ItemName(SchemaConstants.NS_C, "result");
    if (QNameUtil.match(typeName, ObjectReferenceType.COMPLEX_TYPE)) {
        resultDef = prismContext.definitionFactory().createReferenceDefinition(resultName, typeName);
    } else {
        resultDef = prismContext.definitionFactory().createPropertyDefinition(resultName, typeName);
    }
    if (multiValued) {
        resultDef.setMaxOccurs(-1);
    }
    Expression<?, ?> expression = expressionFactory.makeExpression(expressionType, resultDef, MiscSchemaUtil.getExpressionProfile(), contextDescription, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task);
    context.setAdditionalConvertor(additionalConvertor);
    PrismValueDeltaSetTriple<?> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateAnyExpressionInContext(expression, context, task, result);
    List<T> list = new ArrayList<>();
    for (PrismValue pv : exprResultTriple.getZeroSet()) {
        T realValue;
        if (pv instanceof PrismReferenceValue) {
            // pv.getRealValue sometimes returns synthesized Referencable, not ObjectReferenceType
            // If we would stay with that we would need to make many changes throughout workflow module.
            // So it is safer to stay with ObjectReferenceType.
            ObjectReferenceType ort = new ObjectReferenceType();
            ort.setupReferenceValue((PrismReferenceValue) pv);
            realValue = (T) ort;
        } else {
            realValue = pv.getRealValue();
        }
        list.add(realValue);
    }
    return list;
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ArrayList(java.util.ArrayList) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismValue(com.evolveum.midpoint.prism.PrismValue) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with PrismValue

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

the class CredentialPolicyEvaluator method hasValueDelta.

private boolean hasValueDelta(ObjectDelta<F> focusDelta, ItemPath credentialsPath) {
    if (focusDelta == null) {
        return false;
    }
    for (PartiallyResolvedDelta<PrismValue, ItemDefinition> partialDelta : focusDelta.findPartial(credentialsPath)) {
        LOGGER.trace("Residual delta:\n{}", partialDelta.debugDumpLazily());
        ItemPath residualPath = partialDelta.getResidualPath();
        if (ItemPath.isEmpty(residualPath)) {
            continue;
        }
        LOGGER.trace("PATH: {}", residualPath);
        ItemName name = residualPath.firstName();
        LOGGER.trace("NAME: {}", name);
        if (isValueElement(name)) {
            return true;
        }
    }
    return false;
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemName(com.evolveum.midpoint.prism.path.ItemName) PrismValue(com.evolveum.midpoint.prism.PrismValue) 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