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);
}
}
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations