Search in sources :

Example 1 with SchemaDescription

use of com.evolveum.midpoint.prism.schema.SchemaDescription in project midpoint by Evolveum.

the class TestPrismContext method testCompileTimeClassmap.

@Test
public void testCompileTimeClassmap() throws SchemaException, SAXException, IOException {
    System.out.println("===[ testCompileTimeClassmap ]===");
    // WHEN
    PrismContext prismContext = constructInitializedPrismContext();
    // THEN
    assertNotNull("No prism context", prismContext);
    SchemaRegistry schemaRegistry = prismContext.getSchemaRegistry();
    assertNotNull("No schema registry in context", schemaRegistry);
    SchemaDescription fooDesc = schemaRegistry.findSchemaDescriptionByNamespace(NS_FOO);
    Map<QName, Class<?>> map = fooDesc.getXsdTypeTocompileTimeClassMap();
    assertNotNull("No XsdTypeTocompileTimeClassMap", map);
    assertFalse("Empty XsdTypeTocompileTimeClassMap", map.isEmpty());
    assertMapping(map, UserType.class, USER_TYPE_QNAME);
    assertMapping(map, AccountType.class, ACCOUNT_TYPE_QNAME);
    assertMapping(map, AssignmentType.class, ASSIGNMENT_TYPE_QNAME);
    assertMapping(map, ActivationType.class, ACTIVATION_TYPE_QNAME);
    // This is not a container, but it should be in the map anyway
    assertMapping(map, AccountConstructionType.class, ACCOUNT_CONSTRUCTION_TYPE_QNAME);
}
Also used : SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) QName(javax.xml.namespace.QName) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) Test(org.testng.annotations.Test)

Example 2 with SchemaDescription

use of com.evolveum.midpoint.prism.schema.SchemaDescription in project midpoint by Evolveum.

the class PrismBeanInspector method getObjectFactoryClassUncached.

private Class getObjectFactoryClassUncached(String namespaceUri) {
    SchemaDescription schemaDescription = prismContext.getSchemaRegistry().findSchemaDescriptionByNamespace(namespaceUri);
    if (schemaDescription == null) {
        throw new IllegalArgumentException("Cannot find object factory class for namespace " + namespaceUri + ": unknown schema namespace");
    }
    Package compileTimeClassesPackage = schemaDescription.getCompileTimeClassesPackage();
    if (compileTimeClassesPackage == null) {
        throw new IllegalArgumentException("Cannot find object factory class for namespace " + namespaceUri + ": not a compile-time schema");
    }
    return getObjectFactoryClassUncached(compileTimeClassesPackage);
}
Also used : SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription)

Example 3 with SchemaDescription

use of com.evolveum.midpoint.prism.schema.SchemaDescription in project midpoint by Evolveum.

the class ExtensionSchemaRestController method getSchema.

@GetMapping(value = "/{name}", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE })
public ResponseEntity<?> getSchema(@PathVariable("name") String name) {
    Task task = initRequest();
    OperationResult result = createSubresult(task, "getSchema");
    ResponseEntity<?> response;
    try {
        securityEnforcer.authorize(ModelAuthorizationAction.GET_EXTENSION_SCHEMA.getUrl(), null, AuthorizationParameters.EMPTY, null, task, result);
        if (name == null) {
            result.recordFatalError("Name not defined");
            response = createErrorResponseBuilder(HttpStatus.BAD_REQUEST, result);
        } else if (!name.toLowerCase().endsWith(".xsd") && name.length() > 4) {
            result.recordFatalError("Name must be an xsd schema (.xsd extension expected)");
            response = createErrorResponseBuilder(HttpStatus.BAD_REQUEST, result);
        } else {
            SchemaRegistry registry = prismContext.getSchemaRegistry();
            Collection<SchemaDescription> descriptions = registry.getSchemaDescriptions();
            SchemaDescription description = null;
            for (SchemaDescription desc : descriptions) {
                String descName = computeName(desc);
                if (descName != null && descName.equals(name)) {
                    description = desc;
                    break;
                }
            }
            if (description != null) {
                String content = FileUtils.readFileToString(new File(description.getPath()), StandardCharsets.UTF_8);
                response = ResponseEntity.status(HttpStatus.OK).contentType(MediaType.TEXT_PLAIN).body(content);
            } else {
                result.recordFatalError("Unknown schema");
                response = createErrorResponseBuilder(HttpStatus.NOT_FOUND, result);
            }
        }
    } catch (Exception ex) {
        result.recordFatalError(ex);
        response = handleException(result, ex);
    }
    finishRequest(task, result);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) File(java.io.File) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with SchemaDescription

use of com.evolveum.midpoint.prism.schema.SchemaDescription in project midpoint by Evolveum.

the class JaxbTestUtil method getCompileTimeClass.

public <T> Class<T> getCompileTimeClass(QName xsdType) {
    SchemaDescription desc = getSchemaRegistry().findSchemaDescriptionByNamespace(xsdType.getNamespaceURI());
    if (desc == null) {
        return null;
    }
    Map<QName, Class<?>> map = desc.getXsdTypeTocompileTimeClassMap();
    if (map == null) {
        return null;
    }
    return (Class<T>) map.get(xsdType);
}
Also used : SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) QName(javax.xml.namespace.QName)

Example 5 with SchemaDescription

use of com.evolveum.midpoint.prism.schema.SchemaDescription in project midpoint by Evolveum.

the class ExtensionSchemaRestController method listSchemas.

@GetMapping
public ResponseEntity<?> listSchemas() {
    Task task = initRequest();
    OperationResult result = createSubresult(task, "listSchemas");
    ResponseEntity<?> response;
    try {
        securityEnforcer.authorize(ModelAuthorizationAction.GET_EXTENSION_SCHEMA.getUrl(), null, AuthorizationParameters.EMPTY, null, task, result);
        SchemaRegistry registry = prismContext.getSchemaRegistry();
        Collection<SchemaDescription> descriptions = registry.getSchemaDescriptions();
        SchemaFilesType files = new SchemaFilesType();
        for (SchemaDescription description : descriptions) {
            String name = computeName(description);
            if (name == null) {
                continue;
            }
            files.schema(new SchemaFileType().namespace(description.getNamespace()).usualPrefix(description.getUsualPrefix()).fileName(name));
        }
        response = ResponseEntity.ok(files);
    } catch (Exception ex) {
        result.recordFatalError(ex);
        response = handleException(result, ex);
    }
    finishRequest(task, result);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SchemaDescription(com.evolveum.midpoint.prism.schema.SchemaDescription) SchemaFilesType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFilesType) SchemaFileType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

SchemaDescription (com.evolveum.midpoint.prism.schema.SchemaDescription)5 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 QName (javax.xml.namespace.QName)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 SchemaFileType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFileType)1 SchemaFilesType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaFilesType)1 File (java.io.File)1 Collection (java.util.Collection)1 Test (org.testng.annotations.Test)1