Search in sources :

Example 31 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class AbstractLexicalProcessorTest method getAssertXMapSubnode.

protected <X extends XNode> X getAssertXMapSubnode(String message, MapXNode xmap, QName key, Class<X> expectedClass) {
    XNode xsubnode = xmap.get(key);
    assertNotNull(message + " no key " + key, xsubnode);
    return getAssertXNode(message + " key " + key, xsubnode, expectedClass);
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 32 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class TestQueryConvertor method testAccountFilter.

@Test
public void testAccountFilter() throws Exception {
    displayTestTitle("testAccountFilter");
    SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_FILE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_FAILED_OPERATION_TYPE, FAILED_OPERATION_TYPE_QNAME, new ItemPath(ShadowType.F_FAILED_OPERATION_TYPE));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, FailedOperationTypeType.ADD);
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, ShadowType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(ShadowType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, createPolyString("someName"));
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    SearchFilterType convertedFilterType = convertedQueryType.getFilter();
    MapXNode xFilter = convertedFilterType.serializeToXNode();
    PrismAsserts.assertSize(xFilter, 1);
    PrismAsserts.assertSubnode(xFilter, AndFilter.ELEMENT_NAME, MapXNode.class);
    MapXNode xandmap = (MapXNode) xFilter.get(AndFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xandmap, 1);
    PrismAsserts.assertSubnode(xandmap, EqualFilter.ELEMENT_NAME, ListXNode.class);
    ListXNode xequalsList = (ListXNode) xandmap.get(EqualFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xequalsList, 2);
    Element filterClauseElement = convertedFilterType.getFilterClauseAsElement(getPrismContext());
    System.out.println("Serialized filter (JAXB->DOM)");
    System.out.println(DOMUtil.serializeDOMToString(filterClauseElement));
    DomAsserts.assertElementQName(filterClauseElement, AndFilter.ELEMENT_NAME);
    DomAsserts.assertSubElements(filterClauseElement, 2);
    Element firstSubelement = DOMUtil.getChildElement(filterClauseElement, 0);
    DomAsserts.assertElementQName(firstSubelement, EqualFilter.ELEMENT_NAME);
    Element firstValueElement = DOMUtil.getChildElement(firstSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(firstValueElement, "add");
    Element secondSubelement = DOMUtil.getChildElement(filterClauseElement, 1);
    DomAsserts.assertElementQName(secondSubelement, EqualFilter.ELEMENT_NAME);
    Element secondValueElement = DOMUtil.getChildElement(secondSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(secondValueElement, "someName");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 33 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class JaxbDomHack method toAny.

/**
	 * Serializes prism value to JAXB "any" format as returned by JAXB getAny() methods.
	 */
public Object toAny(PrismValue value) throws SchemaException {
    if (value == null) {
        return null;
    }
    Itemable parent = value.getParent();
    if (parent == null) {
        throw new IllegalStateException("Couldn't convert parent-less prism value to xsd:any: " + value);
    }
    QName elementName = parent.getElementName();
    if (value instanceof PrismPropertyValue) {
        PrismPropertyValue<Object> pval = (PrismPropertyValue) value;
        if (pval.isRaw() && parent.getDefinition() == null) {
            XNode rawElement = pval.getRawElement();
            if (rawElement instanceof MapXNode) {
                return domParser.serializeXMapToElement((MapXNode) rawElement, elementName);
            } else if (rawElement instanceof PrimitiveXNode<?>) {
                PrimitiveXNode<?> xprim = (PrimitiveXNode<?>) rawElement;
                String stringValue = xprim.getStringValue();
                Element element = DOMUtil.createElement(DOMUtil.getDocument(), elementName);
                element.setTextContent(stringValue);
                DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                return element;
            } else {
                throw new IllegalArgumentException("Cannot convert raw element " + rawElement + " to xsd:any");
            }
        } else {
            Object realValue = pval.getValue();
            if (XmlTypeConverter.canConvert(realValue.getClass())) {
                // Always record xsi:type. This is FIXME, but should work OK for now (until we put definition into deltas)
                return XmlTypeConverter.toXsdElement(realValue, elementName, DOMUtil.getDocument(), true);
            } else {
                return wrapIfNeeded(realValue, elementName);
            }
        }
    } else if (value instanceof PrismReferenceValue) {
        return prismContext.domSerializer().serialize(value, elementName);
    } else if (value instanceof PrismContainerValue<?>) {
        PrismContainerValue<?> pval = (PrismContainerValue<?>) value;
        if (pval.getParent().getCompileTimeClass() == null) {
            // We need to convert it to DOM
            return prismContext.domSerializer().serialize(pval, elementName);
        } else {
            return wrapIfNeeded(pval.asContainerable(), elementName);
        }
    } else {
        throw new IllegalArgumentException("Unknown type " + value);
    }
}
Also used : PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) QName(javax.xml.namespace.QName) XNode(com.evolveum.midpoint.prism.xnode.XNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 34 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class AbstractJsonLexicalProcessor method processDefaultNamespaces.

// Default namespaces (@ns properties) are processed in the second pass, because they might be present within an object
// at any place, even at the end.
private void processDefaultNamespaces(XNode xnode, String parentDefault, JsonParsingContext ctx) {
    if (xnode instanceof MapXNode) {
        MapXNode map = (MapXNode) xnode;
        final String currentDefault = ctx.defaultNamespaces.containsKey(map) ? ctx.defaultNamespaces.get(map) : parentDefault;
        for (Entry<QName, XNode> entry : map.entrySet()) {
            QName fieldName = entry.getKey();
            XNode subnode = entry.getValue();
            if (StringUtils.isNotEmpty(currentDefault) && StringUtils.isEmpty(fieldName.getNamespaceURI()) && !ctx.noNamespaceEntries.containsKey(entry)) {
                map.qualifyKey(fieldName, currentDefault);
            }
            processDefaultNamespaces(subnode, currentDefault, ctx);
        }
        qualifyElementNameIfNeeded(map, currentDefault, ctx);
    } else {
        qualifyElementNameIfNeeded(xnode, parentDefault, ctx);
        if (xnode instanceof ListXNode) {
            for (XNode item : (ListXNode) xnode) {
                processDefaultNamespaces(item, parentDefault, ctx);
            }
        }
    }
}
Also used : ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) SchemaXNode(com.evolveum.midpoint.prism.xnode.SchemaXNode) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) XNode(com.evolveum.midpoint.prism.xnode.XNode) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) PrimitiveXNode(com.evolveum.midpoint.prism.xnode.PrimitiveXNode) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode)

Example 35 with MapXNode

use of com.evolveum.midpoint.prism.xnode.MapXNode in project midpoint by Evolveum.

the class TestQueryConvertors method testFilterUserAndJaxb.

@Test
public void testFilterUserAndJaxb() throws Exception {
    displayTestTitle("testFilterUserAndJaxb");
    SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_USER_AND_FILE);
    ObjectQuery query = toObjectQuery(UserType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, UserType.F_GIVEN_NAME, DOMUtil.XSD_STRING, new ItemPath(new QName(null, UserType.F_GIVEN_NAME.getLocalPart())));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, "Jack");
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, UserType.F_LOCALITY, DOMUtil.XSD_STRING, new ItemPath(new QName(null, UserType.F_LOCALITY.getLocalPart())));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, "Caribbean");
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    SearchFilterType convertedFilterType = convertedQueryType.getFilter();
    MapXNode xFilter = convertedFilterType.serializeToXNode();
    PrismAsserts.assertSize(xFilter, 1);
    PrismAsserts.assertSubnode(xFilter, AndFilter.ELEMENT_NAME, MapXNode.class);
    MapXNode xandmap = (MapXNode) xFilter.get(AndFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xandmap, 1);
    PrismAsserts.assertSubnode(xandmap, EqualFilter.ELEMENT_NAME, ListXNode.class);
    ListXNode xequalsList = (ListXNode) xandmap.get(EqualFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xequalsList, 2);
    Element filterClauseElement = convertedFilterType.getFilterClauseAsElement(getPrismContext());
    System.out.println("Serialized filter (JAXB->DOM)");
    System.out.println(DOMUtil.serializeDOMToString(filterClauseElement));
    DomAsserts.assertElementQName(filterClauseElement, AndFilter.ELEMENT_NAME);
    DomAsserts.assertSubElements(filterClauseElement, 2);
    Element firstSubelement = DOMUtil.getChildElement(filterClauseElement, 0);
    DomAsserts.assertElementQName(firstSubelement, EqualFilter.ELEMENT_NAME);
    Element firstValueElement = DOMUtil.getChildElement(firstSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(firstValueElement, "Jack");
    Element secondSubelement = DOMUtil.getChildElement(filterClauseElement, 1);
    DomAsserts.assertElementQName(secondSubelement, EqualFilter.ELEMENT_NAME);
    Element secondValueElement = DOMUtil.getChildElement(secondSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(secondValueElement, "Caribbean");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)42 QName (javax.xml.namespace.QName)24 RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)21 XNode (com.evolveum.midpoint.prism.xnode.XNode)18 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)15 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)13 Test (org.testng.annotations.Test)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)9 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)7 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)7 Element (org.w3c.dom.Element)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 EncryptedDataType (com.evolveum.prism.xml.ns._public.types_3.EncryptedDataType)3 NotNull (org.jetbrains.annotations.NotNull)3 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2