Search in sources :

Example 86 with PrismPropertyValue

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

the class RObjectTextInfo method createItemsSet.

public static <T extends ObjectType> Set<RObjectTextInfo> createItemsSet(@NotNull ObjectType object, @NotNull RObject repo, @NotNull RepositoryContext repositoryContext) {
    FullTextSearchConfigurationType config = repositoryContext.repositoryService.getFullTextSearchConfiguration();
    if (!FullTextSearchConfigurationUtil.isEnabled(config)) {
        return Collections.emptySet();
    }
    Set<ItemPath> paths = FullTextSearchConfigurationUtil.getFullTextSearchItemPaths(config, object.getClass());
    List<PrismValue> values = new ArrayList<>();
    for (ItemPath path : paths) {
        Object o = object.asPrismObject().find(path);
        if (o == null) {
        // shouldn't occur
        } else if (o instanceof PrismValue) {
            values.add((PrismValue) o);
        } else if (o instanceof Item) {
            values.addAll(((Item<?, ?>) o).getValues());
        } else {
            throw new IllegalStateException("Unexpected value " + o + " in " + object + " at " + path);
        }
    }
    // not a (hash) set in order to preserve order
    List<String> allWords = new ArrayList<>();
    for (PrismValue value : values) {
        if (value == null) {
            continue;
        }
        if (value instanceof PrismPropertyValue) {
            Object realValue = value.getRealValue();
            if (realValue == null) {
            // skip
            } else if (realValue instanceof String) {
                append(allWords, (String) realValue, repositoryContext.prismContext);
            } else if (realValue instanceof PolyString) {
                append(allWords, (PolyString) realValue, repositoryContext.prismContext);
            } else {
                append(allWords, realValue.toString(), repositoryContext.prismContext);
            }
        }
    }
    LOGGER.trace("Indexing {}:\n  items: {}\n  values: {}\n  words:  {}", object, paths, values, allWords);
    return createItemsSet(repo, allWords);
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismValue(com.evolveum.midpoint.prism.PrismValue) Item(com.evolveum.midpoint.prism.Item) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 87 with PrismPropertyValue

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

the class SqlRepositoryServiceImpl method modifyObject.

@Override
public <T extends ObjectType> void modifyObject(Class<T> type, String oid, Collection<? extends ItemDelta> modifications, RepoModifyOptions options, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException {
    Validate.notNull(modifications, "Modifications must not be null.");
    Validate.notNull(type, "Object class in delta must not be null.");
    Validate.notEmpty(oid, "Oid must not null or empty.");
    Validate.notNull(result, "Operation result must not be null.");
    OperationResult subResult = result.createSubresult(MODIFY_OBJECT);
    subResult.addParam("type", type.getName());
    subResult.addParam("oid", oid);
    subResult.addCollectionOfSerializablesAsParam("modifications", modifications);
    if (modifications.isEmpty() && !RepoModifyOptions.isExecuteIfNoChanges(options)) {
        LOGGER.debug("Modification list is empty, nothing was modified.");
        subResult.recordStatus(OperationResultStatus.SUCCESS, "Modification list is empty, nothing was modified.");
        return;
    }
    if (InternalsConfig.encryptionChecks) {
        CryptoUtil.checkEncrypted(modifications);
    }
    if (InternalsConfig.consistencyChecks) {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.THOROUGH);
    } else {
        ItemDelta.checkConsistence(modifications, ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
    }
    if (LOGGER.isTraceEnabled()) {
        for (ItemDelta modification : modifications) {
            if (modification instanceof PropertyDelta<?>) {
                PropertyDelta<?> propDelta = (PropertyDelta<?>) modification;
                if (propDelta.getPath().equivalent(new ItemPath(ObjectType.F_NAME))) {
                    Collection<PrismPropertyValue<PolyString>> values = propDelta.getValues(PolyString.class);
                    for (PrismPropertyValue<PolyString> pval : values) {
                        PolyString value = pval.getValue();
                        LOGGER.trace("NAME delta: {} - {}", value.getOrig(), value.getNorm());
                    }
                }
            }
        }
    }
    final String operation = "modifying";
    int attempt = 1;
    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("modifyObject");
    try {
        while (true) {
            try {
                objectUpdater.modifyObjectAttempt(type, oid, modifications, options, subResult);
                return;
            } catch (RuntimeException ex) {
                attempt = baseHelper.logOperationAttempt(oid, operation, attempt, ex, subResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 88 with PrismPropertyValue

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

the class SimpleSmsTransport method evaluateExpression.

private String evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_STRING, prismContext);
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    if (exprResult.getZeroSet().size() != 1) {
        throw new SystemException("Invalid number of return values (" + exprResult.getZeroSet().size() + "), expected 1.");
    }
    return exprResult.getZeroSet().iterator().next().getValue();
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 89 with PrismPropertyValue

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

the class BaseHandler method evaluateBooleanExpression.

protected boolean evaluateBooleanExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl<>(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
    Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
    if (exprResult.size() == 0) {
        return false;
    } else if (exprResult.size() > 1) {
        throw new IllegalStateException("Filter expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
    }
    Boolean boolResult = exprResult.iterator().next().getValue();
    return boolResult != null ? boolResult : false;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 90 with PrismPropertyValue

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

the class TaskQuartzImpl method setExtensionPropertyValueTransient.

@Override
public <T> void setExtensionPropertyValueTransient(QName propertyName, T value) throws SchemaException {
    PrismPropertyDefinition propertyDef = getPrismContext().getSchemaRegistry().findPropertyDefinitionByElementName(propertyName);
    if (propertyDef == null) {
        throw new SchemaException("Unknown property " + propertyName);
    }
    ArrayList<PrismPropertyValue<T>> values = new ArrayList(1);
    if (value != null) {
        values.add(new PrismPropertyValue<T>(value));
    }
    ItemDelta delta = new PropertyDelta(new ItemPath(TaskType.F_EXTENSION, propertyName), propertyDef, getPrismContext());
    delta.setValuesToReplace(values);
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>(1);
    modifications.add(delta);
    PropertyDelta.applyTo(modifications, taskPrism);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) F_WORKFLOW_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT) F_MODEL_OPERATION_CONTEXT(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_MODEL_OPERATION_CONTEXT) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8