use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class PrismAsserts method assertHasTargetName.
public static void assertHasTargetName(PrismContainerValue<?> pcv, ItemPath path) {
for (PrismValue value : getValues(pcv, path)) {
PrismReferenceValue prv = (PrismReferenceValue) value;
assertHasTargetName(prv);
}
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class PrismAsserts method assertHasNoTargetName.
public static void assertHasNoTargetName(PrismContainerValue<?> pcv, ItemPath path) {
for (PrismValue value : getValues(pcv, path)) {
PrismReferenceValue prv = (PrismReferenceValue) value;
assertHasNoTargetName(prv);
}
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class LazyXPathVariableResolver method convertToXml.
// May return primitive types or DOM Node
public static Object convertToXml(Object variableValue, QName variableName, final PrismContext prismContext, String contextDescription) throws SchemaException {
try {
if (variableValue instanceof Objectable) {
variableValue = ((Objectable) variableValue).asPrismObject();
}
if (variableValue instanceof PrismObject) {
PrismObject<?> prismObject = (PrismObject<?>) variableValue;
variableValue = prismObject.getPrismContext().domSerializer().serialize(prismObject);
} else if (variableValue instanceof PrismProperty<?>) {
PrismProperty<?> prismProperty = (PrismProperty<?>) variableValue;
final List<Element> elementList = new ArrayList<Element>();
for (PrismPropertyValue<?> value : prismProperty.getValues()) {
Element valueElement = prismContext.domSerializer().serialize(value, prismProperty.getElementName());
elementList.add(valueElement);
}
NodeList nodeList = new AdHocNodeList(elementList);
variableValue = nodeList;
} else if (variableValue instanceof PrismValue) {
PrismValue pval = (PrismValue) variableValue;
if (pval.getParent() == null) {
// Set a fake parent to allow serialization
pval.setParent(new AdHocItemable(prismContext));
}
variableValue = prismContext.domSerializer().serialize(pval, variableName);
}
if (!((variableValue instanceof Node) || variableValue instanceof NodeList) && !(variableValue.getClass().getPackage().getName().startsWith("java."))) {
throw new SchemaException("Unable to convert value of variable " + variableName + " to XML, still got " + variableValue.getClass().getName() + ":" + variableValue + " value at the end");
}
return variableValue;
} catch (SchemaException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new SchemaException(e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
} catch (RuntimeException e) {
if (variableValue != null && variableValue instanceof DebugDumpable) {
LOGGER.trace("Value of variable {}:\n{}", variableName, ((DebugDumpable) variableValue).debugDump());
}
throw new RuntimeException(e.getClass().getName() + ": " + e.getMessage() + " while processing variable " + variableName + " with value " + variableValue + " in " + contextDescription, e);
}
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class MappingEvaluator method computeTargetValues.
private <V extends PrismValue, F extends FocusType> Collection<V> computeTargetValues(VariableBindingDefinitionType target, Object defaultTargetContext, ExpressionVariables variables, ObjectResolver objectResolver, String contextDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
if (target == null) {
// Is this correct? What about default targets?
return null;
}
ItemPathType itemPathType = target.getPath();
if (itemPathType == null) {
// Is this correct? What about default targets?
return null;
}
ItemPath path = itemPathType.getItemPath();
Object object = ExpressionUtil.resolvePath(path, variables, defaultTargetContext, objectResolver, contextDesc, task, result);
if (object == null) {
return new ArrayList<>();
} else if (object instanceof Item) {
return ((Item) object).getValues();
} else if (object instanceof PrismValue) {
return (List<V>) Collections.singletonList((PrismValue) object);
} else if (object instanceof ItemDeltaItem) {
ItemDeltaItem<V, ?> idi = (ItemDeltaItem<V, ?>) object;
PrismValueDeltaSetTriple<V> triple = idi.toDeltaSetTriple();
return triple != null ? triple.getNonNegativeValues() : new ArrayList<V>();
} else {
throw new IllegalStateException("Unsupported target value(s): " + object.getClass() + " (" + object + ")");
}
}
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);
}
}
Aggregations