use of com.evolveum.midpoint.repo.common.expression.ItemDeltaItem in project midpoint by Evolveum.
the class TestAbstractAssignmentEvaluator method test300DisableRoleEmployee.
/**
* Jack is an Engineer which induces Employee. But role Employee is not valid anymore.
*/
@Test
public void test300DisableRoleEmployee() throws Exception {
final String TEST_NAME = "test300DisableRoleEmployee";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// disable role Employee
ObjectDelta disableEmployeeDelta = DeltaBuilder.deltaFor(RoleType.class, prismContext).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_EMPLOYEE_OID);
modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singletonList(disableEmployeeDelta), null, task, result);
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_ENGINEER_FILE);
ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userTypeJack.asPrismObject(), null, null);
userOdo.recompute();
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
assignmentIdi.recompute();
// WHEN
TestUtil.displayWhen(TEST_NAME);
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testRoleEngineer", task, result);
evaluatedAssignment.evaluateConstructions(userOdo, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertNotNull(evaluatedAssignment);
display("Evaluated assignment", evaluatedAssignment.debugDump());
assertEquals(2, evaluatedAssignment.getConstructionTriple().size());
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Engineer");
assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
assertNoConstruction(evaluatedAssignment, PLUS, "title");
assertNoConstruction(evaluatedAssignment, MINUS, "title");
assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
assertNoConstruction(evaluatedAssignment, PLUS, "location");
assertNoConstruction(evaluatedAssignment, MINUS, "location");
assertEquals("Wrong number of admin GUI configs", 1, evaluatedAssignment.getAdminGuiConfigurations().size());
}
use of com.evolveum.midpoint.repo.common.expression.ItemDeltaItem 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.repo.common.expression.ItemDeltaItem in project midpoint by Evolveum.
the class Mapping method parseSource.
private <IV extends PrismValue, ID extends ItemDefinition> Source<IV, ID> parseSource(VariableBindingDefinitionType sourceType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ItemPathType itemPathType = sourceType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in source definition in " + getMappingContextDescription());
}
ItemPath path = itemPathType.getItemPath();
if (path.isEmpty()) {
throw new SchemaException("Empty source path in " + getMappingContextDescription());
}
QName name = sourceType.getName();
if (name == null) {
name = ItemPath.getName(path.last());
}
ItemPath resolvePath = path;
Object sourceObject = ExpressionUtil.resolvePath(path, variables, sourceContext, objectResolver, "source definition in " + getMappingContextDescription(), task, result);
Item<IV, ID> itemOld = null;
ItemDelta<IV, ID> delta = null;
Item<IV, ID> itemNew = null;
ItemPath residualPath = null;
Collection<? extends ItemDelta<?, ?>> subItemDeltas = null;
if (sourceObject != null) {
if (sourceObject instanceof ItemDeltaItem<?, ?>) {
itemOld = ((ItemDeltaItem<IV, ID>) sourceObject).getItemOld();
delta = ((ItemDeltaItem<IV, ID>) sourceObject).getDelta();
itemNew = ((ItemDeltaItem<IV, ID>) sourceObject).getItemNew();
residualPath = ((ItemDeltaItem<IV, ID>) sourceObject).getResidualPath();
resolvePath = ((ItemDeltaItem<IV, ID>) sourceObject).getResolvePath();
subItemDeltas = ((ItemDeltaItem<IV, ID>) sourceObject).getSubItemDeltas();
} else if (sourceObject instanceof Item<?, ?>) {
itemOld = (Item<IV, ID>) sourceObject;
itemNew = (Item<IV, ID>) sourceObject;
} else {
throw new IllegalStateException("Unknown resolve result " + sourceObject);
}
}
// apply domain
ValueSetDefinitionType domainSetType = sourceType.getSet();
if (domainSetType != null) {
ValueSetDefinition setDef = new ValueSetDefinition(domainSetType, name, "domain of " + name.getLocalPart() + " in " + getMappingContextDescription(), task, result);
setDef.init(expressionFactory);
try {
if (itemOld != null) {
itemOld = itemOld.clone();
itemOld.filterValues(val -> setDef.containsTunnel(val));
}
if (itemNew != null) {
itemNew = itemNew.clone();
itemNew.filterValues(val -> setDef.containsTunnel(val));
}
if (delta != null) {
delta = delta.clone();
delta.filterValues(val -> setDef.containsTunnel(val));
}
} catch (TunnelException te) {
Throwable cause = te.getCause();
if (cause instanceof SchemaException) {
throw (SchemaException) cause;
} else if (cause instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) cause;
} else if (cause instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) cause;
}
}
}
Source<IV, ID> source = new Source<>(itemOld, delta, itemNew, name);
source.setResidualPath(residualPath);
source.setResolvePath(resolvePath);
source.setSubItemDeltas(subItemDeltas);
return source;
}
use of com.evolveum.midpoint.repo.common.expression.ItemDeltaItem 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.repo.common.expression.ItemDeltaItem in project midpoint by Evolveum.
the class LensUtil method getIterationVariableValue.
public static Object getIterationVariableValue(LensProjectionContext accCtx) {
Integer iterationOld = null;
PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent();
if (shadowCurrent != null) {
iterationOld = shadowCurrent.asObjectable().getIteration();
}
if (iterationOld == null) {
return accCtx.getIteration();
}
PrismPropertyDefinition<Integer> propDef = new PrismPropertyDefinitionImpl<>(ExpressionConstants.VAR_ITERATION, DOMUtil.XSD_INT, accCtx.getPrismContext());
PrismProperty<Integer> propOld = propDef.instantiate();
propOld.setRealValue(iterationOld);
PropertyDelta<Integer> propDelta = propDef.createEmptyDelta(new ItemPath(ExpressionConstants.VAR_ITERATION));
propDelta.setValueToReplace(new PrismPropertyValue<Integer>(accCtx.getIteration()));
PrismProperty<Integer> propNew = propDef.instantiate();
propNew.setRealValue(accCtx.getIteration());
ItemDeltaItem<PrismPropertyValue<Integer>, PrismPropertyDefinition<Integer>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew);
return idi;
}
Aggregations