use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class PrismAsserts method assertNoEmptyItem.
public static void assertNoEmptyItem(PrismContainer<?> container) {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if (visitable != null && visitable instanceof Item) {
assertNotEmpty((Item<?, ?>) visitable);
}
}
};
container.accept(visitor);
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class PathExpressionEvaluator method evaluate.
/* (non-Javadoc)
* @see com.evolveum.midpoint.common.expression.ExpressionEvaluator#evaluate(java.util.Collection, java.util.Map, boolean, java.lang.String, com.evolveum.midpoint.schema.result.OperationResult)
*/
@Override
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ItemDeltaItem<?, ?> resolveContext = null;
if (context.getSources() != null && context.getSources().size() == 1) {
Source<?, ?> source = context.getSources().iterator().next();
if (path.isEmpty()) {
PrismValueDeltaSetTriple<V> outputTriple = (PrismValueDeltaSetTriple<V>) source.toDeltaSetTriple();
return outputTriple.clone();
}
resolveContext = source;
}
Map<QName, Object> variablesAndSources = ExpressionUtil.compileVariablesAndSources(context);
ItemPath resolvePath = path;
ItemPathSegment first = path.first();
if (first instanceof NameItemPathSegment && first.isVariable()) {
QName variableName = ((NameItemPathSegment) first).getName();
Object variableValue;
if (variablesAndSources.containsKey(variableName)) {
variableValue = variablesAndSources.get(variableName);
} else if (QNameUtil.matchAny(variableName, variablesAndSources.keySet())) {
QName fullVariableName = QNameUtil.resolveNs(variableName, variablesAndSources.keySet());
variableValue = variablesAndSources.get(fullVariableName);
} else {
throw new ExpressionEvaluationException("No variable with name " + variableName + " in " + context.getContextDescription());
}
if (variableValue == null) {
return null;
}
if (variableValue instanceof Item || variableValue instanceof ItemDeltaItem<?, ?>) {
resolveContext = ExpressionUtil.toItemDeltaItem(variableValue, objectResolver, "path expression in " + context.getContextDescription(), context.getResult());
} else if (variableValue instanceof PrismPropertyValue<?>) {
PrismValueDeltaSetTriple<V> outputTriple = new PrismValueDeltaSetTriple<>();
outputTriple.addToZeroSet((V) variableValue);
return ExpressionUtil.toOutputTriple(outputTriple, outputDefinition, context.getAdditionalConvertor(), null, protector, prismContext);
} else {
throw new ExpressionEvaluationException("Unexpected variable value " + variableValue + " (" + variableValue.getClass() + ")");
}
resolvePath = path.rest();
}
if (resolveContext == null) {
return null;
}
while (!resolvePath.isEmpty()) {
if (resolveContext.isContainer()) {
resolveContext = resolveContext.findIdi(resolvePath.head());
resolvePath = resolvePath.tail();
if (resolveContext == null) {
throw new ExpressionEvaluationException("Cannot find item using path " + path + " in " + context.getContextDescription());
}
} else if (resolveContext.isStructuredProperty()) {
// The output path does not really matter. The delta will be converted to triple anyway
// But the path cannot be null, oherwise the code will die
resolveContext = resolveContext.resolveStructuredProperty(resolvePath, (PrismPropertyDefinition) outputDefinition, new ItemPath());
break;
} else if (resolveContext.isNull()) {
break;
} else {
throw new ExpressionEvaluationException("Cannot resolve path " + resolvePath + " on " + resolveContext + " in " + context.getContextDescription());
}
}
PrismValueDeltaSetTriple<V> outputTriple = ItemDelta.toDeltaSetTriple((Item<V, D>) resolveContext.getItemOld(), (ItemDelta<V, D>) resolveContext.getDelta());
if (outputTriple == null) {
return null;
}
return ExpressionUtil.toOutputTriple(outputTriple, outputDefinition, context.getAdditionalConvertor(), null, protector, prismContext);
}
use of com.evolveum.midpoint.prism.Item 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.Item in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertAllowRequestItems.
protected void assertAllowRequestItems(String userOid, String targetRoleOid, AuthorizationDecisionType expectedDefaultDecision, QName... expectedAllowedItemQNames) throws SchemaException, SecurityViolationException, CommunicationException, ObjectNotFoundException, ConfigurationException, ExpressionEvaluationException {
PrismObject<UserType> user = getUser(userOid);
PrismObject<RoleType> target = getRole(targetRoleOid);
ItemSecurityDecisions decisions = modelInteractionService.getAllowedRequestAssignmentItems(user, target);
display("Request decisions for " + target, decisions);
assertEquals("Wrong assign default decision", expectedDefaultDecision, decisions.getDefaultDecision());
assertEquals("Unexpected number of allowed items", expectedAllowedItemQNames.length, decisions.getItemDecisionMap().size());
decisions.getItemDecisionMap().forEach((path, decision) -> {
assertEquals("wrong item " + path + " decision", AuthorizationDecisionType.ALLOW, decision);
QName lastPathName = path.lastNamed().getName();
if (!Arrays.stream(expectedAllowedItemQNames).anyMatch(qname -> QNameUtil.match(qname, lastPathName))) {
AssertJUnit.fail("Unexpected path " + path);
}
});
}
use of com.evolveum.midpoint.prism.Item in project midpoint by Evolveum.
the class RObject method copyFromJAXB.
public static void copyFromJAXB(PrismContainerValue containerValue, RObject repo, RepositoryContext repositoryContext, RObjectExtensionType ownerType) throws DtoTranslationException {
RAnyConverter converter = new RAnyConverter(repositoryContext.prismContext);
Set<RAnyValue> values = new HashSet<RAnyValue>();
try {
List<Item<?, ?>> items = containerValue.getItems();
//TODO: is this ehought??should we try items without definitions??
if (items != null) {
for (Item item : items) {
values.addAll(converter.convertToRValue(item, false));
}
}
} catch (Exception ex) {
throw new DtoTranslationException(ex.getMessage(), ex);
}
for (RAnyValue value : values) {
ROExtValue ex = (ROExtValue) value;
ex.setOwner(repo);
ex.setOwnerType(ownerType);
if (value instanceof ROExtDate) {
repo.getDates().add(value);
} else if (value instanceof ROExtLong) {
repo.getLongs().add(value);
} else if (value instanceof ROExtReference) {
repo.getReferences().add(value);
} else if (value instanceof ROExtString) {
repo.getStrings().add(value);
} else if (value instanceof ROExtPolyString) {
repo.getPolys().add(value);
} else if (value instanceof ROExtBoolean) {
repo.getBooleans().add(value);
}
}
repo.setStringsCount((short) repo.getStrings().size());
repo.setDatesCount((short) repo.getDates().size());
repo.setPolysCount((short) repo.getPolys().size());
repo.setReferencesCount((short) repo.getReferences().size());
repo.setLongsCount((short) repo.getLongs().size());
repo.setBooleansCount((short) repo.getBooleans().size());
}
Aggregations