Search in sources :

Example 76 with QueryType

use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.

the class ModelWebServiceTest method badPagingSearch.

@Test(expectedExceptions = FaultMessage.class)
public void badPagingSearch() throws FaultMessage, SchemaException, IOException, JAXBException {
    PagingType paging = new PagingType();
    paging.setMaxSize(-1);
    paging.setOffset(-1);
    final UserType expectedUser = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
    setSecurityContext(expectedUser);
    try {
        QueryType queryType = new QueryType();
        queryType.setPaging(paging);
        modelService.searchObjects(UserType.COMPLEX_TYPE, queryType, null, new Holder<ObjectListType>(), new Holder<OperationResultType>());
    } catch (FaultMessage ex) {
        ModelTUtil.assertIllegalArgumentFault(ex);
    } finally {
        SecurityContextHolder.getContext().setAuthentication(null);
    }
    Assert.fail("Illegal argument exception was not thrown.");
}
Also used : FaultMessage(com.evolveum.midpoint.xml.ns._public.common.fault_3.FaultMessage) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) PagingType(com.evolveum.prism.xml.ns._public.query_3.PagingType) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 77 with QueryType

use of com.evolveum.prism.xml.ns._public.query_3.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 78 with QueryType

use of com.evolveum.prism.xml.ns._public.query_3.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 79 with QueryType

use of com.evolveum.prism.xml.ns._public.query_3.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 80 with QueryType

use of com.evolveum.prism.xml.ns._public.query_3.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)

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