Search in sources :

Example 96 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.

the class AbstractCswSource method createSubscriptionGetRecordsRequest.

private GetRecordsType createSubscriptionGetRecordsRequest() {
    GetRecordsType getRecordsType = new GetRecordsType();
    getRecordsType.setVersion(cswVersion);
    getRecordsType.setService(CswConstants.CSW);
    getRecordsType.setResultType(ResultType.RESULTS);
    getRecordsType.setStartPosition(BigInteger.ONE);
    getRecordsType.setMaxRecords(BigInteger.TEN);
    getRecordsType.setOutputFormat(MediaType.APPLICATION_XML);
    getRecordsType.setOutputSchema("urn:catalog:metacard");
    getRecordsType.getResponseHandler().add(SystemBaseUrl.EXTERNAL.constructUrl("csw/subscription/event", true));
    QueryType queryType = new QueryType();
    queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
    ObjectFactory objectFactory = new ObjectFactory();
    getRecordsType.setAbstractQuery(objectFactory.createQuery(queryType));
    return getRecordsType;
}
Also used : ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType)

Example 97 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.

the class CswQueryFactoryTest method generateTemporalFilter.

private Filter generateTemporalFilter(JAXBElement<BinaryComparisonOpType> temporalOps) throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    FilterType filter = new FilterType();
    filter.setComparisonOps(temporalOps);
    constraint.setFilter(filter);
    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    return ((QueryImpl) frameworkQuery.getFilter()).getFilter();
}
Also used : FilterType(net.opengis.filter.v_1_1_0.FilterType) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType)

Example 98 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.

the class CswQueryFactoryTest method testPostGetRecordsValidSort.

@Test
public void testPostGetRecordsValidSort() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    grr.setResultType(ResultType.RESULTS);
    QueryType query = new QueryType();
    SortByType incomingSort = new SortByType();
    SortPropertyType propType = new SortPropertyType();
    PropertyNameType propName = new PropertyNameType();
    propName.setContent(Collections.singletonList(TITLE_TEST_ATTRIBUTE));
    propType.setPropertyName(propName);
    incomingSort.getSortProperty().add(propType);
    query.setSortBy(incomingSort);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    QueryRequest queryRequest = queryFactory.getQuery(grr);
    SortBy resultSort = queryRequest.getQuery().getSortBy();
    assertThat(resultSort.getPropertyName().getPropertyName(), is(CQL_FRAMEWORK_TEST_ATTRIBUTE));
    assertThat(resultSort.getSortOrder(), is(SortOrder.ASCENDING));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) SortPropertyType(net.opengis.filter.v_1_1_0.SortPropertyType) SortByType(net.opengis.filter.v_1_1_0.SortByType) JAXBElement(javax.xml.bind.JAXBElement) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) PropertyNameType(net.opengis.filter.v_1_1_0.PropertyNameType) Test(org.junit.Test)

Example 99 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.

the class CswQueryFactoryTest method cqlSpatialQuery.

/**
 * Runs a binary Spatial CQL Query, verifying that the right filter class is generated based on
 * CQL
 *
 * @param clz Class of filter to generate
 * @param cql CQL Query String
 * @throws UnsupportedQueryException
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends BinarySpatialOperator> void cqlSpatialQuery(Class<N> clz, String cql) throws UnsupportedQueryException, SourceUnavailableException, FederationException, CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    QueryType query = new QueryType();
    List<QName> typeNames = new ArrayList<>();
    typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
    query.setTypeNames(typeNames);
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText(cql);
    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    QueryImpl frameworkQuery = (QueryImpl) queryFactory.getQuery(grr).getQuery();
    Filter queryFilter = ((QueryImpl) frameworkQuery.getFilter()).getFilter();
    assertThat(queryFilter, instanceOf(clz));
    @SuppressWarnings("unchecked") N spatial = (N) queryFilter;
    assertThat(((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));
    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(), is(SPATIAL_TEST_ATTRIBUTE));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType)

Example 100 with QueryType

use of net.opengis.wfs.v_1_1_0.QueryType in project ddf by codice.

the class CswQueryFactory method getQuery.

public QueryRequest getQuery(GetRecordsType request) throws CswException {
    QueryType query = (QueryType) request.getAbstractQuery().getValue();
    Filter filter = buildFilter(query.getConstraint());
    QueryImpl frameworkQuery = new QueryImpl(filter);
    SortBy[] sortBys = buildSort(query.getSortBy());
    SortBy[] extSortBys = null;
    if (sortBys != null && sortBys.length > 0) {
        frameworkQuery.setSortBy(sortBys[0]);
        extSortBys = Arrays.copyOfRange(sortBys, 1, sortBys.length);
    }
    if (ResultType.HITS.equals(request.getResultType()) || request.getMaxRecords().intValue() < 1) {
        frameworkQuery.setStartIndex(1);
        frameworkQuery.setPageSize(1);
    } else {
        frameworkQuery.setStartIndex(request.getStartPosition().intValue());
        frameworkQuery.setPageSize(request.getMaxRecords().intValue());
    }
    boolean isEnterprise = request.getDistributedSearch() != null && (request.getDistributedSearch().getHopCount().longValue() > 1);
    Map<String, Serializable> properties = new HashMap<>();
    if (extSortBys != null && extSortBys.length > 0) {
        properties.put(ADDITIONAL_SORT_BYS, extSortBys);
    }
    QueryRequest queryRequest = getQueryRequest(frameworkQuery, isEnterprise, properties);
    return transformQuery(queryRequest, query.getTypeNames());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Serializable(java.io.Serializable) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) SortBy(org.opengis.filter.sort.SortBy) QueryType(net.opengis.cat.csw.v_2_0_2.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