public MapXNode serializeToXNode(PrismContext prismContext) throws SchemaException { MapXNode xmap = getFilterClauseXNode(); if (description == null) { return xmap; } else { // we have to serialize the map in correct order (see MID-1847): description first, filter clause next Map<QName, XNode> newXMap = new HashMap<>(); newXMap.put(SearchFilterType.F_DESCRIPTION, prismContext.xnodeFactory().primitive(description)); if (xmap != null && !xmap.isEmpty()) { Map.Entry<QName, ? extends XNode> filter = xmap.getSingleSubEntry("search filter"); newXMap.put(filter.getKey(), filter.getValue()); } return prismContext.xnodeFactory().map(newXMap); } }
@SuppressWarnings("unchecked") @Test public void testEvaluateExpression() throws Exception { PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml")); ShadowType accountType = account.asObjectable(); PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml")); ResourceType resourceType = resource.asObjectable(); accountType.setResource(resourceType); ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0); for (ConditionalSearchFilterType filter : synchronization.getCorrelation()){ MapXNode clauseXNode = filter.getFilterClauseXNode(); // key = q:equal, value = map (path + expression) RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()) .getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression")); ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class); LOGGER.debug("Expression: {}",SchemaDebugUtil.prettyPrint(expression)); OperationResult result = new OperationResult("testCorrelationRule"); String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result); LOGGER.info(result.debugDump()); assertEquals("Wrong expression result", "hbarbossa", name); } }