Search in sources :

Example 61 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method createLensContext.

@NotNull
private <F extends FocusType> LensContext<F> createLensContext(Class<F> focusClass, ResourceObjectShadowChangeDescription change, SynchronizationReactionType reactionDefinition, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ModelExecuteOptions options, PrismObject<SystemConfigurationType> configuration, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    LensContext<F> context = contextFactory.createSyncContext(focusClass, change);
    context.setLazyAuditRequest(true);
    context.setSystemConfiguration(configuration);
    context.setOptions(options);
    ResourceType resource = change.getResource().asObjectable();
    if (ModelExecuteOptions.isLimitPropagation(options)) {
        context.setTriggeredResource(resource);
    }
    context.rememberResource(resource);
    PrismObject<ShadowType> shadow = getShadowFromChange(change);
    if (InternalsConfig.consistencyChecks)
        shadow.checkConsistence();
    // Projection context
    ShadowKindType kind = getKind(shadow, synchronizationPolicy);
    String intent = getIntent(shadow, synchronizationPolicy);
    boolean thombstone = isThombstone(change);
    ResourceShadowDiscriminator descr = new ResourceShadowDiscriminator(resource.getOid(), kind, intent, thombstone);
    LensProjectionContext projectionContext = context.createProjectionContext(descr);
    projectionContext.setResource(resource);
    projectionContext.setOid(getOidFromChange(change));
    projectionContext.setSynchronizationSituationDetected(situation.getSituation());
    // insert object delta if available in change
    ObjectDelta<? extends ShadowType> delta = change.getObjectDelta();
    if (delta != null) {
        projectionContext.setSyncDelta((ObjectDelta<ShadowType>) delta);
    } else {
        projectionContext.setSyncAbsoluteTrigger(true);
    }
    // we insert account if available in change
    PrismObject<ShadowType> currentAccount = shadow;
    if (currentAccount != null) {
        projectionContext.setLoadedObject(currentAccount);
        if (!thombstone) {
            projectionContext.setFullShadow(true);
        }
        projectionContext.setFresh(true);
    }
    if (delta != null && delta.isDelete()) {
        projectionContext.setExists(false);
    } else {
        projectionContext.setExists(true);
    }
    projectionContext.setDoReconciliation(ModelExecuteOptions.isReconcile(options));
    // Focus context
    if (situation.getCurrentOwner() != null) {
        F focusType = situation.getCurrentOwner();
        LensFocusContext<F> focusContext = context.createFocusContext();
        PrismObject<F> focusOld = (PrismObject<F>) focusType.asPrismObject();
        focusContext.setLoadedObject(focusOld);
    }
    // Global stuff
    ObjectReferenceType objectTemplateRef = null;
    if (reactionDefinition.getObjectTemplateRef() != null) {
        objectTemplateRef = reactionDefinition.getObjectTemplateRef();
    } else if (synchronizationPolicy.getObjectTemplateRef() != null) {
        objectTemplateRef = synchronizationPolicy.getObjectTemplateRef();
    }
    if (objectTemplateRef != null) {
        ObjectTemplateType objectTemplate = repositoryService.getObject(ObjectTemplateType.class, objectTemplateRef.getOid(), null, parentResult).asObjectable();
        context.setFocusTemplate(objectTemplate);
    }
    return context;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method determineSituationWithCorrelation.

/**
	 * account is not linked to user. you have to use correlation and
	 * confirmation rule to be sure user for this account doesn't exists
	 * resourceShadow only contains the data that were in the repository before
	 * the change. But the correlation/confirmation should work on the updated
	 * data. Therefore let's apply the changes before running
	 * correlation/confirmation
	 */
private <F extends FocusType> SynchronizationSituation determineSituationWithCorrelation(Class<F> focusType, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, PrismObject<F> owner, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (ChangeType.DELETE.equals(getModificationType(change))) {
        // account was deleted and we know it didn't have owner
        return new SynchronizationSituation<>(owner == null ? null : owner.asObjectable(), null, SynchronizationSituationType.DELETED);
    }
    PrismObject<? extends ShadowType> resourceShadow = change.getCurrentShadow();
    ObjectDelta syncDelta = change.getObjectDelta();
    if (resourceShadow == null && syncDelta != null && ChangeType.ADD.equals(syncDelta.getChangeType())) {
        LOGGER.trace("Trying to compute current shadow from change delta add.");
        PrismObject<ShadowType> shadow = syncDelta.computeChangedObject(syncDelta.getObjectToAdd());
        resourceShadow = shadow;
        change.setCurrentShadow(shadow);
    }
    Validate.notNull(resourceShadow, "Current shadow must not be null.");
    ResourceType resource = change.getResource().asObjectable();
    validateResourceInShadow(resourceShadow.asObjectable(), resource);
    SynchronizationSituationType state = null;
    LOGGER.trace("SYNCHRONIZATION: CORRELATION: Looking for list of {} objects based on correlation rule.", focusType.getSimpleName());
    List<PrismObject<F>> users = correlationConfirmationEvaluator.findFocusesByCorrelationRule(focusType, resourceShadow.asObjectable(), synchronizationPolicy.getCorrelation(), resource, configurationType, task, result);
    if (users == null) {
        users = new ArrayList<>();
    }
    if (users.size() > 1) {
        if (synchronizationPolicy.getConfirmation() == null) {
            LOGGER.trace("SYNCHRONIZATION: CONFIRMATION: no confirmation defined.");
        } else {
            LOGGER.debug("SYNCHRONIZATION: CONFIRMATION: Checking objects from correlation with confirmation rule.");
            users = correlationConfirmationEvaluator.findUserByConfirmationRule(focusType, users, resourceShadow.asObjectable(), resource, configurationType, synchronizationPolicy.getConfirmation(), task, result);
        }
    }
    F user = null;
    switch(users.size()) {
        case 0:
            state = SynchronizationSituationType.UNMATCHED;
            break;
        case 1:
            switch(getModificationType(change)) {
                case ADD:
                case MODIFY:
                    state = SynchronizationSituationType.UNLINKED;
                    break;
                case DELETE:
                    state = SynchronizationSituationType.DELETED;
                    break;
            }
            user = users.get(0).asObjectable();
            break;
        default:
            state = SynchronizationSituationType.DISPUTED;
    }
    return new SynchronizationSituation(null, user, state);
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) PrismObject(com.evolveum.midpoint.prism.PrismObject) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 63 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method matchUserCorrelationRule.

/**
	 * Tries to match specified focus and shadow. Return true if it matches,
	 * false otherwise.
	 */
@Override
public <F extends FocusType> boolean matchUserCorrelationRule(PrismObject<ShadowType> shadow, PrismObject<F> focus, ResourceType resourceType, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult result) throws ConfigurationException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ObjectSynchronizationType synchronizationPolicy = determineSynchronizationPolicy(resourceType, shadow, configuration, task, result);
    Class<F> focusClass;
    // be null...
    if (synchronizationPolicy != null) {
        focusClass = determineFocusClass(synchronizationPolicy, resourceType);
    } else {
        focusClass = (Class) focus.asObjectable().getClass();
    }
    return correlationConfirmationEvaluator.matchUserCorrelationRule(focusClass, shadow, focus, synchronizationPolicy, resourceType, configuration == null ? null : configuration.asObjectable(), task, result);
}
Also used : ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType)

Example 64 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class InactivateShadowAction method handle.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.sync.Action#handle(com.evolveum.midpoint.model.lens.LensContext, com.evolveum.midpoint.model.sync.SynchronizationSituation, java.util.Map, com.evolveum.midpoint.task.api.Task, com.evolveum.midpoint.schema.result.OperationResult)
	 */
@Override
public <F extends FocusType> void handle(LensContext<F> context, SynchronizationSituation<F> situation, Map<QName, Object> parameters, Task task, OperationResult parentResult) {
    ActivationStatusType desiredStatus = ActivationStatusType.DISABLED;
    LensProjectionContext projectionContext = context.getProjectionContextsIterator().next();
    PrismObject<ShadowType> objectCurrent = projectionContext.getObjectCurrent();
    if (objectCurrent != null) {
        PrismProperty<Object> administrativeStatusProp = objectCurrent.findProperty(SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS);
        if (administrativeStatusProp != null) {
            if (desiredStatus.equals(administrativeStatusProp.getRealValue())) {
                // Desired status already set, nothing to do
                return;
            }
        }
    }
    ObjectDelta<ShadowType> activationDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, projectionContext.getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, getPrismContext(), desiredStatus);
    projectionContext.setPrimaryDelta(activationDelta);
}
Also used : ActivationStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 65 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class TestActivation method assertEffectiveStatus.

private <F extends FocusType> void assertEffectiveStatus(PrismObject<F> focus, ActivationStatusType expected) {
    ActivationType activation = focus.asObjectable().getActivation();
    assertNotNull("No activation in " + focus, activation);
    assertEquals("Unexpected effective activation status in " + focus, expected, activation.getEffectiveStatus());
}
Also used : ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7