Search in sources :

Example 1 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class TestUtil method setAttribute.

public static void setAttribute(PrismObject<ShadowType> account, QName attrName, QName typeName, PrismContext prismContext, String value) throws SchemaException {
    PrismContainer<Containerable> attributesContainer = account.findContainer(ShadowType.F_ATTRIBUTES);
    ResourceAttributeDefinition attrDef = new ResourceAttributeDefinitionImpl(attrName, typeName, prismContext);
    ResourceAttribute attribute = attrDef.instantiate();
    attribute.setRealValue(value);
    attributesContainer.add(attribute);
}
Also used : ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute) ResourceAttributeDefinitionImpl(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinitionImpl)

Example 2 with Containerable

use of com.evolveum.midpoint.prism.Containerable 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 3 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class ResourceObjectReferenceResolver method resolvePrimaryIdentifier.

/**
	 * Resolve primary identifier from a collection of identifiers that may contain only secondary identifiers. 
	 */
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (identifiers == null) {
        return null;
    }
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, ctx.getObjectClassDefinition());
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIdentifiers(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        return null;
    }
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        return null;
    }
    RefinedObjectClassDefinition ocDef = ctx.getObjectClassDefinition();
    Collection primaryIdentifiers = new ArrayList<>();
    for (PrismProperty<?> property : attributesContainer.getValue().getProperties()) {
        if (ocDef.isPrimaryIdentifier(property.getElementName())) {
            RefinedAttributeDefinition<?> attrDef = ocDef.findAttributeDefinition(property.getElementName());
            ResourceAttribute<?> primaryIdentifier = new ResourceAttribute<>(property.getElementName(), attrDef, prismContext);
            primaryIdentifier.setRealValue(property.getRealValue());
            primaryIdentifiers.add(primaryIdentifier);
        }
    }
    LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, ocDef);
    return primaryIdentifiers;
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Example 4 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test030ResourceAndConnectorCaching.

@Test
public void test030ResourceAndConnectorCaching() throws Exception {
    TestUtil.displayTestTile("test030ResourceAndConnectorCaching");
    // GIVEN
    OperationResult result = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching");
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    // Check resource schema caching
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
    // Check capabilities caching
    CapabilitiesType capabilitiesType = resourceType.getCapabilities();
    assertNotNull("No capabilities fetched from provisioning", capabilitiesType);
    CachingMetadataType capCachingMetadataType = capabilitiesType.getCachingMetadata();
    assertNotNull("No capabilities caching metadata fetched from provisioning", capCachingMetadataType);
    CachingMetadataType capCachingMetadataTypeAgain = resourceTypeAgain.getCapabilities().getCachingMetadata();
    assertEquals("Capabilities caching metadata serial number has changed", capCachingMetadataType.getSerialNumber(), capCachingMetadataTypeAgain.getSerialNumber());
    assertEquals("Capabilities caching metadata timestamp has changed", capCachingMetadataType.getRetrievalTimestamp(), capCachingMetadataTypeAgain.getRetrievalTimestamp());
    // Rough test if everything is fine
    resource.asObjectable().setFetchResult(null);
    resourceAgain.asObjectable().setFetchResult(null);
    ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resource, resourceAgain);
    display("Dummy resource diff", dummyResourceDiff);
    assertTrue("The resource read again is not the same as the original. diff:" + dummyResourceDiff, dummyResourceDiff.isEmpty());
    // Now we stick our nose deep inside the provisioning impl. But we need
    // to make sure that the
    // configured connector is properly cached
    ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
    assertTrue("Connector instance was not cached", configuredConnectorInstance == configuredConnectorInstanceAgain);
    // Check if the connector still works.
    OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test010ResourceAndConnectorCaching.test");
    configuredConnectorInstanceAgain.test(testResult);
    testResult.computeStatus();
    TestUtil.assertSuccess("Connector test failed", testResult);
    // Test connection should also refresh the connector by itself. So check if it has been refreshed
    ConnectorInstance configuredConnectorInstanceAfterTest = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAfterTest);
    assertTrue("Connector instance was not cached", configuredConnectorInstanceAgain == configuredConnectorInstanceAfterTest);
    assertSteadyResource();
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) CapabilitiesType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilitiesType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) Test(org.testng.annotations.Test)

Example 5 with Containerable

use of com.evolveum.midpoint.prism.Containerable in project midpoint by Evolveum.

the class AbstractBasicDummyTest method test031ResourceAndConnectorCachingForceFresh.

@Test
public void test031ResourceAndConnectorCachingForceFresh() throws Exception {
    TestUtil.displayTestTile("test031ResourceAndConnectorCachingForceFresh");
    // GIVEN
    OperationResult result = new OperationResult(AbstractBasicDummyTest.class.getName() + ".test011ResourceAndConnectorCachingForceFresh");
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resource, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    assertNotNull("No resource schema", resourceSchema);
    // WHEN
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, null, result);
    // THEN
    result.computeStatus();
    display("getObject result", result);
    TestUtil.assertSuccess(result);
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    PrismContainer<Containerable> configurationContainerAgain = resourceAgain.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertTrue("Configurations not equivalent", configurationContainer.equivalent(configurationContainerAgain));
    ResourceSchema resourceSchemaAgain = RefinedResourceSchemaImpl.getResourceSchema(resourceAgain, prismContext);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertTrue("Resource schema was not cached", resourceSchema == resourceSchemaAgain);
    // Now we stick our nose deep inside the provisioning impl. But we need
    // to make sure that the configured connector is properly refreshed
    // forceFresh = true
    ConnectorInstance configuredConnectorInstanceAgain = resourceManager.getConfiguredConnectorInstance(resourceAgain, ReadCapabilityType.class, true, result);
    assertNotNull("No configuredConnectorInstance (again)", configuredConnectorInstanceAgain);
    assertFalse("Connector instance was not refreshed", configuredConnectorInstance == configuredConnectorInstanceAgain);
    // Check if the connector still works
    OperationResult testResult = new OperationResult(TestOpenDj.class.getName() + ".test011ResourceAndConnectorCachingForceFresh.test");
    configuredConnectorInstanceAgain.test(testResult);
    testResult.computeStatus();
    TestUtil.assertSuccess("Connector test failed", testResult);
    assertConnectorInitializationCountIncrement(1);
    rememberConnectorInstance(configuredConnectorInstanceAgain);
    assertSteadyResource();
}
Also used : ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) Containerable(com.evolveum.midpoint.prism.Containerable) Test(org.testng.annotations.Test)

Aggregations

Containerable (com.evolveum.midpoint.prism.Containerable)42 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 ArrayList (java.util.ArrayList)12 Test (org.testng.annotations.Test)10 Task (com.evolveum.midpoint.task.api.Task)9 PrismObject (com.evolveum.midpoint.prism.PrismObject)7 Collection (java.util.Collection)6 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)5 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)5 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 QName (javax.xml.namespace.QName)5 IModel (org.apache.wicket.model.IModel)5 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)4 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)4 PrismPropertyWrapperColumn (com.evolveum.midpoint.gui.impl.component.data.column.PrismPropertyWrapperColumn)4 Item (com.evolveum.midpoint.prism.Item)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 List (java.util.List)4