use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.
the class AssignmentProcessor method distributeConstructions.
private <AH extends AssignmentHolderType> void distributeConstructions(LensContext<AH> context, DeltaSetTriple<EvaluatedAssignmentImpl<AH>> evaluatedAssignmentTriple, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
ComplexConstructionConsumer<ResourceShadowDiscriminator, EvaluatedAssignedResourceObjectConstructionImpl<AH>> consumer = new ComplexConstructionConsumer<>() {
private boolean processOnlyExistingProjContexts;
@Override
public boolean before(ResourceShadowDiscriminator rsd) {
if (rsd.getResourceOid() == null) {
throw new IllegalStateException("Resource OID null in ResourceShadowDiscriminator during assignment processing");
}
if (rsd.getIntent() == null) {
throw new IllegalStateException("Resource object intent is null in ResourceShadowDiscriminator during assignment processing");
}
processOnlyExistingProjContexts = false;
if (ModelExecuteOptions.isLimitPropagation(context.getOptions())) {
if (context.getTriggeringResourceOid() != null && !rsd.getResourceOid().equals(context.getTriggeringResourceOid())) {
LOGGER.trace("Skipping processing construction for shadow identified by {} because of limitation to propagate changes only for resource {}", rsd, context.getTriggeringResourceOid());
return false;
}
if (context.getChannel() != null && SchemaConstants.CHANNEL_DISCOVERY.equals(QNameUtil.uriToQName(context.getChannel()))) {
LOGGER.trace("Processing of shadow identified by {} will be skipped because of limitation for discovery channel.", // TODO is this message OK? [med]
context.getChannel());
processOnlyExistingProjContexts = true;
}
}
return true;
}
@Override
public void onAssigned(ResourceShadowDiscriminator rsd, String desc) throws SchemaException {
LensProjectionContext projectionContext = LensUtil.getOrCreateProjectionContext(context, rsd).context;
projectionContext.setAssigned(true);
projectionContext.setAssignedOldIfUnknown(false);
projectionContext.setLegalOldIfUnknown(false);
if (projectionContext.getAssignmentPolicyEnforcementType() != AssignmentPolicyEnforcementType.NONE) {
LOGGER.trace("Projection {} legal: assigned (valid)", desc);
projectionContext.setLegal(true);
} else {
LOGGER.trace("Projection {} skip: assigned (valid), NONE enforcement", desc);
}
}
@Override
public void onUnchangedValid(ResourceShadowDiscriminator key, String desc) throws SchemaException {
LensProjectionContext projectionContext = context.findProjectionContext(key);
if (projectionContext == null) {
if (processOnlyExistingProjContexts) {
LOGGER.trace("Projection {} skip: unchanged (valid), processOnlyExistingProjCxts", desc);
return;
}
// The projection should exist before the change but it does not
// This happens during reconciliation if there is an inconsistency.
// Pretend that the assignment was just added. That should do.
projectionContext = LensUtil.getOrCreateProjectionContext(context, key).context;
}
LOGGER.trace("Projection {} legal: unchanged (valid)", desc);
projectionContext.setAssigned(true);
projectionContext.setAssignedOldIfUnknown(true);
if (projectionContext.getAssignmentPolicyEnforcementType() == AssignmentPolicyEnforcementType.NONE) {
projectionContext.setLegalOld(null);
projectionContext.setLegal(null);
} else {
projectionContext.setLegalOldIfUnknown(true);
projectionContext.setLegal(true);
}
}
@Override
public void onUnchangedInvalid(ResourceShadowDiscriminator rsd, String desc) throws SchemaException {
LensProjectionContext projectionContext = context.findProjectionContext(rsd);
if (projectionContext == null) {
if (processOnlyExistingProjContexts) {
LOGGER.trace("Projection {} skip: unchanged (invalid), processOnlyExistingProjContexts", desc);
} else {
LOGGER.trace("Projection {} skip: unchanged (invalid) and does not exist in current lens context", desc);
}
return;
}
LOGGER.trace("Projection {} illegal: unchanged (invalid)", desc);
projectionContext.setLegal(false);
projectionContext.setLegalOldIfUnknown(false);
projectionContext.setAssigned(false);
projectionContext.setAssignedOldIfUnknown(false);
if (projectionContext.getAssignmentPolicyEnforcementType() == AssignmentPolicyEnforcementType.NONE || projectionContext.getAssignmentPolicyEnforcementType() == AssignmentPolicyEnforcementType.POSITIVE) {
projectionContext.setLegalOld(null);
projectionContext.setLegal(null);
} else {
projectionContext.setLegalOldIfUnknown(false);
projectionContext.setLegal(false);
}
}
@Override
public void onUnassigned(ResourceShadowDiscriminator rsd, String desc) throws SchemaException {
if (accountExists(context, rsd)) {
LensProjectionContext projectionContext = context.findProjectionContext(rsd);
if (projectionContext == null) {
if (processOnlyExistingProjContexts) {
LOGGER.trace("Projection {} skip: unassigned, processOnlyExistingProjContexts", desc);
return;
}
projectionContext = LensUtil.getOrCreateProjectionContext(context, rsd).context;
}
projectionContext.setAssigned(false);
projectionContext.setAssignedOldIfUnknown(true);
projectionContext.setLegalOldIfUnknown(true);
AssignmentPolicyEnforcementType assignmentPolicyEnforcement = projectionContext.getAssignmentPolicyEnforcementType();
// TODO: check for MARK and LEGALIZE enforcement policies ....add delete also for relative enforcement
if (assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.FULL || assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.RELATIVE) {
LOGGER.trace("Projection {} illegal: unassigned", desc);
projectionContext.setLegal(false);
} else if (assignmentPolicyEnforcement == AssignmentPolicyEnforcementType.POSITIVE) {
LOGGER.trace("Projection {} legal: unassigned, but allowed by policy ({})", desc, assignmentPolicyEnforcement);
projectionContext.setLegal(true);
} else {
LOGGER.trace("Projection {} legal: unassigned, policy decision postponed ({})", desc, assignmentPolicyEnforcement);
projectionContext.setLegal(null);
}
} else {
LOGGER.trace("Projection {} nothing: unassigned (valid->invalid) but not there", desc);
// We have to delete something that is not there. Nothing to do.
}
}
@Override
public void after(ResourceShadowDiscriminator rsd, String desc, DeltaMapTriple<ResourceShadowDiscriminator, EvaluatedConstructionPack<EvaluatedAssignedResourceObjectConstructionImpl<AH>>> constructionMapTriple) {
DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<AH>> projectionEvaluatedConstructionDeltaSetTriple = prismContext.deltaFactory().createDeltaSetTriple(getConstructions(constructionMapTriple.getZeroMap().get(rsd), true), getConstructions(constructionMapTriple.getPlusMap().get(rsd), true), getConstructions(constructionMapTriple.getMinusMap().get(rsd), false));
LensProjectionContext projectionContext = context.findProjectionContext(rsd);
if (projectionContext != null) {
// This can be null in a exotic case if we delete already deleted account
LOGGER.trace("Construction delta set triple for {}:\n{}", rsd, projectionEvaluatedConstructionDeltaSetTriple.debugDumpLazily(1));
projectionContext.setEvaluatedAssignedConstructionDeltaSetTriple(projectionEvaluatedConstructionDeltaSetTriple);
if (isForceRecon(constructionMapTriple.getZeroMap().get(rsd)) || isForceRecon(constructionMapTriple.getPlusMap().get(rsd)) || isForceRecon(constructionMapTriple.getMinusMap().get(rsd))) {
projectionContext.setDoReconciliation(true);
}
}
}
};
OperationResult result = parentResult.createMinorSubresult(OP_DISTRIBUTE_CONSTRUCTIONS);
try {
LOGGER.trace("Starting construction distribution");
constructionProcessor.distributeConstructions(evaluatedAssignmentTriple, EvaluatedAssignmentImpl::getConstructionTriple, construction -> getConstructionMapKey(context, construction, task, result), consumer);
LOGGER.trace("Finished construction distribution");
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.
the class TestAssignmentProcessor method test021AddAssignmentModifyAccountAssignment.
/**
* Context: user barbossa (two assignments of dummy account) + dummy account projection
*
* Primary delta: add (third) dummy account assignment with some attribute mappings.
*/
@Test
public void test021AddAssignmentModifyAccountAssignment() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_BARBOSSA_OID, result);
fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
addFocusModificationToContext(context, REQ_USER_BARBOSSA_MODIFY_ADD_ASSIGNMENT_ACCOUNT_DUMMY_ATTR);
recompute(context);
displayDumpable("Input context", context);
assertFocusModificationSanity(context);
when();
processAssignments(task, result, context);
then();
displayDumpable("Output context", context);
display("outbound processor result", result);
assertSuccess("Outbound processor failed (result)", result);
assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
LensProjectionContext accContext = getSingleProjectionContext(context);
assertNull(accContext.getPrimaryDelta());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
assertNoDecision(accContext);
assertLegal(accContext);
// assignmentProcessor.processAssignmentsAccountValues(accContext, result);
DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> accountConstructionDeltaSetTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
PrismAsserts.assertTripleNoMinus(accountConstructionDeltaSetTriple);
assertSetSize("zero", accountConstructionDeltaSetTriple.getZeroSet(), 2);
EvaluatedAssignedResourceObjectConstructionImpl<UserType> zeroAccountConstruction = getZeroEvaluatedAccountConstruction(accountConstructionDeltaSetTriple, "Brethren account construction");
assertZeroAttributeValues(zeroAccountConstruction, getShipAttributeName(), "Pirate Brethren, Inc.");
assertNoPlusAttributeValues(zeroAccountConstruction, getShipAttributeName());
assertNoMinusAttributeValues(zeroAccountConstruction, getShipAttributeName());
assertZeroAttributeValues(zeroAccountConstruction, getLocationAttributeName(), "Caribbean");
assertNoPlusAttributeValues(zeroAccountConstruction, getLocationAttributeName());
assertNoMinusAttributeValues(zeroAccountConstruction, getLocationAttributeName());
assertZeroAttributeValues(zeroAccountConstruction, getWeaponAttributeName(), "Sword");
assertNoPlusAttributeValues(zeroAccountConstruction, getWeaponAttributeName());
assertNoMinusAttributeValues(zeroAccountConstruction, getWeaponAttributeName());
assertSetSize("plus", accountConstructionDeltaSetTriple.getPlusSet(), 1);
EvaluatedAssignedResourceObjectConstructionImpl<UserType> plusAccountConstruction = getPlusEvaluatedAccountConstruction(accountConstructionDeltaSetTriple, "Monkey account construction");
assertZeroAttributeValues(plusAccountConstruction, getDrinkAttributeName(), "Rum");
assertNoPlusAttributeValues(plusAccountConstruction, getDrinkAttributeName());
assertNoMinusAttributeValues(plusAccountConstruction, getDrinkAttributeName());
assertZeroAttributeValues(plusAccountConstruction, getWeaponAttributeName(), "Dagger", "Pistol");
assertNoPlusAttributeValues(plusAccountConstruction, getWeaponAttributeName());
assertNoMinusAttributeValues(plusAccountConstruction, getWeaponAttributeName());
assertTrue("Old legal variable for projection context is not true", accContext.isLegalOld());
assertTrue("Legal variable for projection context is not true", accContext.isLegal());
assertTrue("Old assigned variable for projection context is not true", accContext.isAssignedOld());
assertTrue("Assigned variable for projection context is not true", accContext.isAssigned());
assertSerializable(context);
}
use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.
the class TestAssignmentProcessor method test002ModifyUser.
/**
* Context: user barbossa (2 assignments to dummy account) + dummy account projection context.
*
* Primary delta: change of user locality.
*
* Assignment evaluator should produce 2 constructions.
*/
@Test
public void test002ModifyUser() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_BARBOSSA_OID, result);
fillContextWithAccount(context, ACCOUNT_HBARBOSSA_DUMMY_OID, task, result);
addModificationToContextReplaceUserProperty(context, UserType.F_LOCALITY, new PolyString("Tortuga"));
recompute(context);
displayDumpable("Input context", context);
assertFocusModificationSanity(context);
when();
processAssignments(task, result, context);
then();
displayDumpable("Output context", context);
display("outbound processor result", result);
assertSuccess("Outbound processor failed (result)", result);
assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
LensProjectionContext accContext = getSingleProjectionContext(context);
assertNull(accContext.getPrimaryDelta());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
assertNoDecision(accContext);
assertLegal(accContext);
// assignmentProcessor.processAssignmentsAccountValues(accContext, result);
DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> accountConstructionDeltaSetTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
displayDumpable("accountConstructionDeltaSetTriple", accountConstructionDeltaSetTriple);
PrismAsserts.assertTripleNoMinus(accountConstructionDeltaSetTriple);
PrismAsserts.assertTripleNoPlus(accountConstructionDeltaSetTriple);
assertSetSize("zero", accountConstructionDeltaSetTriple.getZeroSet(), 2);
EvaluatedAssignedResourceObjectConstructionImpl<UserType> zeroEvaluatedAccountConstruction = getZeroEvaluatedAccountConstruction(accountConstructionDeltaSetTriple, "Brethren account construction");
assertNoZeroAttributeValues(zeroEvaluatedAccountConstruction, getLocationAttributeName());
assertPlusAttributeValues(zeroEvaluatedAccountConstruction, getLocationAttributeName(), "Tortuga");
assertMinusAttributeValues(zeroEvaluatedAccountConstruction, getLocationAttributeName(), "Caribbean");
assertSerializable(context);
}
use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.
the class TestAssignmentProcessor method test012AddAssignmentAddAccountDirectAssignmentWithAttrs.
/**
* Context: user jack (no assignments)
*
* Primary delta: add new dummy account assignment with two attribute mappings
*
* Assignment evaluator execution should result in projection context being created. Constructions with evaluated
* mappings should be created as well.
*/
@Test
public void test012AddAssignmentAddAccountDirectAssignmentWithAttrs() throws Exception {
given();
Task task = getTestTask();
OperationResult result = task.getResult();
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
addFocusModificationToContext(context, REQ_USER_JACK_MODIFY_ADD_ASSIGNMENT_ACCOUNT_DUMMY_ATTR);
recompute(context);
displayDumpable("Input context", context);
assertFocusModificationSanity(context);
when();
processAssignments(task, result, context);
then();
displayDumpable("Output context", context);
display("outbound processor result", result);
assertSuccess("Outbound processor failed (result)", result);
assertSame(context.getFocusContext().getPrimaryDelta().getChangeType(), ChangeType.MODIFY);
assertNull("Unexpected user changes", context.getFocusContext().getSecondaryDelta());
LensProjectionContext accContext = getSingleProjectionContext(context);
assertNull(accContext.getPrimaryDelta());
ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
assertNull("Account secondary delta sneaked in", accountSecondaryDelta);
assertNoDecision(accContext);
assertLegal(accContext);
// assignmentProcessor.processAssignmentsAccountValues(accContext, result);
DeltaSetTriple<EvaluatedAssignedResourceObjectConstructionImpl<UserType>> accountConstructionDeltaSetTriple = accContext.getEvaluatedAssignedConstructionDeltaSetTriple();
PrismAsserts.assertTripleNoMinus(accountConstructionDeltaSetTriple);
PrismAsserts.assertTripleNoZero(accountConstructionDeltaSetTriple);
assertSetSize("plus", accountConstructionDeltaSetTriple.getPlusSet(), 1);
EvaluatedAssignedResourceObjectConstructionImpl<UserType> plusAccountConstruction = getPlusEvaluatedAccountConstruction(accountConstructionDeltaSetTriple);
assertZeroAttributeValues(plusAccountConstruction, getShipAttributeName(), "Pirate Brethren, Inc.");
assertNoPlusAttributeValues(plusAccountConstruction, getShipAttributeName());
assertNoMinusAttributeValues(plusAccountConstruction, getShipAttributeName());
assertZeroAttributeValues(plusAccountConstruction, getLocationAttributeName(), "Caribbean");
assertNoPlusAttributeValues(plusAccountConstruction, getLocationAttributeName());
assertNoMinusAttributeValues(plusAccountConstruction, getLocationAttributeName());
assertSerializable(context);
}
use of com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl in project midpoint by Evolveum.
the class AbstractAssignmentEvaluatorTest method test110DirectExpression.
@Test
public void test110DirectExpression() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_DIRECT_EXPRESSION_FILE);
ObjectDeltaObject<UserType> userOdo = createUserOdo(userTypeJack.asPrismObject());
userOdo.recompute();
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = createAssignmentIdi(assignmentType);
// WHEN
when();
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", AssignmentOrigin.createInObject(), task, result);
evaluateConstructions(evaluatedAssignment, userOdo, task, result);
// THEN
then();
result.computeStatus();
TestUtil.assertSuccess(result);
assertNotNull(evaluatedAssignment);
displayDumpable("Evaluated assignment", evaluatedAssignment);
assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
ResourceObjectConstruction<UserType, EvaluatedAssignedResourceObjectConstructionImpl<UserType>> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
assertNotNull("No object class definition in construction", construction.getResourceObjectDefinition());
assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Aggregations