Search in sources :

Example 21 with RootXNode

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

the class SearchFilterPanel method updateFilterClause.

private void updateFilterClause(PrismContext context) throws SchemaException {
    final String clauseString = clauseStringModel.getObject();
    if (StringUtils.isNotEmpty(clauseString)) {
        LOGGER.trace("Filter Clause to serialize: {}", clauseString);
        RootXNode filterClauseNode = ExpressionUtil.parseSearchFilter(clauseString, context);
        getModelObject().setFilterClauseXNode(filterClauseNode);
    } else {
        if (getModelObject() != null) {
            getModelObject().setFilterClauseXNode((MapXNode) null);
        }
    }
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 22 with RootXNode

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

the class StaticExpressionUtil method serializeValueElements.

public static <IV extends PrismValue, ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV, ID> item) throws SchemaException {
    if (item == null) {
        return null;
    }
    List<JAXBElement<RawType>> elements = new ArrayList<>(item.size());
    for (PrismValue value : item.getValues()) {
        RootXNode xnode = item.getPrismContext().xnodeSerializer().serialize(value);
        RawType rawType = new RawType(xnode.getSubnode().frozen(), item.getPrismContext());
        JAXBElement<RawType> jaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, RawType.class, rawType);
        elements.add(jaxbElement);
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 23 with RootXNode

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

the class NinjaUtils method createObjectQuery.

public static ObjectQuery createObjectQuery(FileReference ref, NinjaContext context, Class<? extends Containerable> objectClass) throws IOException, SchemaException {
    if (ref == null) {
        return null;
    }
    String filterStr = ref.getValue();
    if (ref.getReference() != null) {
        File file = ref.getReference();
        filterStr = FileUtils.readFileToString(file, context.getCharset());
    }
    PrismContext prismContext = context.getPrismContext();
    // Experimental Axiom filter support, % is chosen as a marker and will be skipped.
    if (filterStr.startsWith("%")) {
        ObjectFilter objectFilter = prismContext.createQueryParser().parseQuery(objectClass, filterStr.substring(1));
        return prismContext.queryFactory().createQuery(objectFilter);
    } else {
        PrismParserNoIO parser = prismContext.parserFor(filterStr);
        RootXNode root = parser.parseToXNode();
        ObjectFilter filter = context.getQueryConverter().parseFilter(root.toMapXNode(), objectClass);
        return prismContext.queryFactory().createQuery(filter);
    }
}
Also used : RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 24 with RootXNode

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

the class DefinitionScopeDto method getParsedSearchFilter.

public SearchFilterType getParsedSearchFilter(PrismContext context) {
    if (searchFilterText == null || searchFilterText.isEmpty()) {
        return null;
    }
    SearchFilterType rv = new SearchFilterType();
    RootXNode filterClauseNode;
    try {
        filterClauseNode = context.parserFor(searchFilterText).xml().parseToXNode();
    } catch (SchemaException e) {
        throw new SystemException("Cannot parse search filter " + searchFilterText + ": " + e.getMessage(), e);
    }
    rv.setFilterClauseXNode(filterClauseNode);
    return rv;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) SystemException(com.evolveum.midpoint.util.exception.SystemException) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode)

Example 25 with RootXNode

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

the class TestParseTaskBulkAction2 method testParseTaskRoundtrip.

@Test
public void testParseTaskRoundtrip() throws Exception {
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    PrismObject<TaskType> task = prismContext.parseObject(TASK_FILE);
    System.out.println("Parsed task:");
    System.out.println(task.debugDump());
    task.checkConsistence();
    // SERIALIZE
    String serializedTask = prismContext.xmlSerializer().serialize(task);
    System.out.println("serialized task:");
    System.out.println(serializedTask);
    // RE-PARSE
    RootXNode reparsedToXNode = prismContext.parserFor(serializedTask).xml().parseToXNode();
    System.out.println("Re-parsed task (to XNode):");
    System.out.println(reparsedToXNode.debugDump());
    // real reparse
    PrismObject<TaskType> reparsedTask = prismContext.parseObject(serializedTask);
    System.out.println("Re-parsed task:");
    System.out.println(reparsedTask.debugDump());
    // Cannot assert here. It will cause parsing of some of the raw values and diff will fail
    reparsedTask.checkConsistence();
    ObjectDelta<TaskType> objectDelta = task.diff(reparsedTask);
    System.out.println("Delta:");
    System.out.println(objectDelta.debugDump());
    assertTrue("Delta is not empty", objectDelta.isEmpty());
    PrismAsserts.assertEquivalent("Task re-parsed equivalence", task, reparsedTask);
    Item executeScriptItem = reparsedTask.findExtensionItem(new QName("executeScript"));
    ExecuteScriptType executeScript = (ExecuteScriptType) executeScriptItem.getRealValue();
    Object o = executeScript.getInput().getValue().get(0);
    System.out.println(o);
    assertTrue("Raw value is not parsed", o instanceof RawType && ((RawType) o).getAlreadyParsedValue() != null);
}
Also used : Item(com.evolveum.midpoint.prism.Item) ExecuteScriptType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ExecuteScriptType) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) RootXNode(com.evolveum.midpoint.prism.xnode.RootXNode) PrismObject(com.evolveum.midpoint.prism.PrismObject) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) Test(org.testng.annotations.Test)

Aggregations

RootXNode (com.evolveum.midpoint.prism.xnode.RootXNode)51 Test (org.testng.annotations.Test)22 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)14 QName (javax.xml.namespace.QName)13 XNode (com.evolveum.midpoint.prism.xnode.XNode)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)7 NotNull (org.jetbrains.annotations.NotNull)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ListXNode (com.evolveum.midpoint.prism.xnode.ListXNode)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)4 SchemaXNode (com.evolveum.midpoint.prism.xnode.SchemaXNode)3 ArrayList (java.util.ArrayList)3 ResourceType (com.evolveum.midpoint.prism.foo.ResourceType)2 UserType (com.evolveum.midpoint.prism.foo.UserType)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 TaskType (com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType)2 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)2 Element (org.w3c.dom.Element)2