Search in sources :

Example 26 with ShadowType

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

the class ShadowIntegrityCheckResultHandler method doFixIntent.

private void doFixIntent(ShadowCheckResult checkResult, PrismObject<ShadowType> fetchedShadow, PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, Task task, OperationResult result) {
    PrismObject<ShadowType> fullShadow;
    if (!checkFetch) {
        fullShadow = fetchShadow(checkResult, shadow, resource, task, result);
    } else {
        fullShadow = fetchedShadow;
    }
    if (fullShadow == null) {
        checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Cannot fix missing intent, because the resource object couldn't be fetched"));
        return;
    }
    ObjectSynchronizationType synchronizationPolicy;
    try {
        synchronizationPolicy = synchronizationService.determineSynchronizationPolicy(resource.asObjectable(), fullShadow, configuration, task, result);
    } catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException e) {
        checkResult.recordError(Statistics.CANNOT_APPLY_FIX, new SystemException("Couldn't prepare fix for missing intent, because the synchronization policy couldn't be determined", e));
        return;
    }
    if (synchronizationPolicy != null) {
        if (synchronizationPolicy.getIntent() != null) {
            PropertyDelta delta = PropertyDelta.createReplaceDelta(fullShadow.getDefinition(), ShadowType.F_INTENT, synchronizationPolicy.getIntent());
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Intent fix delta (not executed now) = \n{}", delta.debugDump());
            }
            checkResult.addFixDelta(delta, Statistics.NO_INTENT_SPECIFIED);
        } else {
            LOGGER.info("Synchronization policy does not contain intent: {}", synchronizationPolicy);
        }
    } else {
        LOGGER.info("Intent couldn't be fixed, because no synchronization policy was found");
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta)

Example 27 with ShadowType

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

the class ObjectMerger method takeProjections.

private void takeProjections(MergeStategyType strategy, List<ShadowType> mergedProjections, List<ShadowType> matchedProjections, List<ShadowType> candidateProjections, List<ShadowType> projectionsLeft, List<ShadowType> projectionsRight, ProjectionMergeConfigurationType projectionMergeConfig) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("TAKE: Evaluating situation {}, discriminator: {}", projectionMergeConfig.getSituation(), projectionMergeConfig.getProjectionDiscriminator());
    }
    for (ShadowType candidateProjection : candidateProjections) {
        if (projectionMatches(candidateProjection, projectionsLeft, projectionsRight, projectionMergeConfig)) {
            LOGGER.trace("Projection matches {}", candidateProjection);
            matchedProjections.add(candidateProjection);
            if (strategy == MergeStategyType.TAKE) {
                mergedProjections.add(candidateProjection);
            } else if (strategy == null || strategy == MergeStategyType.IGNORE) {
            // Nothing to do here
            } else {
                throw new UnsupportedOperationException("Merge strategy " + strategy + " is not supported");
            }
        } else {
            LOGGER.trace("Discriminator does NOT match {}", candidateProjection);
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 28 with ShadowType

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

the class TestRefinedSchema method assertAccountShadow.

private void assertAccountShadow(PrismObject<ShadowType> accObject, PrismObject<ResourceType> resource, PrismContext prismContext) throws SchemaException, JAXBException {
    ResourceType resourceType = resource.asObjectable();
    QName objectClassQName = new QName(ResourceTypeUtil.getResourceNamespace(resourceType), "AccountObjectClass");
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_NAME, createPolyString("jack"));
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_OBJECT_CLASS, objectClassQName);
    PrismAsserts.assertPropertyValue(accObject, ShadowType.F_INTENT, SchemaConstants.INTENT_DEFAULT);
    PrismContainer<?> attributes = accObject.findOrCreateContainer(SchemaConstants.C_ATTRIBUTES);
    assertEquals("Wrong type of <attributes> definition in account", ResourceAttributeContainerDefinitionImpl.class, attributes.getDefinition().getClass());
    ResourceAttributeContainerDefinition attrDef = (ResourceAttributeContainerDefinition) attributes.getDefinition();
    assertAttributeDefs(attrDef, resourceType, null, LayerType.MODEL);
    PrismAsserts.assertPropertyValue(attributes, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "cn"), "Jack Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "givenName"), "Jack");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "sn"), "Sparrow");
    PrismAsserts.assertPropertyValue(attributes, getAttrQName(resource, "uid"), "jack");
    assertEquals("JAXB class name doesn't match (1)", ShadowType.class, accObject.getCompileTimeClass());
    accObject.checkConsistence();
    ShadowType accObjectType = accObject.asObjectable();
    assertEquals("Wrong JAXB name", createPolyStringType("jack"), accObjectType.getName());
    assertEquals("Wrong JAXB objectClass", objectClassQName, accObjectType.getObjectClass());
    ShadowAttributesType attributesType = accObjectType.getAttributes();
    assertNotNull("null ResourceObjectShadowAttributesType (JAXB)", attributesType);
    List<Object> attributeElements = attributesType.getAny();
    TestUtil.assertElement(attributeElements, SchemaTestConstants.ICFS_NAME, "uid=jack,ou=People,dc=example,dc=com");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "cn"), "Jack Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "givenName"), "Jack");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "sn"), "Sparrow");
    TestUtil.assertElement(attributeElements, getAttrQName(resource, "uid"), "jack");
    String accString = PrismTestUtil.serializeObjectToString(accObjectType.asPrismObject());
    System.out.println("Result of JAXB marshalling:\n" + accString);
    accObject.checkConsistence(true, true, ConsistencyCheckScope.THOROUGH);
}
Also used : QName(javax.xml.namespace.QName) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowAttributesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 29 with ShadowType

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

the class TestRefinedSchema method testApplyAttributeDefinition.

@Test
public void testApplyAttributeDefinition() throws JAXBException, SchemaException, SAXException, IOException {
    System.out.println("\n===[ testApplyAttributeDefinition ]===\n");
    // GIVEN
    PrismContext prismContext = createInitializedPrismContext();
    PrismObject<ResourceType> resource = prismContext.parseObject(RESOURCE_COMPLEX_FILE);
    RefinedResourceSchema rSchema = RefinedResourceSchemaImpl.parse(resource, prismContext);
    RefinedObjectClassDefinition defaultAccountDefinition = rSchema.getDefaultRefinedDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("No refined default account definition in " + rSchema, defaultAccountDefinition);
    System.out.println("Refined account definition:");
    System.out.println(defaultAccountDefinition.debugDump());
    PrismObject<ShadowType> accObject = prismContext.parseObject(new File(TEST_DIR_NAME, "account-jack.xml"));
    PrismContainer<Containerable> attributesContainer = accObject.findContainer(ShadowType.F_ATTRIBUTES);
    System.out.println("Attributes container:");
    System.out.println(attributesContainer.debugDump());
    // WHEN
    attributesContainer.applyDefinition((PrismContainerDefinition) defaultAccountDefinition.toResourceAttributeContainerDefinition(), true);
    // THEN
    System.out.println("Parsed account:");
    System.out.println(accObject.debugDump());
    assertAccountShadow(accObject, resource, prismContext);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) File(java.io.File) Test(org.testng.annotations.Test)

Example 30 with ShadowType

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

the class AssociationFromLinkExpressionEvaluator method gatherAssociationsFromAbstractRole.

private void gatherAssociationsFromAbstractRole(AbstractRoleType thisRole, PrismContainer<ShadowAssociationType> output, String resourceOid, ShadowKindType kind, String intent, QName assocName, Collection<SelectorOptions<GetOperationOptions>> options, String desc, ExpressionEvaluationContext params) throws SchemaException {
    for (ObjectReferenceType linkRef : thisRole.getLinkRef()) {
        ShadowType shadowType;
        try {
            shadowType = objectResolver.resolve(linkRef, ShadowType.class, options, desc, params.getTask(), params.getResult());
        } catch (ObjectNotFoundException e) {
            // Linked shadow not found. This may happen e.g. if the account is deleted and model haven't got
            // the chance to react yet. Just ignore such shadow.
            LOGGER.trace("Ignoring shadow " + linkRef.getOid() + " linked in " + thisRole + " because it no longer exists");
            continue;
        }
        if (ShadowUtil.matches(shadowType, resourceOid, kind, intent)) {
            PrismContainerValue<ShadowAssociationType> newValue = output.createNewValue();
            ShadowAssociationType shadowAssociationType = newValue.asContainerable();
            shadowAssociationType.setName(assocName);
            ObjectReferenceType shadowRef = new ObjectReferenceType();
            shadowRef.setOid(linkRef.getOid());
            shadowAssociationType.setShadowRef(shadowRef);
        }
    }
}
Also used : ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ShadowAssociationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)426 Test (org.testng.annotations.Test)378 Task (com.evolveum.midpoint.task.api.Task)319 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)191 QName (javax.xml.namespace.QName)121 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)89 PrismObject (com.evolveum.midpoint.prism.PrismObject)87 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)79 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)78 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)76 ArrayList (java.util.ArrayList)74 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)72 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)69 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)64 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)61 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)50 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)47 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)47 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)46