Search in sources :

Example 6 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class ShadowManager method createSearchShadowQuery.

private ObjectQuery createSearchShadowQuery(ProvisioningContext ctx, PrismObject<ShadowType> resourceShadow, PrismContext prismContext, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(resourceShadow);
    PrismProperty identifier = attributesContainer.getPrimaryIdentifier();
    Collection<PrismPropertyValue<Object>> idValues = identifier.getValues();
    // Only one value is supported for an identifier
    if (idValues.size() > 1) {
        // TODO: This should probably be switched to checked exception later
        throw new IllegalArgumentException("More than one identifier value is not supported");
    }
    if (idValues.size() < 1) {
        // TODO: This should probably be switched to checked exception later
        throw new IllegalArgumentException("The identifier has no value");
    }
    // We have all the data, we can construct the filter now
    try {
        // TODO TODO TODO TODO: set matching rule instead of null
        PrismPropertyDefinition def = identifier.getDefinition();
        return QueryBuilder.queryFor(ShadowType.class, prismContext).itemWithDef(def, ShadowType.F_ATTRIBUTES, def.getName()).eq(getNormalizedValue(identifier, ctx.getObjectClassDefinition())).and().item(ShadowType.F_OBJECT_CLASS).eq(resourceShadow.getPropertyRealValue(ShadowType.F_OBJECT_CLASS, QName.class)).and().item(ShadowType.F_RESOURCE_REF).ref(ctx.getResourceOid()).build();
    } catch (SchemaException e) {
        throw new SchemaException("Schema error while creating search filter: " + e.getMessage(), e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 7 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class AbstractModelIntegrationTest method addAttributeToShadow.

protected <T> void addAttributeToShadow(PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, String attrName, T attrValue) throws SchemaException {
    ResourceAttributeContainer attrs = ShadowUtil.getAttributesContainer(shadow);
    ResourceAttributeDefinition attrSnDef = attrs.getDefinition().findAttributeDefinition(new QName(ResourceTypeUtil.getResourceNamespace(resource), attrName));
    ResourceAttribute<T> attr = attrSnDef.instantiate();
    attr.setRealValue(attrValue);
    attrs.add(attr);
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)

Example 8 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class TestDummy method testLiveSyncDeleteCorsairs.

public void testLiveSyncDeleteCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    if (isNameUnique()) {
        dummyResource.deleteGroupByName(GROUP_CORSAIRS_NAME);
    } else {
        dummyResource.deleteGroupById(corsairsIcfUid);
    }
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
        ShadowType oldShadowType = oldShadow.asObjectable();
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
        assertNotNull("No attributes container in old shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
        assertNotNull("No ICF name attribute in old  shadow", icfsNameAttribute);
        assertEquals("Wrong value of ICF name attribute in old  shadow", GROUP_CORSAIRS_NAME, icfsNameAttribute.getRealValue());
        ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
        assertNotNull("Delta missing", objectDelta);
        assertEquals("Wrong delta changetype", ChangeType.DELETE, objectDelta.getChangeType());
        PrismAsserts.assertClass("delta", ShadowType.class, objectDelta);
        assertNotNull("No OID in delta", objectDelta.getOid());
        assertNull("Unexpected current shadow", lastChange.getCurrentShadow());
        try {
            // The shadow should be gone
            PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
            AssertJUnit.fail("The shadow " + repoShadow + " is not gone from repo");
        } catch (ObjectNotFoundException e) {
        // This is expected
        }
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 9 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class TestDummy method testLiveSyncAddCorsairs.

public void testLiveSyncAddCorsairs(final String TEST_NAME, DummySyncStyle syncStyle, QName objectClass, boolean expectReaction) throws Exception {
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestDummy.class.getName() + "." + TEST_NAME);
    syncServiceMock.reset();
    dummyResource.setSyncStyle(syncStyle);
    DummyGroup newGroup = new DummyGroup(GROUP_CORSAIRS_NAME);
    newGroup.setEnabled(true);
    dummyResource.addGroup(newGroup);
    corsairsIcfUid = newGroup.getId();
    display("Resource before sync", dummyResource.debugDump());
    ResourceShadowDiscriminator coords = new ResourceShadowDiscriminator(RESOURCE_DUMMY_OID, objectClass);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    provisioningService.synchronize(coords, syncTokenTask, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    display("Synchronization result", result);
    TestUtil.assertSuccess("Synchronization result is not OK", result);
    if (expectReaction) {
        syncServiceMock.assertNotifyChange();
        ResourceObjectShadowChangeDescription lastChange = syncServiceMock.getLastChange();
        display("The change", lastChange);
        PrismObject<? extends ShadowType> oldShadow = lastChange.getOldShadow();
        assertNotNull("Old shadow missing", oldShadow);
        assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
        if (syncStyle == DummySyncStyle.DUMB) {
            assertNull("Delta present when not expecting it", lastChange.getObjectDelta());
        } else {
            ObjectDelta<? extends ShadowType> objectDelta = lastChange.getObjectDelta();
            assertNotNull("Delta present when not expecting it", objectDelta);
            assertTrue("Delta is not add: " + objectDelta, objectDelta.isAdd());
        }
        ShadowType currentShadowType = lastChange.getCurrentShadow().asObjectable();
        assertNotNull("Current shadow missing", lastChange.getCurrentShadow());
        PrismAsserts.assertClass("current shadow", ShadowType.class, currentShadowType);
        ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(currentShadowType);
        assertNotNull("No attributes container in current shadow", attributesContainer);
        Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
        assertFalse("Attributes container is empty", attributes.isEmpty());
        assertEquals("Unexpected number of attributes", 2, attributes.size());
        corsairsShadowOid = currentShadowType.getOid();
        PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, corsairsShadowOid, null, result);
        display("Corsairs repo shadow", repoShadow);
        PrismObject<ShadowType> accountRepo = findShadowByName(new QName(RESOURCE_DUMMY_NS, SchemaConstants.GROUP_OBJECT_CLASS_LOCAL_NAME), GROUP_CORSAIRS_NAME, resource, result);
        assertNotNull("Shadow was not created in the repository", accountRepo);
        display("Repository shadow", accountRepo);
        ProvisioningTestUtil.checkRepoShadow(repoShadow, ShadowKindType.ENTITLEMENT);
    } else {
        syncServiceMock.assertNoNotifyChange();
    }
    checkAllShadows();
    assertSteadyResource();
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup)

Example 10 with ResourceAttributeContainer

use of com.evolveum.midpoint.schema.processor.ResourceAttributeContainer in project midpoint by Evolveum.

the class TestDummy method assertSyncOldShadow.

protected void assertSyncOldShadow(PrismObject<? extends ShadowType> oldShadow, String repoName, Integer expectedNumberOfAttributes) {
    assertNotNull("Old shadow missing", oldShadow);
    assertNotNull("Old shadow does not have an OID", oldShadow.getOid());
    PrismAsserts.assertClass("old shadow", ShadowType.class, oldShadow);
    ShadowType oldShadowType = oldShadow.asObjectable();
    ResourceAttributeContainer attributesContainer = ShadowUtil.getAttributesContainer(oldShadowType);
    assertNotNull("No attributes container in old shadow", attributesContainer);
    Collection<ResourceAttribute<?>> attributes = attributesContainer.getAttributes();
    assertFalse("Attributes container is empty", attributes.isEmpty());
    if (expectedNumberOfAttributes != null) {
        assertEquals("Unexpected number of attributes", (int) expectedNumberOfAttributes, attributes.size());
    }
    ResourceAttribute<?> icfsNameAttribute = attributesContainer.findAttribute(SchemaConstants.ICFS_NAME);
    assertNotNull("No ICF name attribute in old  shadow", icfsNameAttribute);
    assertEquals("Wrong value of ICF name attribute in old  shadow", repoName, icfsNameAttribute.getRealValue());
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceAttributeContainer(com.evolveum.midpoint.schema.processor.ResourceAttributeContainer) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

ResourceAttributeContainer (com.evolveum.midpoint.schema.processor.ResourceAttributeContainer)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)20 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)16 QName (javax.xml.namespace.QName)16 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 Test (org.testng.annotations.Test)8 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)6 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)6 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)6 PrismObject (com.evolveum.midpoint.prism.PrismObject)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 Task (com.evolveum.midpoint.task.api.Task)5 ShadowAssociationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType)5 RefinedAttributeDefinition (com.evolveum.midpoint.common.refinery.RefinedAttributeDefinition)4 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PropertyModificationOperation (com.evolveum.midpoint.provisioning.ucf.api.PropertyModificationOperation)3 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)3