Search in sources :

Example 11 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)

Example 12 with PrismValue

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

the class ValueOperation method convertValues.

private <T> Collection<Object> convertValues(QName propName, List<PrismPropertyValue<T>> values) throws SchemaException {
    if (values == null) {
        return null;
    }
    Collection<Object> convertedValues = new ArrayList<>();
    for (PrismValue value : values) {
        Object converted = ConnIdUtil.convertValueToIcf(value, null, propName);
        convertedValues.add(converted);
    }
    return convertedValues;
}
Also used : ArrayList(java.util.ArrayList) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 13 with PrismValue

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

the class TestUserTemplate method test160ModifyUserGivenNameAgain.

@Test
public void test160ModifyUserGivenNameAgain() throws Exception {
    TestUtil.displayTestTile(this, "test160ModifyUserGivenNameAgain");
    // GIVEN
    Task task = taskManager.createTaskInstance(TestUserTemplate.class.getName() + ".test160ModifyUserGivenNameAgain");
    OperationResult result = task.getResult();
    dummyAuditService.clear();
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_GIVEN_NAME, prismContext, new PolyString("JACKIE"));
    deltas.add(userDelta);
    // WHEN
    modelService.executeChanges(deltas, null, task, result);
    // THEN
    PrismObject<UserType> userJack = modelService.getObject(UserType.class, USER_JACK_OID, null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismAsserts.assertPropertyValue(userJack.findContainer(UserType.F_EXTENSION), PIRACY_BAD_LUCK, 123L);
    display("Audit", dummyAuditService);
    dummyAuditService.assertRecords(2);
    dummyAuditService.assertSimpleRecordSanity();
    dummyAuditService.assertAnyRequestDeltas();
    dummyAuditService.assertExecutionDeltas(2);
    dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
    dummyAuditService.assertTarget(USER_JACK_OID);
    dummyAuditService.assertExecutionSuccess();
    ObjectDeltaOperation<?> objectDeltaOperation = dummyAuditService.getExecutionDelta(0, ChangeType.MODIFY, UserType.class);
    // givenName + badLuck + modifyTimestamp
    assertEquals("unexpected number of modifications in audited delta", 4, objectDeltaOperation.getObjectDelta().getModifications().size());
    PropertyDelta badLuckDelta = objectDeltaOperation.getObjectDelta().findPropertyDelta(new ItemPath(UserType.F_EXTENSION, PIRACY_BAD_LUCK));
    assertNotNull("badLuck delta was not found", badLuckDelta);
    List<PrismValue> oldValues = (List<PrismValue>) badLuckDelta.getEstimatedOldValues();
    assertNotNull("badLuck delta has null estimatedOldValues field", oldValues);
    PrismAsserts.assertEqualsCollectionUnordered("badLuck delta has wrong estimatedOldValues", oldValues, new PrismPropertyValue<Long>(123L), new PrismPropertyValue<Long>(456L));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) List(java.util.List) ArrayList(java.util.ArrayList) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with PrismValue

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

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 15 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue 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)

Aggregations

PrismValue (com.evolveum.midpoint.prism.PrismValue)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)8 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)8 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 Item (com.evolveum.midpoint.prism.Item)6 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)6 ArrayList (java.util.ArrayList)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)5 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 QName (javax.xml.namespace.QName)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)2 Objectable (com.evolveum.midpoint.prism.Objectable)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2