Search in sources :

Example 6 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class ResourceCarefulAntUtil method createNewXmlSchemaDef.

private static SchemaDefinitionType createNewXmlSchemaDef(File resourceFile, int iteration, PrismContext prismContext) throws SchemaException {
    PrismObject<ResourceType> resource = parseResource(resourceFile, prismContext);
    XmlSchemaType schema = resource.asObjectable().getSchema();
    SchemaDefinitionType def;
    if (schema == null) {
        def = new SchemaDefinitionType();
        def.getAny().add(DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT));
    } else {
        def = schema.getDefinition();
    // TODO: modify it somehow
    }
    return def;
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)

Example 7 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class TestJaxbConstruction method testResourceConstruction.

@Test
public void testResourceConstruction() throws Exception {
    System.out.println("\n\n ===[ testResourceConstruction ]===\n");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    ResourceType resourceType = new ResourceType();
    prismContext.adopt(resourceType);
    PrismObject<ResourceType> resource = resourceType.asPrismObject();
    assertNotNull("No object definition after adopt", resource.getDefinition());
    // name: PolyString
    resourceType.setName(new PolyStringType("Môj risórs"));
    PrismProperty<PolyString> fullNameProperty = resource.findProperty(ResourceType.F_NAME);
    PolyString fullName = fullNameProperty.getRealValue();
    assertEquals("Wrong name orig", "Môj risórs", fullName.getOrig());
    assertEquals("Wrong name norm", "moj risors", fullName.getNorm());
    // description: setting null value
    resourceType.setDescription(null);
    PrismProperty<String> descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property " + descriptionProperty, descriptionProperty);
    // description: setting null value
    resourceType.setDescription("blah blah");
    descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertEquals("Wrong description value", "blah blah", descriptionProperty.getRealValue());
    // description: resetting null value
    resourceType.setDescription(null);
    descriptionProperty = resource.findProperty(UserType.F_DESCRIPTION);
    assertNull("Unexpected description property (after reset) " + descriptionProperty, descriptionProperty);
    // Extension
    ExtensionType extension = new ExtensionType();
    resourceType.setExtension(extension);
    resource.checkConsistence();
    PrismContainer<Containerable> extensionContainer = resource.findContainer(GenericObjectType.F_EXTENSION);
    checkExtension(extensionContainer, "resource extension after setExtension");
    checkExtension(extension, "resource extension after setExtension");
    // Schema
    XmlSchemaType xmlSchemaType = new XmlSchemaType();
    CachingMetadataType cachingMetadata = new CachingMetadataType();
    cachingMetadata.setSerialNumber("serial123");
    xmlSchemaType.setCachingMetadata(cachingMetadata);
    resourceType.setSchema(xmlSchemaType);
    SchemaDefinitionType schemaDefinition = new SchemaDefinitionType();
    Element xsdSchemaElement = DOMUtil.createElement(DOMUtil.XSD_SCHEMA_ELEMENT);
    schemaDefinition.getAny().add(xsdSchemaElement);
    xmlSchemaType.setDefinition(schemaDefinition);
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    assertNotNull("No schema container", schemaContainer);
    // TODO
    // Schema: null
    resourceType.setSchema(null);
    schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    assertNull("Unexpected schema container", schemaContainer);
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) Element(org.w3c.dom.Element) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExtensionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType) CachingMetadataType(com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType) Test(org.testng.annotations.Test)

Example 8 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class TestJaxbSanity method testUnmarshallAndEqualsResourceSchema.

@Test
public void testUnmarshallAndEqualsResourceSchema() throws JAXBException, SchemaException, FileNotFoundException {
    System.out.println("\n\n ===[testUnmarshallAndEqualsResourceSchema]===\n");
    // GIVEN
    ResourceType resource1Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource1Type);
    SchemaDefinitionType schemaDefinition1 = resource1Type.getSchema().getDefinition();
    ResourceType resource2Type = JaxbTestUtil.getInstance().unmarshalObject(new File(RESOURCE_OPENDJ_FILENAME), ResourceType.class);
    assertNotNull(resource2Type);
    SchemaDefinitionType schemaDefinition2 = resource2Type.getSchema().getDefinition();
    // WHEN
    boolean equals = schemaDefinition1.equals(schemaDefinition2);
    // THEN
    assertTrue("Schema definition not equal", equals);
    assertEquals("Hashcode does not match", schemaDefinition1.hashCode(), schemaDefinition2.hashCode());
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) File(java.io.File) Test(org.testng.annotations.Test)

Example 9 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class ResourceUtils method deleteSchema.

public static void deleteSchema(PrismObject<ResourceType> resource, ModelService modelService, PrismContext prismContext, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    PrismContainer<XmlSchemaType> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (schemaContainer != null && schemaContainer.getValue() != null) {
        PrismProperty<SchemaDefinitionType> definitionProperty = schemaContainer.findProperty(XmlSchemaType.F_DEFINITION);
        if (definitionProperty != null && !definitionProperty.isEmpty()) {
            PrismPropertyValue<SchemaDefinitionType> definitionValue = definitionProperty.getValue().clone();
            ObjectDelta<ResourceType> deleteSchemaDefinitionDelta = ObjectDelta.createModificationDeleteProperty(ResourceType.class, resource.getOid(), new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), prismContext, // TODO ...or replace with null?
            definitionValue.getValue());
            // delete schema
            modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singleton(deleteSchemaDefinitionDelta), null, task, parentResult);
        }
    }
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) XmlSchemaType(com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with SchemaDefinitionType

use of com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType in project midpoint by Evolveum.

the class PrismUnmarshaller method parseProperty.

@NotNull
private <T> PrismProperty<T> parseProperty(@NotNull XNode node, @NotNull QName itemName, @Nullable PrismPropertyDefinition<T> itemDefinition, @NotNull ParsingContext pc) throws SchemaException {
    Validate.isTrue(!(node instanceof RootXNode));
    PrismProperty<T> property = itemDefinition != null ? itemDefinition.instantiate() : new PrismProperty<>(itemName, prismContext);
    if (node instanceof ListXNode && !node.isHeterogeneousList()) {
        ListXNode listNode = (ListXNode) node;
        if (itemDefinition != null && !itemDefinition.isMultiValue() && listNode.size() > 1) {
            throw new SchemaException("Attempt to store multiple values in single-valued property " + itemName);
        }
        for (XNode subNode : listNode) {
            PrismPropertyValue<T> pval = parsePropertyValue(subNode, itemDefinition, pc);
            addItemValueIfPossible(property, pval, pc);
        }
    } else if (node instanceof MapXNode || node instanceof PrimitiveXNode || node.isHeterogeneousList()) {
        PrismPropertyValue<T> pval = parsePropertyValue(node, itemDefinition, pc);
        if (pval != null) {
            property.add(pval);
        }
    } else if (node instanceof SchemaXNode) {
        SchemaDefinitionType schemaDefType = getBeanUnmarshaller().unmarshalSchemaDefinitionType((SchemaXNode) node);
        @SuppressWarnings("unchecked") PrismPropertyValue<T> val = new PrismPropertyValue(schemaDefType);
        addItemValueIfPossible(property, val, pc);
    } else {
        throw new IllegalArgumentException("Cannot parse property from " + node);
    }
    return property;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SchemaDefinitionType (com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)11 Element (org.w3c.dom.Element)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)4 XmlSchemaType (com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 QName (javax.xml.namespace.QName)3 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 CachingMetadataType (com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType)2 JAXBElement (javax.xml.bind.JAXBElement)2 Test (org.testng.annotations.Test)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)1 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)1 ExtensionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExtensionType)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 SchemaGenerationConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType)1 SchemaHandlingType (com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType)1 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)1 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)1