Search in sources :

Example 31 with ResourceSchema

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

the class TestSanityLegacy method checkOpenDjSchema.

private void checkOpenDjSchema(ResourceType resource, String source) throws SchemaException {
    ResourceSchema schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
    ObjectClassComplexTypeDefinition accountDefinition = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
    assertNotNull("Schema does not define any account (resource from " + source + ")", accountDefinition);
    Collection<? extends ResourceAttributeDefinition> identifiers = accountDefinition.getPrimaryIdentifiers();
    assertFalse("No account identifiers (resource from " + source + ")", identifiers == null || identifiers.isEmpty());
    // TODO: check for naming attributes and display names, etc
    ActivationCapabilityType capActivation = ResourceTypeUtil.getEffectiveCapability(resource, ActivationCapabilityType.class);
    if (capActivation != null && capActivation.getStatus() != null && capActivation.getStatus().getAttribute() != null) {
        // There is simulated activation capability, check if the attribute is in schema.
        QName enableAttrName = capActivation.getStatus().getAttribute();
        ResourceAttributeDefinition enableAttrDef = accountDefinition.findAttributeDefinition(enableAttrName);
        display("Simulated activation attribute definition", enableAttrDef);
        assertNotNull("No definition for enable attribute " + enableAttrName + " in account (resource from " + source + ")", enableAttrDef);
        assertTrue("Enable attribute " + enableAttrName + " is not ignored (resource from " + source + ")", enableAttrDef.isIgnored());
    }
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) ActivationCapabilityType(com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType) QName(javax.xml.namespace.QName) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)

Example 32 with ResourceSchema

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

the class TestVillage method test022ResourceOpenDjRefinedSchema.

/**
	 * MID-3424
	 */
@Test
public void test022ResourceOpenDjRefinedSchema() throws Exception {
    final String TEST_NAME = "test022ResourceOpenDjRefinedSchema";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TestTrafo.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<ResourceType> resourceBefore = modelService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    ResourceSchema resourceSchemaBefore = RefinedResourceSchema.getResourceSchema(resourceBefore, prismContext);
    RefinedResourceSchema refinedSchemaBefore = RefinedResourceSchema.getRefinedSchema(resourceBefore);
    rememberResourceSchemaFetchCount();
    rememberResourceSchemaParseCount();
    rememberConnectorCapabilitiesFetchCount();
    rememberConnectorInitializationCount();
    rememberConnectorSchemaParseCount();
    rememberPrismObjectCloneCount();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    long t0 = System.currentTimeMillis();
    PrismObject<ResourceType> resourceAfter = modelService.getObject(ResourceType.class, RESOURCE_OPENDJ_OID, null, task, result);
    long t1 = System.currentTimeMillis();
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    long t2 = System.currentTimeMillis();
    ResourceSchema resourceSchemaAfter = RefinedResourceSchema.getResourceSchema(resourceAfter, prismContext);
    long t3 = System.currentTimeMillis();
    RefinedResourceSchema refinedSchemaAfter = RefinedResourceSchema.getRefinedSchema(resourceAfter);
    long t4 = System.currentTimeMillis();
    display("Times", "getObject(RESOURCE_OPENDJ_OID): " + (t1 - t0) + "ms\ngetResourceSchema: " + (t3 - t2) + "ms\ngetRefinedSchema: " + (t4 - t3) + "ms");
    // variable number of clones: 1 or 2 because of trigger scanner task
    assertPrismObjectCloneIncrement(1, 2);
    assertResourceSchemaFetchIncrement(0);
    assertResourceSchemaParseCountIncrement(0);
    assertConnectorCapabilitiesFetchIncrement(0);
    assertConnectorInitializationCountIncrement(0);
    assertConnectorSchemaParseIncrement(0);
    assertTrue("Resource schema has changed", resourceSchemaBefore == resourceSchemaAfter);
    assertTrue("Refined schema has changed", refinedSchemaBefore == refinedSchemaAfter);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) Test(org.testng.annotations.Test)

Example 33 with ResourceSchema

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

the class TestUnix method test010Schema.

@Test
public void test010Schema() throws Exception {
    final String TEST_NAME = "test010Schema";
    TestUtil.displayTestTile(this, TEST_NAME);
    resourceOpenDj = getObject(ResourceType.class, RESOURCE_OPENDJ_OID);
    resourceOpenDjType = resourceOpenDj.asObjectable();
    IntegrationTestTools.displayXml("Initialized resource", resourceOpenDj);
    ResourceSchema resourceSchema = RefinedResourceSchema.getResourceSchema(resourceOpenDj, prismContext);
    display("OpenDJ schema (resource)", resourceSchema);
    ObjectClassComplexTypeDefinition ocDefPosixAccount = resourceSchema.findObjectClassDefinition(OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME);
    assertNotNull("No objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", ocDefPosixAccount);
    assertTrue("Objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", ocDefPosixAccount.isAuxiliary());
    ObjectClassComplexTypeDefinition ocDefPosixGroup = resourceSchema.findObjectClassDefinition(OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME);
    assertNotNull("No objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", ocDefPosixGroup);
    assertTrue("Objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", ocDefPosixGroup.isAuxiliary());
    RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(resourceOpenDj);
    display("OpenDJ schema (refined)", refinedSchema);
    RefinedObjectClassDefinition rOcDefPosixAccount = refinedSchema.getRefinedDefinition(OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME);
    assertNotNull("No refined objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", rOcDefPosixAccount);
    assertTrue("Refined objectclass " + OPENDJ_ACCOUNT_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", rOcDefPosixAccount.isAuxiliary());
    RefinedObjectClassDefinition rOcDefPosixGroup = refinedSchema.getRefinedDefinition(OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME);
    assertNotNull("No refined objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " in resource schema", rOcDefPosixGroup);
    assertTrue("Refined objectclass " + OPENDJ_GROUP_POSIX_AUXILIARY_OBJECTCLASS_NAME + " is not auxiliary", rOcDefPosixGroup.isAuxiliary());
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ObjectClassComplexTypeDefinition(com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) Test(org.testng.annotations.Test)

Example 34 with ResourceSchema

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

the class RefinedResourceSchemaImpl method parse.

public static RefinedResourceSchema parse(ResourceType resourceType, PrismContext prismContext) throws SchemaException {
    ResourceSchema originalResourceSchema = getResourceSchema(resourceType, prismContext);
    if (originalResourceSchema == null) {
        return null;
    }
    String contextDescription = "definition of " + resourceType;
    RefinedResourceSchemaImpl rSchema = new RefinedResourceSchemaImpl(originalResourceSchema);
    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (schemaHandling != null) {
        parseObjectTypeDefsFromSchemaHandling(rSchema, resourceType, schemaHandling, schemaHandling.getObjectType(), null, prismContext, contextDescription);
    }
    parseObjectTypesFromSchema(rSchema, resourceType, prismContext, contextDescription);
    // targets
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
        ((RefinedObjectClassDefinitionImpl) rOcDef).parseAssociations(rSchema);
        ((RefinedObjectClassDefinitionImpl) rOcDef).parseAuxiliaryObjectClasses(rSchema);
    }
    // We can parse attributes only after we have all the object class info parsed (including auxiliary object classes)
    for (RefinedObjectClassDefinition rOcDef : rSchema.getRefinedDefinitions()) {
        ((RefinedObjectClassDefinitionImpl) rOcDef).parseAttributes(rSchema, contextDescription);
    }
    return rSchema;
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema)

Example 35 with ResourceSchema

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

the class ResourceValidatorImpl method validate.

@NotNull
@Override
public ValidationResult validate(@NotNull PrismObject<ResourceType> resourceObject, @NotNull Scope scope, @Nullable Locale locale, @NotNull Task task, @NotNull OperationResult result) {
    final ResourceType resource = resourceObject.asObjectable();
    final ValidationResult vr = new ValidationResult();
    ResourceBundle bundle = ResourceBundle.getBundle(SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH, locale != null ? locale : Locale.getDefault());
    ResourceSchema resourceSchema = null;
    try {
        resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resourceObject, prismContext);
    } catch (Throwable t) {
        vr.add(Issue.Severity.WARNING, CAT_SCHEMA, C_NO_SCHEMA, getString(bundle, CLASS_DOT + C_NO_SCHEMA, t.getMessage()), ObjectTypeUtil.createObjectRef(resourceObject), ItemPath.EMPTY_PATH);
    }
    ResourceValidationContext ctx = new ResourceValidationContext(resourceObject, scope, task, vr, resourceSchema, bundle);
    SchemaHandlingType schemaHandling = resource.getSchemaHandling();
    if (schemaHandling != null) {
        checkSchemaHandlingDuplicateObjectTypes(ctx, schemaHandling);
        checkSchemaHandlingDefaults(ctx, schemaHandling);
        checkSchemaHandlingObjectTypes(ctx, schemaHandling);
    }
    SynchronizationType synchronization = resource.getSynchronization();
    if (synchronization != null) {
        checkSynchronizationDuplicateObjectTypes(ctx, synchronization);
        int i = 1;
        for (ObjectSynchronizationType objectSync : resource.getSynchronization().getObjectSynchronization()) {
            checkObjectSynchronization(ctx, new ItemPath(ResourceType.F_SYNCHRONIZATION, SynchronizationType.F_OBJECT_SYNCHRONIZATION, i), objectSync);
            i++;
        }
    }
    checkSynchronizationExistenceForSchemaHandlingObjectTypes(ctx);
    checkSchemaHandlingExistenceForSynchronizationObjectTypes(ctx);
    return ctx.validationResult;
}
Also used : RefinedResourceSchema(com.evolveum.midpoint.common.refinery.RefinedResourceSchema) ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ValidationResult(com.evolveum.midpoint.model.api.validator.ValidationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)48 Test (org.testng.annotations.Test)26 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)23 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)21 ObjectClassComplexTypeDefinition (com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition)17 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)16 QName (javax.xml.namespace.QName)14 Task (com.evolveum.midpoint.task.api.Task)13 Element (org.w3c.dom.Element)8 ResourceAttributeDefinition (com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition)7 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)7 ArrayList (java.util.ArrayList)7 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)6 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)6 Containerable (com.evolveum.midpoint.prism.Containerable)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 AbstractProvisioningIntegrationTest (com.evolveum.midpoint.provisioning.impl.AbstractProvisioningIntegrationTest)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ConnectorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3