Search in sources :

Example 91 with QueryType

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

the class CswSourceTest method testQueryWitNaturalSorting.

@Test
public void testQueryWitNaturalSorting() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 1;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    query.setSortBy(SortBy.NATURAL_ORDER);
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    SourceResponse response = cswSource.query(getQueryRequestWithSubject(query));
    // Verify
    Assert.assertNotNull(response);
    assertThat(response.getResults().size(), is(numRecordsReturned));
    assertThat(response.getHits(), is(numRecordsMatched));
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify mock CSW record count: " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
    assertThat(cswQuery.getSortBy(), nullValue());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 92 with QueryType

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

the class CswSourceTest method testQueryWithDefaultQueryType.

@Test
public void testQueryWithDefaultQueryType() throws JAXBException, UnsupportedQueryException, DatatypeConfigurationException, SAXException, IOException, SecurityServiceException {
    // Setup
    final String searchPhrase = "*";
    final int pageSize = 1;
    final int numRecordsReturned = 1;
    final long numRecordsMatched = 1;
    setupMockContextForMetacardTypeRegistrationAndUnregistration(getDefaultContentTypes());
    try {
        configureMockCsw(numRecordsReturned, numRecordsMatched, CswConstants.VERSION_2_0_2);
    } catch (CswException e) {
        fail("Could not configure Mock Remote CSW: " + e.getMessage());
    }
    QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
    query.setPageSize(pageSize);
    // Verify passing a null config for qname/prefix falls back to CSW Record
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext, null, null, null, null, permissions);
    cswSource.setCswUrl(URL);
    cswSource.setId(ID);
    // Perform test
    cswSource.query(getQueryRequestWithSubject(query));
    ArgumentCaptor<GetRecordsType> captor = ArgumentCaptor.forClass(GetRecordsType.class);
    try {
        verify(mockCsw, atLeastOnce()).getRecords(captor.capture());
    } catch (CswException e) {
        fail("Could not verify mock CSW record count: " + e.getMessage());
    }
    GetRecordsType getRecordsType = captor.getValue();
    QueryType cswQuery = (QueryType) getRecordsType.getAbstractQuery().getValue();
    assertThat(cswQuery.getTypeNames().size(), is(1));
    assertThat(cswQuery.getTypeNames().get(0), is(new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME)));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QName(javax.xml.namespace.QName) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 93 with QueryType

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

the class CswEndpointTest method testPostGetRecordsValidate.

@Test
public void testPostGetRecordsValidate() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    grr.setResultType(ResultType.VALIDATE);
    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_CONTEXTUAL_LIKE_QUERY);
    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    CswRecordCollection collection = csw.getRecords(grr);
    assertThat(collection.getCswRecords(), is(empty()));
    assertThat(collection.getNumberOfRecordsMatched(), is(0L));
    assertThat(collection.getNumberOfRecordsReturned(), is(0L));
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) 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) Test(org.junit.Test)

Example 94 with QueryType

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

the class CswEndpointTest method testPostGetRecordsValidElementSetNames.

@Test
public void testPostGetRecordsValidElementSetNames() throws CswException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    QueryType query = new QueryType();
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    ElementSetNameType elsnt = new ElementSetNameType();
    elsnt.setValue(ElementSetType.BRIEF);
    query.setElementSetName(elsnt);
    grr.setAbstractQuery(jaxbQuery);
    csw.getRecords(grr);
}
Also used : GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ElementSetNameType(net.opengis.cat.csw.v_2_0_2.ElementSetNameType) JAXBElement(javax.xml.bind.JAXBElement) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 95 with QueryType

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

the class AbstractCswSource method createQuery.

private JAXBElement<QueryType> createQuery(QueryRequest queryRequest, ElementSetType elementSetType, List<QName> elementNames) throws UnsupportedQueryException {
    QueryType queryType = new QueryType();
    QName queryTypeQName = null;
    try {
        if (StringUtils.isNotBlank(cswSourceConfiguration.getQueryTypeName())) {
            String[] parts = cswSourceConfiguration.getQueryTypeName().split(":");
            if (parts.length > 1) {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), parts[1], parts[0]);
            } else {
                queryTypeQName = new QName(cswSourceConfiguration.getQueryTypeNamespace(), cswSourceConfiguration.getQueryTypeName());
            }
        }
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Unable to parse query type QName of {}.  Defaulting to CSW Record", cswSourceConfiguration.getQueryTypeName());
    }
    if (queryTypeQName == null) {
        queryTypeQName = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME, CswConstants.CSW_NAMESPACE_PREFIX);
    }
    QueryRequest transformedQueryRequest = cswQueryFilterTransformerProvider != null ? cswQueryFilterTransformerProvider.getTransformer(cswSourceConfiguration.getQueryTypeName()).map(it -> it.transform(queryRequest, null)).orElse(queryRequest) : queryRequest;
    queryType.setTypeNames(Arrays.asList(queryTypeQName));
    if (null != elementSetType) {
        queryType.setElementSetName(createElementSetName(elementSetType));
    } else if (!CollectionUtils.isEmpty(elementNames)) {
        queryType.setElementName(elementNames);
    } else {
        queryType.setElementSetName(createElementSetName(ElementSetType.FULL));
    }
    SortByType sortBy = createSortBy(transformedQueryRequest);
    if (sortBy != null) {
        queryType.setSortBy(sortBy);
    }
    QueryConstraintType constraint = createQueryConstraint(transformedQueryRequest);
    if (null != constraint) {
        queryType.setConstraint(constraint);
    }
    ObjectFactory objectFactory = new ObjectFactory();
    return objectFactory.createQuery(queryType);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) QName(javax.xml.namespace.QName) SortByType(net.opengis.filter.v_1_1_0.SortByType) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType)

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