Search in sources :

Example 76 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class AbstractSearchIterativeTaskHandler method createQueryFromTask.

/**
     * Ready-made implementation of createQuery - gets and parses objectQuery extension property.
     */
protected ObjectQuery createQueryFromTask(H handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException {
    Class<? extends ObjectType> objectClass = getType(task);
    LOGGER.trace("Object class = {}", objectClass);
    QueryType queryFromTask = getObjectQueryTypeFromTask(task);
    if (queryFromTask != null) {
        ObjectQuery query = QueryJaxbConvertor.createObjectQuery(objectClass, queryFromTask, prismContext);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Using object query from the task: {}", query.debugDump());
        }
        return query;
    } else {
        // Search all objects
        return new ObjectQuery();
    }
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 77 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class QueryJaxbConvertor method createQueryType.

public static QueryType createQueryType(ObjectQuery query, PrismContext prismContext) throws SchemaException {
    ObjectFilter filter = query.getFilter();
    QueryType queryType = new QueryType();
    if (filter != null) {
        SearchFilterType filterType = new SearchFilterType();
        MapXNode filterXNode = QueryConvertor.serializeFilter(filter, prismContext);
        filterType.setFilterClauseXNode(filterXNode);
        queryType.setFilter(filterType);
    }
    queryType.setPaging(PagingConvertor.createPagingType(query.getPaging()));
    return queryType;
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 78 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testAccountFilter.

@Test
public void testAccountFilter() throws Exception {
    displayTestTitle("testAccountFilter");
    SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_FILE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_FAILED_OPERATION_TYPE, FAILED_OPERATION_TYPE_QNAME, new ItemPath(ShadowType.F_FAILED_OPERATION_TYPE));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, FailedOperationTypeType.ADD);
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, ShadowType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(ShadowType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, createPolyString("someName"));
    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, "add");
    Element secondSubelement = DOMUtil.getChildElement(filterClauseElement, 1);
    DomAsserts.assertElementQName(secondSubelement, EqualFilter.ELEMENT_NAME);
    Element secondValueElement = DOMUtil.getChildElement(secondSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(secondValueElement, "someName");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) 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 79 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testUserQuery.

@Test
public void testUserQuery() throws Exception {
    displayTestTitle("testUserQuery");
    File[] userQueriesToTest = new File[] { new File(TEST_DIR, "filter-user-by-fullName.xml"), new File(TEST_DIR, "filter-user-by-name.xml"), new File(TEST_DIR, "filter-user-substring-fullName.xml"), new File(TEST_DIR, "filter-user-substring-employeeType.xml") };
    // prismContext.silentMarshalObject(queryTypeNew, LOGGER);
    for (File file : userQueriesToTest) {
        SearchFilterType filterType = PrismTestUtil.parseAtomicValue(file, SearchFilterType.COMPLEX_TYPE);
        LOGGER.info("===[ query type parsed ]===");
        ObjectQuery query;
        try {
            query = QueryJaxbConvertor.createObjectQuery(UserType.class, filterType, getPrismContext());
            LOGGER.info("query converted: ");
            LOGGER.info("QUERY DUMP: {}", query.debugDump());
            LOGGER.info("QUERY Pretty print: {}", query.toString());
            System.out.println("QUERY Pretty print: " + query.toString());
            QueryType convertedQueryType = QueryJaxbConvertor.createQueryType(query, getPrismContext());
            LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
        } catch (Exception ex) {
            LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
            throw ex;
        }
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) File(java.io.File) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Test(org.testng.annotations.Test)

Example 80 with QueryType

use of ogc.schema.opengis.wfs.v_1_0_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testTypeFilterQuery.

@Test
public void testTypeFilterQuery() throws Exception {
    displayTestTitle("testConnectorQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        query = QueryJaxbConvertor.createObjectQuery(ConnectorType.class, filterType, getPrismContext());
        displayQuery(query);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        assertTrue("filter is not an instance of type filter", filter instanceof TypeFilter);
        TypeFilter typeFilter = (TypeFilter) filter;
        assertEquals(typeFilter.getType(), UserType.COMPLEX_TYPE);
        assertNotNull("filter in type filter must not be null", typeFilter.getFilter());
        ItemPath namePath = new ItemPath(UserType.F_NAME);
        PrismPropertyDefinition ppd = getUserDefinition().findPropertyDefinition(namePath);
        PrismAsserts.assertEqualsFilter(typeFilter.getFilter(), ppd.getName(), ppd.getTypeName(), namePath);
        PrismAsserts.assertEqualsFilterValue((EqualFilter) typeFilter.getFilter(), PrismTestUtil.createPolyString("some name identificator"));
        //			PrismAsserts.assertEqualsFilter(query.getFilter(), ConnectorType.F_CONNECTOR_TYPE, DOMUtil.XSD_STRING,
        //					new ItemPath(ConnectorType.F_CONNECTOR_TYPE));
        //			PrismAsserts.assertEqualsFilterValue((EqualsFilter) filter, "org.identityconnectors.ldap.LdapConnector");
        QueryType convertedQueryType = toQueryType(query);
        displayQueryType(convertedQueryType);
    } catch (Exception ex) {
        LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
        throw ex;
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) 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)32 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 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 Task (com.evolveum.midpoint.task.api.Task)12 Holder (javax.xml.ws.Holder)12 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)12 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)12