Search in sources :

Example 6 with XmlSchemaType

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

the class ResourceManager method completeSchemaAndCapabilities.

private void completeSchemaAndCapabilities(PrismObject<ResourceType> resource, ResourceSchema resourceSchema, boolean fetchedSchema, Map<String, Collection<Object>> capabilityMap, Task task, OperationResult result) throws SchemaException, CommunicationException, ObjectNotFoundException, GenericFrameworkException, ConfigurationException {
    Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
    // Capabilities
    // we need to process capabilities first. Schema is one of the connector capabilities.
    // We need to determine this capability to select the right connector for schema retrieval.
    completeCapabilities(resource, capabilityMap != null, capabilityMap, modifications, result);
    if (resourceSchema == null) {
        // Try to get existing schema from resource. We do not want to override this if it exists
        // (but we still want to refresh the capabilities, that happens below)
        resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    }
    if (resourceSchema == null || resourceSchema.isEmpty()) {
        LOGGER.trace("Fetching resource schema for {}", resource);
        resourceSchema = fetchResourceSchema(resource, capabilityMap, task, result);
        if (resourceSchema == null) {
            LOGGER.warn("No resource schema fetched from {}", resource);
        } else if (resourceSchema.isEmpty()) {
            LOGGER.warn("Empty resource schema fetched from {}", resource);
        } else {
            LOGGER.debug("Fetched resource schema for {}: {} definitions", resource, resourceSchema.getDefinitions().size());
            fetchedSchema = true;
        }
    }
    if (fetchedSchema) {
        adjustSchemaForSimulatedCapabilities(resource, resourceSchema);
        ContainerDelta<XmlSchemaType> schemaContainerDelta = createSchemaUpdateDelta(resource, resourceSchema);
        modifications.add(schemaContainerDelta);
        // We have successfully fetched the resource schema. Therefore the resource must be up.
        modifications.add(createResourceAvailabilityStatusDelta(resource, AvailabilityStatusType.UP));
    }
    if (!modifications.isEmpty()) {
        try {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Completing {}:\n{}", resource, DebugUtil.debugDump(modifications, 1));
            }
            repositoryService.modifyObject(ResourceType.class, resource.getOid(), modifications, result);
        } catch (ObjectAlreadyExistsException ex) {
            // This should not happen
            throw new SystemException(ex);
        }
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 7 with XmlSchemaType

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

the class AbstractDummyTest method getSchemaCachingMetadata.

protected CachingMetadataType getSchemaCachingMetadata(PrismObject<ResourceType> resource) {
    ResourceType resourceType = resource.asObjectable();
    XmlSchemaType xmlSchemaTypeAfter = resourceType.getSchema();
    assertNotNull("No schema", xmlSchemaTypeAfter);
    Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceType);
    assertNotNull("No schema XSD element", resourceXsdSchemaElementAfter);
    return xmlSchemaTypeAfter.getCachingMetadata();
}
Also used : Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)

Example 8 with XmlSchemaType

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

the class AbstractDummyTest method assertHasSchema.

protected void assertHasSchema(PrismObject<ResourceType> resource, String desc) throws SchemaException {
    ResourceType resourceType = resource.asObjectable();
    display("Resource " + desc, resourceType);
    XmlSchemaType xmlSchemaTypeAfter = resourceType.getSchema();
    assertNotNull("No schema in " + desc, xmlSchemaTypeAfter);
    Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceType);
    assertNotNull("No schema XSD element in " + desc, resourceXsdSchemaElementAfter);
    String resourceXml = prismContext.serializeObjectToString(resource, PrismContext.LANG_XML);
    //		display("Resource XML", resourceXml);                            
    CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
    assertNotNull("No caching metadata in " + desc, cachingMetadata);
    assertNotNull("No retrievalTimestamp in " + desc, cachingMetadata.getRetrievalTimestamp());
    assertNotNull("No serialNumber in " + desc, cachingMetadata.getSerialNumber());
    Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
    ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resource.toString(), prismContext);
    assertNotNull("No schema after parsing in " + desc, parsedSchema);
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)

Example 9 with XmlSchemaType

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

the class TestDummyHacks method test003Connection.

/**
	 * This should be the very first test that works with the resource.
	 * 
	 * The original repository object does not have resource schema. The schema
	 * should be generated from the resource on the first use. This is the test
	 * that executes testResource and checks whether the schema was generated.
	 */
@Test
public void test003Connection() throws Exception {
    final String TEST_NAME = "test003Connection";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // Check that there is no schema before test (pre-condition)
    ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result).asObjectable();
    assertNotNull("No connector ref", resourceBefore.getConnectorRef());
    assertNotNull("No connector ref OID", resourceBefore.getConnectorRef().getOid());
    ConnectorType connector = repositoryService.getObject(ConnectorType.class, resourceBefore.getConnectorRef().getOid(), null, result).asObjectable();
    assertNotNull(connector);
    XmlSchemaType xmlSchemaTypeBefore = resourceBefore.getSchema();
    Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
    AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
    // WHEN
    OperationResult testResult = provisioningService.testResource(RESOURCE_DUMMY_OID, task);
    // THEN
    display("Test result", testResult);
    TestUtil.assertSuccess("Test resource failed (result)", testResult);
    PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
    ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
    display("Resource after test", resourceTypeRepoAfter);
    XmlSchemaType xmlSchemaTypeAfter = resourceTypeRepoAfter.getSchema();
    assertNotNull("No schema after test connection", xmlSchemaTypeAfter);
    Element resourceXsdSchemaElementAfter = ResourceTypeUtil.getResourceXsdSchema(resourceTypeRepoAfter);
    assertNotNull("No schema after test connection", resourceXsdSchemaElementAfter);
    String resourceXml = prismContext.serializeObjectToString(resourceRepoAfter, PrismContext.LANG_XML);
    display("Resource XML", resourceXml);
    CachingMetadataType cachingMetadata = xmlSchemaTypeAfter.getCachingMetadata();
    assertNotNull("No caching metadata", cachingMetadata);
    assertNotNull("No retrievalTimestamp", cachingMetadata.getRetrievalTimestamp());
    assertNotNull("No serialNumber", cachingMetadata.getSerialNumber());
    Element xsdElement = ObjectTypeUtil.findXsdElement(xmlSchemaTypeAfter);
    ResourceSchema parsedSchema = ResourceSchemaImpl.parse(xsdElement, resourceBefore.toString(), prismContext);
    assertNotNull("No schema after parsing", parsedSchema);
    display("Parsed schema", parsedSchema);
    ComplexTypeDefinition accountDef = parsedSchema.findComplexTypeDefinition(new QName(parsedSchema.getNamespace(), SchemaConstants.ACCOUNT_OBJECT_CLASS_LOCAL_NAME));
    assertNotNull("No account definition in schema after parsing", accountDef);
    PrismAsserts.assertPropertyDefinition(accountDef, SchemaConstants.ICFS_NAME, DOMUtil.XSD_STRING, 1, 1);
    PrismAsserts.assertPropertyDefinition(accountDef, new QName(SchemaConstants.NS_ICF_SCHEMA, "description"), DOMUtil.XSD_STRING, 0, 1);
    // The useless configuration variables should be reflected to the resource now
    assertEquals("Wrong useless string", "Shiver me timbers!", dummyResource.getUselessString());
    assertEquals("Wrong guarded useless string", "Dead men tell no tales", dummyResource.getUselessGuardedString());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ComplexTypeDefinition(com.evolveum.midpoint.prism.ComplexTypeDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 10 with XmlSchemaType

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

the class TestDummyLegacy method test103NativeTestResource.

@Test
public void test103NativeTestResource() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    // Check that there is no schema before test (pre-condition)
    ResourceType resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_NATIVE_OID, null, result).asObjectable();
    assertNotNull("No connector ref", resourceBefore.getConnectorRef());
    assertNotNull("No connector ref OID", resourceBefore.getConnectorRef().getOid());
    ConnectorType connector = repositoryService.getObject(ConnectorType.class, resourceBefore.getConnectorRef().getOid(), null, result).asObjectable();
    assertNotNull(connector);
    XmlSchemaType xmlSchemaTypeBefore = resourceBefore.getSchema();
    Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceBefore);
    AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
    // WHEN
    OperationResult testResult = provisioningService.testResource(RESOURCE_DUMMY_NATIVE_OID, task);
    // THEN
    display("Test result", testResult);
    OperationResult connectorResult = assertSingleConnectorTestResult(testResult);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_INITIALIZATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONFIGURATION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CONNECTION);
    assertTestResourceSuccess(connectorResult, ConnectorTestOperation.CONNECTOR_CAPABILITIES);
    assertSuccess(connectorResult);
    assertTestResourceSuccess(testResult, ConnectorTestOperation.RESOURCE_SCHEMA);
    assertSuccess(testResult);
    PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_NATIVE_OID, null, result);
    ResourceType resourceTypeRepoAfter = resourceRepoAfter.asObjectable();
    display("Resource after test", resourceTypeRepoAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) Element(org.w3c.dom.Element) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)12 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)10 Element (org.w3c.dom.Element)10 Test (org.testng.annotations.Test)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Task (com.evolveum.midpoint.task.api.Task)4 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)3 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)3 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)3 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 AbstractSchemaTest (com.evolveum.midpoint.schema.AbstractSchemaTest)2 SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)2 QName (javax.xml.namespace.QName)2 Document (org.w3c.dom.Document)2 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)1 ComplexTypeDefinition (com.evolveum.midpoint.prism.ComplexTypeDefinition)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 VariableItemPathSegment (com.evolveum.midpoint.prism.path.VariableItemPathSegment)1