Search in sources :

Example 1 with SchemaDefinitionType

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

the class AbstractLexicalProcessorTest method assertResourceRum.

private void assertResourceRum(PrismObject<ResourceType> resource) throws SchemaException {
    resource.checkConsistence();
    resource.assertDefinitions("test");
    assertEquals("Wrong oid", RESOURCE_RUM_OID, resource.getOid());
    PrismAsserts.assertObjectDefinition(resource.getDefinition(), RESOURCE_QNAME, RESOURCE_TYPE_QNAME, ResourceType.class);
    PrismAsserts.assertParentConsistency(resource);
    assertPropertyValue(resource, "name", new PolyString("Rum Delivery System", "rum delivery system"));
    assertPropertyDefinition(resource, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    PrismProperty<SchemaDefinitionType> propSchema = resource.findProperty(ResourceType.F_SCHEMA);
    assertNotNull("No schema property in resource", propSchema);
    PrismPropertyDefinition<SchemaDefinitionType> propSchemaDef = propSchema.getDefinition();
    assertNotNull("No definition of schema property in resource", propSchemaDef);
    SchemaDefinitionType schemaDefinitionType = propSchema.getRealValue();
    assertNotNull("No value of schema property in resource", schemaDefinitionType);
    Element schemaElement = schemaDefinitionType.getSchema();
    assertNotNull("No schema element in schema property in resource", schemaElement);
    System.out.println("Resource schema:");
    System.out.println(DOMUtil.serializeDOMToString(schemaElement));
    assertEquals("Bad schema element name", DOMUtil.XSD_SCHEMA_ELEMENT, DOMUtil.getQName(schemaElement));
    Element complexTypeElement = DOMUtil.getChildElement(schemaElement, XSD_COMPLEX_TYPE_ELEMENT_NAME);
    assertNotNull("No complexType element in schema element in schema property in resource", complexTypeElement);
    String complexTypeName = complexTypeElement.getAttribute("name");
    assertEquals("Wrong name of complex type", "BarrelType", complexTypeName);
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Element(org.w3c.dom.Element) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 2 with SchemaDefinitionType

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

the class TestParseResource method assertResourceJaxb.

private void assertResourceJaxb(ResourceType resourceType, boolean isSimple) throws SchemaException {
    assertEquals("Wrong oid (JAXB)", TestConstants.RESOURCE_OID, resourceType.getOid());
    assertEquals("Wrong name (JAXB)", PrismTestUtil.createPolyStringType("Embedded Test OpenDJ"), resourceType.getName());
    String expectedNamespace = TestConstants.RESOURCE_NAMESPACE;
    if (isSimple) {
        expectedNamespace = MidPointConstants.NS_RI;
    }
    assertEquals("Wrong namespace (JAXB)", expectedNamespace, ResourceTypeUtil.getResourceNamespace(resourceType));
    ObjectReferenceType connectorRef = resourceType.getConnectorRef();
    assertNotNull("No connectorRef (JAXB)", connectorRef);
    assertEquals("Wrong type in connectorRef (JAXB)", ConnectorType.COMPLEX_TYPE, connectorRef.getType());
    SearchFilterType filter = connectorRef.getFilter();
    assertNotNull("No filter in connectorRef (JAXB)", filter);
    MapXNode filterElement = filter.getFilterClauseXNode();
    assertNotNull("No filter element in connectorRef (JAXB)", filterElement);
    EvaluationTimeType resolutionTime = connectorRef.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef (JAXB)", EvaluationTimeType.IMPORT, resolutionTime);
    }
    XmlSchemaType xmlSchemaType = resourceType.getSchema();
    SchemaHandlingType schemaHandling = resourceType.getSchemaHandling();
    if (isSimple) {
        assertNull("Schema sneaked in", xmlSchemaType);
        assertNull("SchemaHandling sneaked in", schemaHandling);
    } else {
        assertNotNull("No schema element (JAXB)", xmlSchemaType);
        SchemaDefinitionType definition = xmlSchemaType.getDefinition();
        assertNotNull("No definition element in schema (JAXB)", definition);
        List<Element> anyElements = definition.getAny();
        assertNotNull("Null element list in definition element in schema (JAXB)", anyElements);
        assertFalse("Empty element list in definition element in schema (JAXB)", anyElements.isEmpty());
        assertNotNull("No schema handling (JAXB)", schemaHandling);
        for (ResourceObjectTypeDefinitionType accountType : schemaHandling.getObjectType()) {
            String name = accountType.getIntent();
            assertNotNull("Account type without a name", name);
            assertNotNull("Account type " + name + " does not have an objectClass", accountType.getObjectClass());
            boolean foundDescription = false;
            boolean foundDepartmentNumber = false;
            for (ResourceAttributeDefinitionType attributeDefinitionType : accountType.getAttribute()) {
                if ("description".equals(ItemPathUtil.getOnlySegmentQName(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDescription = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    JAXBElement<?> valueEvaluator = outbound.getExpression().getExpressionEvaluator().get(0);
                    System.out.println("value evaluator for description = " + valueEvaluator);
                    assertNotNull("no expression evaluator for description", valueEvaluator);
                    assertEquals("wrong expression evaluator element name for description", SchemaConstantsGenerated.C_VALUE, valueEvaluator.getName());
                    assertEquals("wrong expression evaluator actual type for description", RawType.class, valueEvaluator.getValue().getClass());
                } else if ("departmentNumber".equals(ItemPathUtil.getOnlySegmentQName(attributeDefinitionType.getRef()).getLocalPart())) {
                    foundDepartmentNumber = true;
                    MappingType outbound = attributeDefinitionType.getOutbound();
                    VariableBindingDefinitionType source = outbound.getSource().get(0);
                    System.out.println("source for departmentNumber = " + source);
                    assertNotNull("no source for outbound mapping for departmentNumber", source);
                    //<path xmlns:z="http://z/">$user/extension/z:dept</path>
                    ItemPath expected = new ItemPath(new NameItemPathSegment(new QName("user"), true), new NameItemPathSegment(new QName("extension")), namespaces ? new NameItemPathSegment(new QName("http://z/", "dept")) : new NameItemPathSegment(new QName("dept")));
                    PrismAsserts.assertPathEqualsExceptForPrefixes("source for departmentNubmer", expected, source.getPath().getItemPath());
                }
            }
            assertTrue("ri:description attribute was not found", foundDescription);
            assertTrue("ri:departmentNumber attribute was not found", foundDepartmentNumber);
        }
        // checking <class> element in fetch result
        OperationResultType fetchResult = resourceType.getFetchResult();
        assertNotNull("No fetchResult (JAXB)", fetchResult);
        JAXBElement<?> value = fetchResult.getParams().getEntry().get(0).getEntryValue();
        assertNotNull("No fetchResult param value (JAXB)", value);
        assertEquals("Wrong value class", UnknownJavaObjectType.class, value.getValue().getClass());
        UnknownJavaObjectType unknownJavaObjectType = (UnknownJavaObjectType) value.getValue();
        assertEquals("Wrong value class", "my.class", unknownJavaObjectType.getClazz());
        assertEquals("Wrong value toString value", "my.value", unknownJavaObjectType.getToString());
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with SchemaDefinitionType

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

the class PrismPropertyValue method equalsComplex.

public boolean equalsComplex(PrismPropertyValue<?> other, boolean ignoreMetadata, boolean isLiteral, MatchingRule<T> matchingRule) {
    if (!super.equalsComplex(other, ignoreMetadata, isLiteral)) {
        return false;
    }
    if (this.rawElement != null && other.rawElement != null) {
        return equalsRawElements((PrismPropertyValue<T>) other);
    }
    PrismPropertyValue<T> otherProcessed = (PrismPropertyValue<T>) other;
    PrismPropertyValue<T> thisProcessed = this;
    if (this.rawElement != null || other.rawElement != null) {
        try {
            if (this.rawElement == null) {
                otherProcessed = parseRawElementToNewValue((PrismPropertyValue<T>) other, this);
            } else if (other.rawElement == null) {
                thisProcessed = parseRawElementToNewValue(this, (PrismPropertyValue<T>) other);
            }
        } catch (SchemaException e) {
            // TODO: Maybe just return false?
            throw new IllegalArgumentException("Error parsing the value of property " + getParent() + " using the 'other' definition " + "during a compare: " + e.getMessage(), e);
        }
    }
    T otherRealValue = otherProcessed.getValue();
    T thisRealValue = thisProcessed.getValue();
    if (otherRealValue == null && thisRealValue == null) {
        return true;
    }
    if (otherRealValue == null || thisRealValue == null) {
        return false;
    }
    if (matchingRule != null) {
        try {
            return matchingRule.match(thisRealValue, otherRealValue);
        } catch (SchemaException e) {
            // ordinary equality mechanism instead.
            return thisRealValue.equals(otherRealValue);
        }
    } else {
        if (thisRealValue instanceof Element && otherRealValue instanceof Element) {
            return DOMUtil.compareElement((Element) thisRealValue, (Element) otherRealValue, isLiteral);
        }
        if (thisRealValue instanceof SchemaDefinitionType && otherRealValue instanceof SchemaDefinitionType) {
            SchemaDefinitionType thisSchema = (SchemaDefinitionType) thisRealValue;
            return thisSchema.equals(otherRealValue, isLiteral);
        //			return DOMUtil.compareElement((Element)thisRealValue, (Element)otherRealValue, isLiteral);
        }
        if (thisRealValue instanceof byte[] && otherRealValue instanceof byte[]) {
            return Arrays.equals((byte[]) thisRealValue, (byte[]) otherRealValue);
        }
        if (isLiteral) {
            if (thisRealValue instanceof QName && otherRealValue instanceof QName) {
                // we compare prefixes as well
                if (!thisRealValue.equals(otherRealValue)) {
                    return false;
                }
                return StringUtils.equals(((QName) thisRealValue).getPrefix(), ((QName) otherRealValue).getPrefix());
            } else if (thisRealValue instanceof Equals && otherRealValue instanceof Equals) {
                return ((Equals) thisRealValue).equals(null, null, otherRealValue, LiteralEqualsStrategy.INSTANCE);
            }
        }
        return thisRealValue.equals(otherRealValue);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Equals(org.jvnet.jaxb2_commons.lang.Equals) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element)

Example 4 with SchemaDefinitionType

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

the class ObjectTypeUtil method setXsdSchemaDefinition.

public static void setXsdSchemaDefinition(PrismProperty<SchemaDefinitionType> definitionProperty, Element xsdElement) {
    //		Document document = xsdElement.getOwnerDocument();
    //		Element definitionElement = document.createElementNS(XmlSchemaType.F_DEFINITION.getNamespaceURI(),
    //				XmlSchemaType.F_DEFINITION.getLocalPart());
    //		definitionElement.appendChild(xsdElement);
    //		SchemaDefinitionType schemaDefinition = definitionProperty.getValue().getValue();
    //		schemaDefinition.setSchema(definitionElement);
    SchemaDefinitionType schemaDefinition = new SchemaDefinitionType();
    schemaDefinition.setSchema(xsdElement);
    definitionProperty.setRealValue(schemaDefinition);
}
Also used : SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType)

Example 5 with SchemaDefinitionType

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

the class ResourceCarefulAntUtil method initAnts.

public static void initAnts(List<CarefulAnt<ResourceType>> ants, final File resourceFile, final PrismContext prismContext) {
    final PrismObjectDefinition<ResourceType> resourceDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ResourceType.class);
    ants.add(new CarefulAnt<ResourceType>() {

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) {
            return PropertyDelta.createModificationReplaceProperty(ResourceType.F_DESCRIPTION, resourceDef, "Blah " + iteration);
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            assertEquals("Wrong descripion in iteration " + iteration, "Blah " + iteration, resource.asObjectable().getDescription());
        }
    });
    ants.add(new CarefulAnt<ResourceType>() {

        SchemaHandlingType schemaHandling;

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) throws SchemaException {
            schemaHandling = createNewSchemaHandling(resourceFile, iteration, prismContext);
            return ContainerDelta.createModificationReplace(ResourceType.F_SCHEMA_HANDLING, prismContext.getSchemaRegistry().findContainerDefinitionByCompileTimeClass(SchemaHandlingType.class), schemaHandling.asPrismContainerValue().clone());
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            assertEquals("Wrong schemaHandling in iteration " + iteration, schemaHandling, resource.asObjectable().getSchemaHandling());
        }
    });
    ants.add(new CarefulAnt<ResourceType>() {

        SchemaDefinitionType xmlSchemaDef;

        @Override
        public ItemDelta<?, ?> createDelta(int iteration) throws SchemaException {
            xmlSchemaDef = createNewXmlSchemaDef(resourceFile, iteration, prismContext);
            return PropertyDelta.createModificationReplaceProperty(new ItemPath(ResourceType.F_SCHEMA, XmlSchemaType.F_DEFINITION), resourceDef, xmlSchemaDef);
        }

        @Override
        public void assertModification(PrismObject<ResourceType> resource, int iteration) {
            List<Element> orgigElements = xmlSchemaDef.getAny();
            List<Element> newElements = resource.asObjectable().getSchema().getDefinition().getAny();
            assertEquals("Wrong number of elements in schema definition in iteration " + iteration, orgigElements.size(), newElements.size());
        // TODO look inside elements
        }
    });
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaHandlingType(com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaHandlingType) SchemaDefinitionType(com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) List(java.util.List) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

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