Search in sources :

Example 11 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testShadowKindTypeQuery.

@Test
public void testShadowKindTypeQuery() throws Exception {
    displayTestTitle("testShadowKindTypeQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        ObjectFilter kindFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
        query = ObjectQuery.createObjectQuery(kindFilter);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        assertTrue("filter is not an instance of type filter", filter instanceof EqualFilter);
        EqualFilter typeFilter = (EqualFilter) filter;
        assertEquals(typeFilter.getSingleValue().getRealValue(), ShadowKindType.ACCOUNT);
        QueryType convertedQueryType = toQueryType(query);
        toObjectQuery(ShadowType.class, convertedQueryType);
        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) Test(org.testng.annotations.Test)

Example 12 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method test430OrgFilterDefaultScope.

@Test
public void test430OrgFilterDefaultScope() throws Exception {
    final String TEST_NAME = "test430OrgFilterDefaultScope";
    displayTestTitle(TEST_NAME);
    // default scope is SUBTREE
    String queryXml = "<?xml version='1.0'?><query><filter><org>\n" + "        <orgRef>\n" + "            <oid>333</oid>\n" + "        </orgRef>\n" + "    </org></filter></query>";
    QueryType queryJaxb = toQueryType(queryXml);
    displayQueryType(queryJaxb);
    ObjectQuery query = toObjectQuery(OrgType.class, queryJaxb);
    displayQuery(query);
    ObjectQuery expectedQuery = QueryBuilder.queryFor(OrgType.class, getPrismContext()).isChildOf("333").build();
    // primitive way of comparing queries
    assertEquals("Parsed query is wrong", expectedQuery.toString(), query.toString());
    // now reserialize the parsed query and compare with XML - the XML contains explicit scope=SUBTREE (as this is set when parsing original queryXml)
    checkQueryRoundtripFile(OrgType.class, query, TEST_NAME);
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 13 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class TestQueryConvertor method testGenericQuery.

@Test
public void testGenericQuery() throws Exception {
    displayTestTitle("testGenericQuery");
    SearchFilterType queryType = unmarshalFilter(FILTER_AND_GENERIC_FILE);
    ObjectQuery query = toObjectQuery(GenericObjectType.class, queryType);
    displayQuery(query);
    // check parent filter
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    // check first condition
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, GenericObjectType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(GenericObjectType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, createPolyString("generic object"));
    // check second condition
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, intExtensionDefinition, DOMUtil.XSD_INT, new ItemPath(ObjectType.F_EXTENSION, new QName(NS_EXTENSION, "intType")));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, 123);
    QueryType convertedQueryType = toQueryType(query);
    assertNotNull("Re-serialized query is null ", convertedQueryType);
    assertNotNull("Filter in re-serialized query must not be null.", convertedQueryType.getFilter());
    displayQueryType(convertedQueryType);
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class PageRepositoryQuery method updateRequestWithMidpointQuery.

private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismContext prismContext = getPrismContext();
    if (objectType == null) {
        objectType = ObjectType.COMPLEX_TYPE;
    }
    @SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
    if (clazz == null) {
        throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
    }
    QueryType queryType = prismContext.parserFor(queryText).xml().parseRealValue(QueryType.class);
    request.setType(clazz);
    ObjectQuery objectQuery = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
    ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new ExpressionVariables(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
    request.setQuery(queryWithExprEvaluated);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContext(com.evolveum.midpoint.prism.PrismContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 15 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project midpoint by Evolveum.

the class QueryBasedHandlerDto method getObjectQuery.

public String getObjectQuery() {
    QueryType query = taskDto.getExtensionPropertyRealValue(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY, QueryType.class);
    if (query == null) {
        return null;
    }
    PrismContext prismContext = ((MidPointApplication) Application.get()).getPrismContext();
    try {
        return WebXmlUtil.stripNamespaceDeclarations(prismContext.xmlSerializer().serializeAnyData(query, SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY));
    } catch (SchemaException e) {
        throw new SystemException("Couldn't serialize query: " + e.getMessage(), e);
    }
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException) PrismContext(com.evolveum.midpoint.prism.PrismContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)91 Test (org.junit.Test)89 QueryImpl (ddf.catalog.operation.impl.QueryImpl)71 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)67 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)58 Test (org.testng.annotations.Test)52 QName (javax.xml.namespace.QName)50 JAXBElement (javax.xml.bind.JAXBElement)44 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)38 ArrayList (java.util.ArrayList)37 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)34 Filter (org.opengis.filter.Filter)32 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)23 SortBy (org.opengis.filter.sort.SortBy)22 QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)21 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)21 SortByImpl (ddf.catalog.filter.impl.SortByImpl)20 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)19 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)19 ObjectFactory (net.opengis.cat.csw.v_2_0_2.ObjectFactory)18