use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestParseTask method testSerializeTask.
@Test
public static void testSerializeTask() throws Exception {
ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).build();
QueryType queryType = QueryJaxbConvertor.createQueryType(query, getPrismContext());
PrismPropertyDefinition queryDef = new PrismPropertyDefinitionImpl(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY, QueryType.COMPLEX_TYPE, getPrismContext());
PrismProperty<QueryType> queryProp = queryDef.instantiate();
queryProp.setRealValue(queryType);
TaskType taskType = getPrismContext().createObject(TaskType.class).asObjectable();
taskType.setExtension(new ExtensionType(getPrismContext()));
taskType.getExtension().asPrismContainerValue().add(queryProp);
taskType.setName(PolyStringType.fromOrig("Test task"));
String xml = getPrismContext().xmlSerializer().serialize(taskType.asPrismObject());
System.out.println("Task serialized:\n" + xml);
PrismObject<TaskType> taskParsed = getPrismContext().parserFor(xml).parse();
String xmlSerializedAgain = getPrismContext().xmlSerializer().serialize(taskParsed);
System.out.println("Task serialized again:\n" + xmlSerializedAgain);
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertors method testFilterUserNameJaxb.
@Test
public void testFilterUserNameJaxb() throws Exception {
displayTestTitle("testFilterUserNameJaxb");
SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_USER_NAME_FILE);
ObjectQuery query = toObjectQuery(UserType.class, filterType);
displayQuery(query);
assertNotNull(query);
ObjectFilter filter = query.getFilter();
PrismAsserts.assertEqualsFilter(filter, UserType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(new QName(null, UserType.F_NAME.getLocalPart())));
PrismAsserts.assertEqualsFilterValue((EqualFilter) filter, createPolyString("jack"));
QueryType convertedQueryType = toQueryType(query);
System.out.println("Re-converted query type");
System.out.println(convertedQueryType.debugDump());
Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
System.out.println("Serialized filter (JAXB->DOM)");
System.out.println(DOMUtil.serializeDOMToString(filterClauseElement));
DomAsserts.assertElementQName(filterClauseElement, EqualFilter.ELEMENT_NAME);
DomAsserts.assertSubElements(filterClauseElement, 2);
DomAsserts.assertSubElement(filterClauseElement, PrismConstants.Q_VALUE);
Element valueElement = DOMUtil.getChildElement(filterClauseElement, PrismConstants.Q_VALUE);
DomAsserts.assertTextContent(valueElement, "jack");
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertors method testFilterNotInOid.
@Test
public void testFilterNotInOid() throws Exception {
displayTestTitle("testFilterNotInOid");
SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_NOT_IN_OID);
ObjectQuery query = toObjectQuery(UserType.class, filterType);
displayQuery(query);
assertNotNull(query);
ObjectFilter filter = query.getFilter();
assertTrue("Filter is not of NOT type", filter instanceof NotFilter);
ObjectFilter subFilter = ((NotFilter) filter).getFilter();
assertTrue("Subfilter is not of IN_OID type", subFilter instanceof InOidFilter);
QueryType convertedQueryType = toQueryType(query);
System.out.println("Re-converted query type");
System.out.println(convertedQueryType.debugDump());
Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump());
System.out.println("Serialized filter (JAXB->DOM)");
String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement);
System.out.println(filterAsString);
LOGGER.info(filterAsString);
DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "not"));
assertEquals("wrong # of inOid subfilters", 1, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "inOid").getLength());
assertEquals("wrong # of value subfilters", 4, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "value").getLength());
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType 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");
}
use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class TestQueryConvertors method testFilterNotFullText.
@Test
public void testFilterNotFullText() throws Exception {
displayTestTitle("testFilterNotFullText");
SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_NOT_FULL_TEXT);
ObjectQuery query = toObjectQuery(UserType.class, filterType);
displayQuery(query);
assertNotNull(query);
ObjectFilter filter = query.getFilter();
assertTrue("Filter is not of NOT type", filter instanceof NotFilter);
ObjectFilter subFilter = ((NotFilter) filter).getFilter();
assertTrue("Subfilter is not of FULL_TEXT type", subFilter instanceof FullTextFilter);
QueryType convertedQueryType = toQueryType(query);
System.out.println("Re-converted query type");
System.out.println(convertedQueryType.debugDump());
Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump());
System.out.println("Serialized filter (JAXB->DOM)");
String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement);
System.out.println(filterAsString);
LOGGER.info(filterAsString);
DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "not"));
assertEquals("wrong # of fullText subfilters", 1, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "fullText").getLength());
assertEquals("wrong # of value subfilters", 2, filterClauseElement.getElementsByTagNameNS(PrismConstants.NS_QUERY, "value").getLength());
}
Aggregations