Search in sources :

Example 41 with Containerable

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

the class TestDummySchemaless method resourceStaticSchemaResourceAndConnectorCaching.

private void resourceStaticSchemaResourceAndConnectorCaching() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = createOperationResult();
    // re-read the resource before tests so we have a clean slate, e.g. configuration properly parsed (no raw elements)
    resourceStaticSchema = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
    ConnectorInstance currentConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
    IntegrationTestTools.displayXml("Initialized static schema resource", resourceStaticSchema);
    rememberCounter(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT);
    rememberCounter(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT);
    rememberCounter(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
    rememberCounter(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT);
    rememberCounter(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT);
    rememberCounter(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT);
    rememberSchemaMetadata(resourceStaticSchema);
    rememberConnectorInstance(currentConnectorInstance);
    rememberResourceCacheStats();
    ConnectorInstance configuredConnectorInstance = resourceManager.getConfiguredConnectorInstance(resourceStaticSchema, ReadCapabilityType.class, false, result);
    assertNotNull("No configuredConnectorInstance", configuredConnectorInstance);
    ResourceSchema resourceSchemaBefore = ResourceSchemaFactory.getRawSchema(resourceStaticSchema);
    assertNotNull("No resource schema", resourceSchemaBefore);
    assertStaticSchemaSanity(resourceSchemaBefore);
    // WHEN
    when();
    PrismObject<ResourceType> resourceAgain = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_STATIC_SCHEMA_OID, null, task, result);
    // THEN
    then();
    assertSuccess(result);
    ResourceType resourceTypeAgain = resourceAgain.asObjectable();
    assertNotNull("No connector ref", resourceTypeAgain.getConnectorRef());
    assertNotNull("No connector ref OID", resourceTypeAgain.getConnectorRef().getOid());
    PrismContainer<Containerable> configurationContainer = resourceStaticSchema.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 = ResourceSchemaFactory.getRawSchema(resourceAgain);
    assertNotNull("No resource schema (again)", resourceSchemaAgain);
    assertSame("Resource schema was not cached", resourceSchemaBefore, resourceSchemaAgain);
    // Check capabilities caching
    CapabilitiesType capabilitiesType = resourceStaticSchema.asObjectable().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
    resourceStaticSchema.asObjectable().setFetchResult(null);
    resourceAgain.asObjectable().setFetchResult(null);
    ObjectDelta<ResourceType> dummyResourceDiff = DiffUtil.diff(resourceStaticSchema, resourceAgain);
    displayDumpable("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);
    assertSame("Connector instance was not cached", configuredConnectorInstance, configuredConnectorInstanceAgain);
    // Check if the connector still works.
    OperationResult testResult = createOperationResult("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);
    assertSame("Connector instance was not cached", configuredConnectorInstanceAgain, configuredConnectorInstanceAfterTest);
    assertSteadyResource();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorInstance(com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Containerable(com.evolveum.midpoint.prism.Containerable)

Example 42 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.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
Collection<? extends ResourceAttribute<?>> resolvePrimaryIdentifier(ProvisioningContext ctx, Collection<? extends ResourceAttribute<?>> identifiers, final String desc, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (identifiers == null) {
        return null;
    }
    ResourceObjectDefinition objDef = ctx.getObjectDefinitionRequired();
    Collection<ResourceAttribute<?>> secondaryIdentifiers = ShadowUtil.getSecondaryIdentifiers(identifiers, objDef);
    PrismObject<ShadowType> repoShadow = shadowManager.lookupShadowBySecondaryIds(ctx, secondaryIdentifiers, result);
    if (repoShadow == null) {
        return null;
    }
    shadowsFacade.applyDefinition(repoShadow, ctx.getTask(), result);
    PrismContainer<Containerable> attributesContainer = repoShadow.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        return null;
    }
    Collection primaryIdentifiers = new ArrayList<>();
    for (PrismProperty property : attributesContainer.getValue().getProperties()) {
        if (objDef.isPrimaryIdentifier(property.getElementName())) {
            ResourceAttributeDefinition<?> attrDef = objDef.findAttributeDefinition(property.getElementName());
            if (attrDef == null) {
                throw new IllegalStateException("No definition for attribute " + property);
            }
            ResourceAttribute primaryIdentifier = attrDef.instantiate();
            primaryIdentifier.setRealValue(property.getRealValue());
            primaryIdentifiers.add(primaryIdentifier);
        }
    }
    LOGGER.trace("Resolved identifiers {} to primary identifiers {} (object class {})", identifiers, primaryIdentifiers, objDef);
    return primaryIdentifiers;
}
Also used : PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ResourceObjectDefinition(com.evolveum.midpoint.schema.processor.ResourceObjectDefinition) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Containerable(com.evolveum.midpoint.prism.Containerable) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

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