Search in sources :

Example 1 with ShadowAssociationType

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

the class OutboundProcessor method processOutbound.

public <F extends FocusType> void processOutbound(LensContext<F> context, LensProjectionContext projCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    ResourceShadowDiscriminator discr = projCtx.getResourceShadowDiscriminator();
    ObjectDelta<ShadowType> projectionDelta = projCtx.getDelta();
    if (projectionDelta != null && projectionDelta.getChangeType() == ChangeType.DELETE) {
        LOGGER.trace("Processing outbound expressions for {} skipped, DELETE account delta", discr);
        // No point in evaluating outbound
        return;
    }
    LOGGER.trace("Processing outbound expressions for {} starting", discr);
    RefinedObjectClassDefinition rOcDef = projCtx.getStructuralObjectClassDefinition();
    if (rOcDef == null) {
        LOGGER.error("Definition for {} not found in the context, but it should be there, dumping context:\n{}", discr, context.debugDump());
        throw new IllegalStateException("Definition for " + discr + " not found in the context, but it should be there");
    }
    ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
    ObjectDeltaObject<ShadowType> projectionOdo = projCtx.getObjectDeltaObject();
    Construction<F> outboundConstruction = new Construction<>(null, projCtx.getResource());
    outboundConstruction.setRefinedObjectClassDefinition(rOcDef);
    Collection<RefinedObjectClassDefinition> auxiliaryObjectClassDefinitions = rOcDef.getAuxiliaryObjectClassDefinitions();
    if (auxiliaryObjectClassDefinitions != null) {
        for (RefinedObjectClassDefinition auxiliaryObjectClassDefinition : auxiliaryObjectClassDefinitions) {
            outboundConstruction.addAuxiliaryObjectClassDefinition(auxiliaryObjectClassDefinition);
        }
    }
    String operation = projCtx.getOperation().getValue();
    for (QName attributeName : rOcDef.getNamesOfAttributesWithOutboundExpressions()) {
        RefinedAttributeDefinition<?> refinedAttributeDefinition = rOcDef.findAttributeDefinition(attributeName);
        final MappingType outboundMappingType = refinedAttributeDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        if (refinedAttributeDefinition.isIgnored(LayerType.MODEL)) {
            LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", attributeName);
            continue;
        }
        Mapping.Builder<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> builder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(refinedAttributeDefinition.getName()) + " in " + rOcDef.getResourceType());
        builder = builder.originObject(rOcDef.getResourceType()).originType(OriginType.OUTBOUND);
        Mapping<PrismPropertyValue<?>, RefinedAttributeDefinition<?>> evaluatedMapping = evaluateMapping(builder, attributeName, refinedAttributeDefinition, focusOdo, projectionOdo, operation, rOcDef, null, context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAttributeMapping(evaluatedMapping);
        }
    }
    for (QName assocName : rOcDef.getNamesOfAssociationsWithOutboundExpressions()) {
        RefinedAssociationDefinition associationDefinition = rOcDef.findAssociationDefinition(assocName);
        final MappingType outboundMappingType = associationDefinition.getOutboundMappingType();
        if (outboundMappingType == null) {
            continue;
        }
        //			if (associationDefinition.isIgnored(LayerType.MODEL)) {
        //				LOGGER.trace("Skipping processing outbound mapping for attribute {} because it is ignored", assocName);
        //				continue;
        //			}
        Mapping.Builder<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> mappingBuilder = mappingFactory.createMappingBuilder(outboundMappingType, "outbound mapping for " + PrettyPrinter.prettyPrint(associationDefinition.getName()) + " in " + rOcDef.getResourceType());
        PrismContainerDefinition<ShadowAssociationType> outputDefinition = getAssociationContainerDefinition();
        Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> evaluatedMapping = (Mapping) evaluateMapping(mappingBuilder, assocName, outputDefinition, focusOdo, projectionOdo, operation, rOcDef, associationDefinition.getAssociationTarget(), context, projCtx, task, result);
        if (evaluatedMapping != null) {
            outboundConstruction.addAssociationMapping(evaluatedMapping);
        }
    }
    projCtx.setOutboundConstruction(outboundConstruction);
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) RefinedAssociationDefinition(com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedAttributeDefinition(com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Construction(com.evolveum.midpoint.model.impl.lens.Construction) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 2 with ShadowAssociationType

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

the class ReconciliationProcessor method getIdentifiersForAssociationTarget.

@NotNull
private ResourceAttributeContainer getIdentifiersForAssociationTarget(PrismContainerValue<ShadowAssociationType> isCValue, Task task, OperationResult result) throws CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, ExpressionEvaluationException {
    ResourceAttributeContainer identifiersContainer = ShadowUtil.getAttributesContainer(isCValue, ShadowAssociationType.F_IDENTIFIERS);
    if (identifiersContainer != null) {
        return identifiersContainer;
    }
    String oid = isCValue.asContainerable().getShadowRef() != null ? isCValue.asContainerable().getShadowRef().getOid() : null;
    if (oid == null) {
        // TODO maybe warn/error log would suffice?
        throw new IllegalStateException("Couldn't evaluate tolerant/intolerant values for association " + isCValue + ", because there are no identifiers and no shadow reference present");
    }
    PrismObject<ShadowType> target;
    try {
        GetOperationOptions rootOpt = GetOperationOptions.createPointInTimeType(PointInTimeType.FUTURE);
        rootOpt.setNoFetch(true);
        target = provisioningService.getObject(ShadowType.class, oid, SelectorOptions.createCollection(rootOpt), task, result);
    } catch (ObjectNotFoundException e) {
        // TODO maybe warn/error log would suffice (also for other exceptions?)
        throw new ObjectNotFoundException("Couldn't evaluate tolerant/intolerant values for association " + isCValue + ", because the association target object does not exist: " + e.getMessage(), e);
    }
    identifiersContainer = ShadowUtil.getAttributesContainer(target);
    if (identifiersContainer == null) {
        // TODO maybe warn/error log would suffice?
        throw new IllegalStateException("Couldn't evaluate tolerant/intolerant values for association " + isCValue + ", because there are no identifiers present, even in the repository object for association target");
    }
    return identifiersContainer;
}
Also used : GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ShadowAssociationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType 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();
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions)

Example 4 with ShadowAssociationType

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

the class TestIntegrationObjectWrapperFactory method test220AssignRoleLandluberToWally.

@Test
public void test220AssignRoleLandluberToWally() throws Exception {
    final String TEST_NAME = "test220AssignRoleLandluberToWally";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestIntegrationObjectWrapperFactory.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    DummyGroup mapmakers = new DummyGroup(GROUP_DUMMY_MAPMAKERS_NAME);
    dummyResource.addGroup(mapmakers);
    PrismObject<UserType> user = createUser(USER_WALLY_NAME, USER_WALLY_FULLNAME, true);
    addObject(user);
    userWallyOid = user.getOid();
    assignRole(userWallyOid, ROLE_MAPMAKER_OID, task, result);
    // preconditions
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userAfter = getUser(userWallyOid);
    display("User after change execution", userAfter);
    accountWallyOid = getSingleLinkOid(userAfter);
    PrismObject<ShadowType> shadow = getShadowModel(accountWallyOid);
    shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
    display("Shadow", shadow);
    DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_MAPMAKERS_NAME);
    assertNotNull("No group on dummy resource", dummyGroup);
    display("Group", dummyGroup);
    assertGroupMember(dummyGroup, USER_WALLY_NAME);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
    ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Wrapper after", objectWrapper);
    WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
    assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
    ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
    WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), shadow.findContainer(ShadowType.F_ATTRIBUTES), true, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_WALLY_FULLNAME);
    WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
    assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
    ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
    WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
    WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
    ContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ASSOCIATION));
    assertNotNull("No association container wrapper", associationContainerWrapper);
    assertEquals("wrong number of items in " + associationContainerWrapper, 2, associationContainerWrapper.getItems().size());
    ItemWrapper groupAssociationWrapper = associationContainerWrapper.findPropertyWrapper(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
    assertNotNull("No group association property wrapper", groupAssociationWrapper);
    assertTrue("Wrong type of group association property wrapper: " + groupAssociationWrapper.getClass(), groupAssociationWrapper instanceof AssociationWrapper);
    List<ValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
    assertEquals("wrong number of values in " + groupAssociationWrapper, 1, groupAssociationValues.size());
    ValueWrapper groupAssociationValue = groupAssociationValues.get(0);
    PrismContainerValue<ShadowAssociationType> groupAssociationValuePVal = (PrismContainerValue<ShadowAssociationType>) groupAssociationValue.getValue();
    display("groupAssociationValuePVal", groupAssociationValuePVal);
    assertEquals("wrong number of values in " + groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
    assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationValuePVal.findProperty(ShadowAssociationType.F_NAME).getRealValue());
    PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
    PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null, "uid"));
    PrismAsserts.assertPropertyValue(groupAssociationUidProp, GROUP_DUMMY_MAPMAKERS_NAME);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ValueWrapper(com.evolveum.midpoint.web.component.prism.ValueWrapper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ContainerWrapper(com.evolveum.midpoint.web.component.prism.ContainerWrapper) ItemWrapper(com.evolveum.midpoint.web.component.prism.ItemWrapper) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) AssociationWrapper(com.evolveum.midpoint.web.component.prism.AssociationWrapper) ShadowIdentifiersType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowIdentifiersType) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 5 with ShadowAssociationType

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

the class Construction method evaluateAssociations.

private void evaluateAssociations(Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    associationMappings = new ArrayList<>();
    for (ResourceObjectAssociationType associationDefinitionType : getConstructionType().getAssociation()) {
        QName assocName = ItemPathUtil.getOnlySegmentQName(associationDefinitionType.getRef());
        if (assocName == null) {
            throw new SchemaException("No association name (ref) in association definition in construction in " + getSource());
        }
        MappingType outboundMappingType = associationDefinitionType.getOutbound();
        if (outboundMappingType == null) {
            throw new SchemaException("No outbound section in definition of association " + assocName + " in construction in " + getSource());
        }
        Mapping<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>> assocMapping = evaluateAssociation(associationDefinitionType, task, result);
        if (assocMapping != null) {
            associationMappings.add(assocMapping);
        }
    }
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) QName(javax.xml.namespace.QName) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ResourceObjectAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectAssociationType)

Aggregations

ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)21 QName (javax.xml.namespace.QName)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)11 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)6 ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)6 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)4 RefinedAssociationDefinition (com.evolveum.midpoint.common.refinery.RefinedAssociationDefinition)3 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)3 Mapping (com.evolveum.midpoint.model.common.mapping.Mapping)3 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)3 PropertyModificationOperation (com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)2 Construction (com.evolveum.midpoint.model.impl.lens.Construction)2 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2