Search in sources :

Example 1 with PopulateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType in project midpoint by Evolveum.

the class AbstractSearchExpressionEvaluator method transformSingleValue.

@Override
protected List<V> transformSingleValue(ExpressionVariables variables, PlusMinusZero valueDestination, boolean useNew, ExpressionEvaluationContext context, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    //		if (LOGGER.isTraceEnabled()) {
    //			LOGGER.trace("transformSingleValue in {}\nvariables:\n{}\nvalueDestination: {}\nuseNew: {}",
    //					new Object[]{contextDescription, variables.debugDump(1), valueDestination, useNew});
    //		}
    QName targetTypeQName = getExpressionEvaluatorType().getTargetType();
    if (targetTypeQName == null) {
        targetTypeQName = getDefaultTargetType();
    }
    if (targetTypeQName != null && QNameUtil.isUnqualified(targetTypeQName)) {
        targetTypeQName = getPrismContext().getSchemaRegistry().resolveUnqualifiedTypeName(targetTypeQName);
    }
    ObjectTypes targetType = ObjectTypes.getObjectTypeFromTypeQName(targetTypeQName);
    if (targetType == null) {
        throw new SchemaException("Unknown target type " + targetTypeQName + " in " + shortDebugDump());
    }
    Class<? extends ObjectType> targetTypeClass = targetType.getClassDefinition();
    List<V> resultValues = null;
    ObjectQuery query = null;
    List<ItemDelta<V, D>> additionalAttributeDeltas = null;
    PopulateType populateAssignmentType = getExpressionEvaluatorType().getPopulate();
    if (populateAssignmentType != null) {
        additionalAttributeDeltas = collectAdditionalAttributes(populateAssignmentType, outputDefinition, variables, context, contextDescription, task, result);
    }
    if (getExpressionEvaluatorType().getOid() != null) {
        resultValues = new ArrayList<>(1);
        resultValues.add(createPrismValue(getExpressionEvaluatorType().getOid(), targetTypeQName, additionalAttributeDeltas, context));
    } else {
        SearchFilterType filterType = getExpressionEvaluatorType().getFilter();
        if (filterType == null) {
            throw new SchemaException("No filter in " + shortDebugDump());
        }
        query = QueryJaxbConvertor.createObjectQuery(targetTypeClass, filterType, prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("XML query converted to: {}", query.debugDump());
        }
        query = ExpressionUtil.evaluateQueryExpressions(query, variables, context.getExpressionFactory(), prismContext, context.getContextDescription(), task, result);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Expression in query evaluated to: {}", query.debugDump());
        }
        query = extendQuery(query, context);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Query after extension: {}", query.debugDump());
        }
        resultValues = executeSearchUsingCache(targetTypeClass, targetTypeQName, query, additionalAttributeDeltas, context, contextDescription, task, context.getResult());
        if (resultValues.isEmpty()) {
            ObjectReferenceType defaultTargetRef = getExpressionEvaluatorType().getDefaultTargetRef();
            if (defaultTargetRef != null) {
                resultValues.add(createPrismValue(defaultTargetRef.getOid(), targetTypeQName, additionalAttributeDeltas, context));
            }
        }
    }
    if (resultValues.isEmpty() && getExpressionEvaluatorType().isCreateOnDemand() == Boolean.TRUE && (valueDestination == PlusMinusZero.PLUS || valueDestination == PlusMinusZero.ZERO || useNew)) {
        String createdObjectOid = createOnDemand(targetTypeClass, variables, context, context.getContextDescription(), task, context.getResult());
        resultValues.add(createPrismValue(createdObjectOid, targetTypeQName, additionalAttributeDeltas, context));
    }
    LOGGER.trace("Search expression got {} results for query {}", resultValues == null ? "null" : resultValues.size(), query);
    return (List<V>) resultValues;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) List(java.util.List) ArrayList(java.util.ArrayList) PopulateType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)

Example 2 with PopulateType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType in project midpoint by Evolveum.

the class AbstractSearchExpressionEvaluator method createOnDemand.

private <O extends ObjectType> String createOnDemand(Class<O> targetTypeClass, ExpressionVariables variables, ExpressionEvaluationContext params, String contextDescription, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Going to create assignment targets on demand, variables:\n{}", variables.formatVariables());
    }
    PrismObjectDefinition<O> objectDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(targetTypeClass);
    PrismObject<O> newObject = objectDefinition.instantiate();
    PopulateType populateObject = getExpressionEvaluatorType().getPopulateObject();
    if (populateObject == null) {
        LOGGER.warn("No populateObject in assignment expression in {}, " + "object created on demand will be empty. Subsequent operations will most likely fail", contextDescription);
    } else {
        for (PopulateItemType populateItem : populateObject.getPopulateItem()) {
            ItemDelta<?, ?> itemDelta = evaluatePopulateExpression(populateItem, variables, params, objectDefinition, contextDescription, true, task, result);
            if (itemDelta != null) {
                itemDelta.applyTo(newObject);
            }
        }
    }
    LOGGER.debug("Creating object on demand from {}: {}", contextDescription, newObject);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Creating object on demand:\n{}", newObject.debugDump());
    }
    ObjectDelta<O> addDelta = newObject.createAddDelta();
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(addDelta);
    try {
        modelService.executeChanges(deltas, null, task, result);
    } catch (ObjectAlreadyExistsException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
        throw new ExpressionEvaluationException(e.getMessage(), e);
    }
    return addDelta.getOid();
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PopulateItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) PopulateType(com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)

Aggregations

PopulateType (com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateType)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 PopulateItemType (com.evolveum.midpoint.xml.ns._public.common.common_3.PopulateItemType)1 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1