use of com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType in project midpoint by Evolveum.
the class ResourceManager method createSchemaUpdateDelta.
private ContainerDelta<XmlSchemaType> createSchemaUpdateDelta(PrismObject<ResourceType> resource, ResourceSchema resourceSchema) throws SchemaException {
Document xsdDoc = null;
try {
// Convert to XSD
LOGGER.trace("Serializing XSD resource schema for {} to DOM", resource);
xsdDoc = resourceSchema.serializeToXsd();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Serialized XSD resource schema for {}:\n{}", resource, DOMUtil.serializeDOMToString(xsdDoc));
}
} catch (SchemaException e) {
throw new SchemaException("Error processing resource schema for " + resource + ": " + e.getMessage(), e);
}
Element xsdElement = DOMUtil.getFirstChildElement(xsdDoc);
if (xsdElement == null) {
throw new SchemaException("No schema was generated for " + resource);
}
CachingMetadataType cachingMetadata = MiscSchemaUtil.generateCachingMetadata();
// Store generated schema into repository (modify the original
// Resource)
LOGGER.info("Storing generated schema in resource {}", resource);
ContainerDelta<XmlSchemaType> schemaContainerDelta = ContainerDelta.createDelta(ResourceType.F_SCHEMA, ResourceType.class, prismContext);
PrismContainerValue<XmlSchemaType> cval = new PrismContainerValue<XmlSchemaType>(prismContext);
schemaContainerDelta.setValueToReplace(cval);
PrismProperty<CachingMetadataType> cachingMetadataProperty = cval.createProperty(XmlSchemaType.F_CACHING_METADATA);
cachingMetadataProperty.setRealValue(cachingMetadata);
List<QName> objectClasses = ResourceTypeUtil.getSchemaGenerationConstraints(resource);
if (objectClasses != null) {
PrismProperty<SchemaGenerationConstraintsType> generationConstraints = cval.createProperty(XmlSchemaType.F_GENERATION_CONSTRAINTS);
SchemaGenerationConstraintsType constraints = new SchemaGenerationConstraintsType();
constraints.getGenerateObjectClass().addAll(objectClasses);
generationConstraints.setRealValue(constraints);
}
PrismProperty<SchemaDefinitionType> definitionProperty = cval.createProperty(XmlSchemaType.F_DEFINITION);
ObjectTypeUtil.setXsdSchemaDefinition(definitionProperty, xsdElement);
return schemaContainerDelta;
}
Aggregations