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);
}
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);
}
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;
}
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);
}
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;
}
Aggregations