Search in sources :

Example 86 with QueryType

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);
}
Also used : ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 87 with QueryType

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");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 88 with QueryType

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());
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismTestUtil.createPolyString(com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 89 with QueryType

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

Example 90 with QueryType

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());
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismTestUtil.createPolyString(com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)57 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)41 Test (org.junit.Test)40 QueryImpl (ddf.catalog.operation.impl.QueryImpl)37 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)36 QName (javax.xml.namespace.QName)34 Test (org.testng.annotations.Test)33 JAXBElement (javax.xml.bind.JAXBElement)27 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)24 ArrayList (java.util.ArrayList)24 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)20 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 Matchers.anyString (org.mockito.Matchers.anyString)14 Task (com.evolveum.midpoint.task.api.Task)13 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)13 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Holder (javax.xml.ws.Holder)12 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)12