use of com.evolveum.midpoint.prism.delta.DeltaSetTriple in project midpoint by Evolveum.
the class ReconciliationProcessor method processReconciliationFocus.
private <F extends ObjectType> void processReconciliationFocus(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
OperationResult subResult = result.createMinorSubresult(PROCESS_RECONCILIATION);
try {
// reconciliation is cheap if the shadow is already fetched therefore just do it
if (!projCtx.isDoReconciliation() && !projCtx.isFullShadow()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Skipping reconciliation of {}: no doReconciliation and no full shadow", projCtx.getHumanReadableName());
}
return;
}
SynchronizationPolicyDecision policyDecision = projCtx.getSynchronizationPolicyDecision();
if (policyDecision != null && (policyDecision == SynchronizationPolicyDecision.DELETE || policyDecision == SynchronizationPolicyDecision.UNLINK)) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Skipping reconciliation of {}: decision={}", projCtx.getHumanReadableName(), policyDecision);
}
return;
}
if (projCtx.getObjectCurrent() == null) {
LOGGER.warn("Can't do reconciliation. Account context doesn't contain current version of account.");
return;
}
if (!projCtx.isFullShadow()) {
// We need to load the object
GetOperationOptions rootOps = GetOperationOptions.createDoNotDiscovery();
rootOps.setPointInTimeType(PointInTimeType.FUTURE);
PrismObject<ShadowType> objectOld = provisioningService.getObject(ShadowType.class, projCtx.getOid(), SelectorOptions.createCollection(rootOps), task, result);
ShadowType oldShadow = objectOld.asObjectable();
projCtx.determineFullShadowFlag(oldShadow.getFetchResult());
projCtx.setLoadedObject(objectOld);
projCtx.recompute();
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Starting reconciliation of {}", projCtx.getHumanReadableName());
}
reconcileAuxiliaryObjectClasses(projCtx);
RefinedObjectClassDefinition rOcDef = projCtx.getCompositeObjectClassDefinition();
Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismPropertyValue<?>, PrismPropertyDefinition<?>>>> squeezedAttributes = projCtx.getSqueezedAttributes();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Attribute reconciliation processing {}", projCtx.getHumanReadableName());
}
reconcileProjectionAttributes(projCtx, squeezedAttributes, rOcDef);
Map<QName, DeltaSetTriple<ItemValueWithOrigin<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>>> squeezedAssociations = projCtx.getSqueezedAssociations();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Association reconciliation processing {}", projCtx.getHumanReadableName());
}
reconcileProjectionAssociations(projCtx, squeezedAssociations, rOcDef, task, result);
reconcileMissingAuxiliaryObjectClassAttributes(projCtx);
} catch (RuntimeException | SchemaException e) {
subResult.recordFatalError(e);
throw e;
} finally {
subResult.computeStatus();
}
}
use of com.evolveum.midpoint.prism.delta.DeltaSetTriple in project midpoint by Evolveum.
the class ConsolidationProcessor method hasActiveWeakMapping.
private <V extends PrismValue, D extends ItemDefinition> boolean hasActiveWeakMapping(Map<QName, DeltaSetTriple<ItemValueWithOrigin<V, D>>> squeezedAttributes, LensProjectionContext accCtx) throws SchemaException {
for (Map.Entry<QName, DeltaSetTriple<ItemValueWithOrigin<V, D>>> entry : squeezedAttributes.entrySet()) {
DeltaSetTriple<ItemValueWithOrigin<V, D>> ivwoTriple = entry.getValue();
boolean hasWeak = false;
for (ItemValueWithOrigin<V, D> ivwo : ivwoTriple.getAllValues()) {
PrismValueDeltaSetTripleProducer<V, D> mapping = ivwo.getMapping();
if (mapping.getStrength() == MappingStrengthType.WEAK) {
// We only care about mappings that change something. If the weak mapping is not
// changing anything then it will not be applied in this step anyway. Therefore
// there is no point in loading the real values just because there is such mapping.
// Note: we can be sure that we are NOT doing reconciliation. If we do reconciliation
// then we cannot get here in the first place (the projection is already loaded).
PrismValueDeltaSetTriple<?> outputTriple = mapping.getOutputTriple();
if (outputTriple != null && !outputTriple.isEmpty() && !outputTriple.isZeroOnly()) {
return true;
}
hasWeak = true;
}
}
if (hasWeak) {
// unless we fetch the real values.
if (ivwoTriple.hasMinusSet()) {
for (ItemValueWithOrigin<V, D> ivwo : ivwoTriple.getMinusSet()) {
PrismValueDeltaSetTripleProducer<V, D> mapping = ivwo.getMapping();
PrismValueDeltaSetTriple<?> outputTriple = mapping.getOutputTriple();
if (outputTriple != null && !outputTriple.isEmpty()) {
return true;
}
}
}
for (ItemValueWithOrigin<V, D> ivwo : ivwoTriple.getNonNegativeValues()) {
PrismValueDeltaSetTripleProducer<V, D> mapping = ivwo.getMapping();
PrismValueDeltaSetTriple<?> outputTriple = mapping.getOutputTriple();
if (outputTriple != null && outputTriple.hasMinusSet()) {
return true;
}
}
ObjectDelta<ShadowType> projectionDelta = accCtx.getDelta();
if (projectionDelta != null) {
PropertyDelta<?> aPrioriAttributeDelta = projectionDelta.findPropertyDelta(new ItemPath(ShadowType.F_ATTRIBUTES, entry.getKey()));
if (aPrioriAttributeDelta != null && aPrioriAttributeDelta.isDelete()) {
return true;
}
if (aPrioriAttributeDelta != null && aPrioriAttributeDelta.isReplace() && aPrioriAttributeDelta.getValuesToReplace().isEmpty()) {
return true;
}
}
}
}
return false;
}
use of com.evolveum.midpoint.prism.delta.DeltaSetTriple in project midpoint by Evolveum.
the class PersonaProcessor method processPersonaChangesFocus.
public <F extends FocusType> HookOperationMode processPersonaChangesFocus(LensContext<F> context, Task task, OperationResult result) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException, PolicyViolationException {
DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple = (DeltaSetTriple) context.getEvaluatedAssignmentTriple();
if (evaluatedAssignmentTriple == null || evaluatedAssignmentTriple.isEmpty()) {
return HookOperationMode.FOREGROUND;
}
DeltaSetTriple<PersonaKey> activePersonaKeyTriple = new DeltaSetTriple<>();
ComplexConstructionConsumer<PersonaKey, PersonaConstruction<F>> consumer = new ComplexConstructionConsumer<PersonaKey, PersonaConstruction<F>>() {
@Override
public boolean before(PersonaKey key) {
return true;
}
@Override
public void onAssigned(PersonaKey key, String desc) {
activePersonaKeyTriple.addToPlusSet(key);
}
@Override
public void onUnchangedValid(PersonaKey key, String desc) {
activePersonaKeyTriple.addToZeroSet(key);
}
@Override
public void onUnchangedInvalid(PersonaKey key, String desc) {
}
@Override
public void onUnassigned(PersonaKey key, String desc) {
activePersonaKeyTriple.addToMinusSet(key);
}
@Override
public void after(PersonaKey key, String desc, DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple) {
}
};
DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple = constructionProcessor.processConstructions(context, evaluatedAssignmentTriple, evaluatedAssignment -> evaluatedAssignment.getPersonaConstructionTriple(), construction -> new PersonaKey(construction.getConstructionType()), consumer, task, result);
LOGGER.trace("activePersonaKeyTriple:\n{}", activePersonaKeyTriple.debugDumpLazily());
List<FocusType> existingPersonas = readExistingPersonas(context, task, result);
LOGGER.trace("existingPersonas:\n{}", existingPersonas);
for (PersonaKey key : activePersonaKeyTriple.getNonNegativeValues()) {
FocusType existingPersona = findPersona(existingPersonas, key);
LOGGER.trace("existingPersona: {}", existingPersona);
// TODO: add ability to merge several constructions
ConstructionPack<PersonaConstruction<F>> pack = constructionMapTriple.getPlusMap().get(key);
if (pack == null) {
pack = constructionMapTriple.getZeroMap().get(key);
}
Collection<PrismPropertyValue<PersonaConstruction<F>>> constructions = pack.getConstructions();
if (constructions.isEmpty()) {
continue;
}
if (constructions.size() > 1) {
throw new UnsupportedOperationException("Merging of multiple persona constructions is not supported yet");
}
PersonaConstruction<F> construction = constructions.iterator().next().getValue();
LOGGER.trace("construction:\n{}", construction.debugDumpLazily());
if (existingPersona == null) {
personaAdd(context, key, construction, task, result);
} else {
personaModify(context, key, construction, existingPersona.asPrismObject(), task, result);
}
}
for (PersonaKey key : activePersonaKeyTriple.getMinusSet()) {
FocusType existingPersona = findPersona(existingPersonas, key);
if (existingPersona != null) {
personaDelete(context, key, existingPersona, task, result);
}
}
return HookOperationMode.FOREGROUND;
}
use of com.evolveum.midpoint.prism.delta.DeltaSetTriple in project midpoint by Evolveum.
the class TestPolicyRules method test100AssignRoleMutinierToJack.
/**
* No exclusion here. The assignment should go smoothly.
*/
@Test
public void test100AssignRoleMutinierToJack() throws Exception {
final String TEST_NAME = "test100AssignRoleMutinierToJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPolicyRules.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
addModificationToContextAssignRole(context, USER_JACK_OID, ROLE_MUTINIER_OID);
display("Input context", context);
assertFocusModificationSanity(context);
rememberShadowFetchOperationCount();
// WHEN
TestUtil.displayWhen(TEST_NAME);
projector.project(context, "test", task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
assertAssignAccountToJack(context);
DeltaSetTriple<EvaluatedAssignmentImpl<UserType>> evaluatedAssignmentTriple = (DeltaSetTriple) context.getEvaluatedAssignmentTriple();
// display("Output evaluatedAssignmentTriple", evaluatedAssignmentTriple);
dumpPolicyRules(context);
assertEvaluatedRules(context, 4);
assertTriggeredRules(context, 0, null);
}
use of com.evolveum.midpoint.prism.delta.DeltaSetTriple in project midpoint by Evolveum.
the class TestPolicyRules method test120AssignRoleConstableToJack.
@Test
public void test120AssignRoleConstableToJack() throws Exception {
final String TEST_NAME = "test120AssignRoleConstableToJack";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestPolicyRules.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
addModificationToContextAssignRole(context, USER_JACK_OID, ROLE_CONSTABLE_OID);
display("Input context", context);
assertFocusModificationSanity(context);
rememberShadowFetchOperationCount();
// WHEN
TestUtil.displayWhen(TEST_NAME);
projector.project(context, "test", task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
display("Output context", context);
DeltaSetTriple<EvaluatedAssignmentImpl<UserType>> evaluatedAssignmentTriple = (DeltaSetTriple) context.getEvaluatedAssignmentTriple();
// display("Output evaluatedAssignmentTriple", evaluatedAssignmentTriple);
dumpPolicyRules(context);
assertEvaluatedRules(context, 5);
// conflicting assignment was pruned, so the exclusion is no longer present here
// EvaluatedExclusionTrigger trigger = (EvaluatedExclusionTrigger) assertTriggeredRule(context, null, PolicyConstraintKindType.EXCLUSION, 1, true);
// assertNotNull("No conflicting assignment in trigger", trigger.getConflictingAssignment());
// assertEquals("Wrong conflicting assignment in trigger", ROLE_JUDGE_OID, trigger.getConflictingAssignment().getTarget().getOid());
ObjectDelta<UserType> focusSecondaryDelta = context.getFocusContext().getSecondaryDelta();
PrismAsserts.assertIsModify(focusSecondaryDelta);
PrismAsserts.assertModifications(focusSecondaryDelta, 2);
ContainerDelta<AssignmentType> assignmentDelta = focusSecondaryDelta.findContainerDelta(FocusType.F_ASSIGNMENT);
assertEquals("Unexpected assignment secondary delta", 1, assignmentDelta.getValuesToDelete().size());
PrismContainerValue<AssignmentType> deletedAssignment = assignmentDelta.getValuesToDelete().iterator().next();
assertEquals("Wrong OID in deleted assignment", ROLE_JUDGE_OID, deletedAssignment.asContainerable().getTargetRef().getOid());
ObjectDelta<ShadowType> accountSecondaryDelta = assertAssignAccountToJack(context);
PrismAsserts.assertPropertyAdd(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME), "Constable");
PrismAsserts.assertPropertyDelete(accountSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME), "Honorable Justice");
}
Aggregations