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);
}
}
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;
}
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));
}
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;
}
}
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);
}
Aggregations