use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AssignmentTripleEvaluator method evaluateAssignment.
private <F extends FocusType> EvaluatedAssignmentImpl<F> evaluateAssignment(ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi, PlusMinusZero mode, boolean evaluateOld, LensContext<F> context, ObjectType source, AssignmentEvaluator<F> assignmentEvaluator, String assignmentPlacementDesc, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
OperationResult result = parentResult.createMinorSubresult(AssignmentProcessor.class.getSimpleName() + ".evaluateAssignment");
result.addParam("assignmentDescription", assignmentPlacementDesc);
try {
// Evaluate assignment. This follows to the assignment targets, follows to the inducements,
// evaluates all the expressions, etc.
EvaluatedAssignmentImpl<F> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, mode, evaluateOld, source, assignmentPlacementDesc, task, result);
context.rememberResources(evaluatedAssignment.getResources(task, result));
result.recordSuccess();
return evaluatedAssignment;
} catch (ObjectNotFoundException ex) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(LensUtil.getAssignmentType(assignmentIdi, evaluateOld)));
}
if (ModelExecuteOptions.isForce(context.getOptions())) {
result.recordHandledError(ex);
return null;
}
ModelUtils.recordFatalError(result, ex);
return null;
} catch (SchemaException ex) {
AssignmentType assignmentType = LensUtil.getAssignmentType(assignmentIdi, evaluateOld);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(assignmentType));
}
ModelUtils.recordFatalError(result, ex);
String resourceOid = FocusTypeUtil.determineConstructionResource(assignmentType);
if (resourceOid == null) {
// This is a role assignment or something like that. Just throw the original exception for now.
throw ex;
}
ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid, FocusTypeUtil.determineConstructionKind(assignmentType), FocusTypeUtil.determineConstructionIntent(assignmentType));
LensProjectionContext accCtx = context.findProjectionContext(rad);
if (accCtx != null) {
accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
}
return null;
} catch (ExpressionEvaluationException | PolicyViolationException e) {
result.recordFatalError(e);
throw e;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AssignmentTripleEvaluator method processAssignment.
private void processAssignment(DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple, ObjectDelta<F> focusDelta, ContainerDelta<AssignmentType> assignmentDelta, SmartAssignmentElement assignmentElement) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
LensFocusContext<F> focusContext = context.getFocusContext();
PrismContainerValue<AssignmentType> assignmentCVal = assignmentElement.getAssignmentCVal();
AssignmentType assignmentType = assignmentCVal.asContainerable();
PrismContainerValue<AssignmentType> assignmentCValOld = assignmentCVal;
PrismContainerValue<AssignmentType> assignmentCValNew = assignmentCVal;
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
boolean presentInCurrent = assignmentElement.isCurrent();
boolean presentInOld = assignmentElement.isOld();
// This really means whether the WHOLE assignment was changed (e.g. added/delted/replaced). It tells nothing
// about "micro-changes" inside assignment, these will be processed later.
boolean isAssignmentChanged = assignmentElement.isChanged();
boolean forceRecon = false;
String assignmentPlacementDesc;
if (isAssignmentChanged) {
// Whole assignment added or deleted
assignmentPlacementDesc = "delta for " + source;
} else {
assignmentPlacementDesc = source.toString();
Collection<? extends ItemDelta<?, ?>> assignmentItemDeltas = getExecutionWaveAssignmentItemDeltas(focusContext, assignmentCVal.getId());
if (assignmentItemDeltas != null && !assignmentItemDeltas.isEmpty()) {
// Small changes inside assignment, but otherwise the assignment stays as it is (not added or deleted)
assignmentIdi.setSubItemDeltas(assignmentItemDeltas);
// The subItemDeltas above will handle some changes. But not other.
// E.g. a replace of the whole construction will not be handled properly.
// Therefore we force recon to sort it out.
forceRecon = true;
isAssignmentChanged = true;
PrismContainer<AssignmentType> assContNew = focusContext.getObjectNew().findContainer(FocusType.F_ASSIGNMENT);
assignmentCValNew = assContNew.getValue(assignmentCVal.getId());
}
}
assignmentIdi.recompute();
if (focusDelta != null && focusDelta.isDelete()) {
// were not changed explicitly.
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing focus delete for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
if (assignmentDelta.isReplace()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing replace of all assignments for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
// ASSIGNMENT REPLACE
// Handling assignment replace delta. This needs to be handled specially as all the "old"
// assignments should be considered deleted - except those that are part of the new value set
// (remain after replace). As account delete and add are costly operations (and potentially dangerous)
// we optimize here are consider the assignments that were there before replace and still are there
// after it as unchanged.
boolean hadValue = presentInCurrent;
boolean willHaveValue = assignmentDelta.isValueToReplace(assignmentCVal, true);
if (hadValue && willHaveValue) {
// No change
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else if (willHaveValue) {
// add
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else if (hadValue) {
// delete
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else if (assignmentElement.isOld()) {
// This is OK, safe to skip. This is just an relic of earlier processing.
return;
} else {
LOGGER.error("Whoops. Unexpected things happen. Assignment is neither current, old nor new (replace delta)\n{}", assignmentElement.debugDump(1));
throw new SystemException("Whoops. Unexpected things happen. Assignment is neither current, old nor new (replace delta).");
}
} else {
// Just sort assignments to sets: unchanged (zero), added (plus), removed (minus)
if (isAssignmentChanged) {
// There was some change
boolean isAdd = assignmentDelta.isValueToAdd(assignmentCVal, true);
boolean isDelete = assignmentDelta.isValueToDelete(assignmentCVal, true);
if (isAdd & !isDelete) {
// Entirely new assignment is added
if (presentInCurrent && presentInOld) {
// Phantom add: adding assignment that is already there
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, phantom add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
}
} else if (isDelete && !isAdd) {
// Existing assignment is removed
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, delete: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
} else {
// Small change inside an assignment
// The only thing that we need to worry about is assignment validity change. That is a cause
// of provisioning/deprovisioning of the projections. So check that explicitly. Other changes are
// not significant, i.e. reconciliation can handle them.
boolean isValidOld = LensUtil.isAssignmentValid(focusContext.getObjectOld().asObjectable(), assignmentCValOld.asContainerable(), now, activationComputer);
boolean isValid = LensUtil.isAssignmentValid(focusContext.getObjectNew().asObjectable(), assignmentCValNew.asContainerable(), now, activationComputer);
if (isValid == isValidOld) {
// The change is not significant for assignment applicability. Recon will sort out the details.
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, minor change (add={}, delete={}, valid={}): {}", new Object[] { isAdd, isDelete, isValid, SchemaDebugUtil.prettyPrint(assignmentCVal) });
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, true);
} else if (isValid) {
// Assignment became valid. We need to place it in plus set to initiate provisioning
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, assignment becomes valid (add={}, delete={}): {}", new Object[] { isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal) });
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, true);
} else {
// Assignment became invalid. We need to place is in minus set to initiate deprovisioning
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing changed assignment, assignment becomes invalid (add={}, delete={}): {}", new Object[] { isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal) });
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, true);
}
}
} else {
// No change in assignment
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Processing unchanged assignment {}", new Object[] { SchemaDebugUtil.prettyPrint(assignmentCVal) });
}
EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
if (evaluatedAssignment == null) {
return;
}
evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
evaluatedAssignment.setPresentInOldObject(presentInOld);
collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
}
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class AssignmentTripleEvaluator method getExecutionWaveAssignmentDelta.
/**
* Returns delta of user assignments, both primary and secondary (merged together).
* The returned object is (kind of) immutable. Changing it may do strange things (but most likely the changes will be lost).
*
* Originally we took only the delta related to current execution wave, to avoid re-processing of already executed assignments.
* But MID-2422 shows that we need to take deltas from waves 0..N (N=current execution wave) [that effectively means all the secondary deltas]
*/
private <F extends FocusType> ContainerDelta<AssignmentType> getExecutionWaveAssignmentDelta(LensFocusContext<F> focusContext) throws SchemaException {
ObjectDelta<? extends FocusType> focusDelta = focusContext.getAggregatedWaveDelta(focusContext.getLensContext().getExecutionWave());
if (focusDelta == null) {
return createEmptyAssignmentDelta(focusContext);
}
ContainerDelta<AssignmentType> assignmentDelta = focusDelta.findContainerDelta(new ItemPath(FocusType.F_ASSIGNMENT));
if (assignmentDelta == null) {
return createEmptyAssignmentDelta(focusContext);
}
return assignmentDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class TestAbstractAssignmentEvaluator method test170RoleManagerChangeCostCenter.
/**
* jack has assigned role Manager.
*
* However, condition in job metarole for Manager is such that it needs "management"
* to be present in user/costCenter in order to be active.
*/
@Test
public void test170RoleManagerChangeCostCenter() throws Exception {
final String TEST_NAME = "test170RoleManagerChangeCostCenter";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_MANAGER_FILE);
AssignmentType assignmentForUser = assignmentType.clone();
assignmentForUser.asPrismContainerValue().setParent(null);
user.asObjectable().getAssignment().add(assignmentForUser);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_COST_CENTER, prismContext, "management");
ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
userOdo.recompute();
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
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, TEST_NAME, 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(4, evaluatedAssignment.getConstructionTriple().size());
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
// because Employee's job metarole is active even if Manager's is not
assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee");
assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
// because Manager's job metarole is originally not active
assertConstruction(evaluatedAssignment, PLUS, "title", ZERO, "Manager");
assertConstruction(evaluatedAssignment, PLUS, "title", PLUS);
assertConstruction(evaluatedAssignment, PLUS, "title", MINUS);
assertNoConstruction(evaluatedAssignment, MINUS, "title");
// because Generic Metarole is active all the time
assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
assertNoConstruction(evaluatedAssignment, PLUS, "location");
assertNoConstruction(evaluatedAssignment, MINUS, "location");
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType in project midpoint by Evolveum.
the class TestAbstractAssignmentEvaluator method test200DisableEngineerEmployeeInducement.
/**
* Disable Engineer -> Employee inducement.
*/
@Test(enabled = false)
public void test200DisableEngineerEmployeeInducement() throws Exception {
final String TEST_NAME = "test200DisableEngineerEmployeeInducement";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// disable Engineer->Employee inducement
ObjectDelta disableInducementDelta = DeltaBuilder.deltaFor(RoleType.class, prismContext).item(RoleType.F_INDUCEMENT, 3, F_ACTIVATION, F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_ENGINEER_OID);
modelService.executeChanges(Collections.singletonList(disableInducementDelta), 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());
// TODO
// assertEquals(2, evaluatedAssignment.getConstructions().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());
}
Aggregations