Search in sources :

Example 1 with SchemaGenerationConstraintsType

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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) SchemaGenerationConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)1 SchemaGenerationConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType)1 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)1 SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)1 QName (javax.xml.namespace.QName)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1