Search in sources :

Example 26 with QueryConstraintType

use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.

the class CswEndpointTest method testUpdateTransactionWithConstraint.

@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Result> results = new ArrayList<>();
    MetacardImpl firstResult = new MetacardImpl();
    firstResult.setId("123");
    firstResult.setTitle("Title one");
    firstResult.setAttribute("subject", "Subject one");
    results.add(new ResultImpl(firstResult));
    MetacardImpl secondResult = new MetacardImpl();
    secondResult.setId("789");
    secondResult.setTitle("Title two");
    secondResult.setAttribute("subject", "Subject two");
    results.add(new ResultImpl(secondResult));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    QueryResponse emptyResponse = new QueryResponseImpl(null, Collections.emptyList(), 0);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(queryResponse).thenReturn(emptyResponse);
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    Map<String, Serializable> recordProperties = new HashMap<>();
    recordProperties.put("title", "foo");
    recordProperties.put("subject", "bar");
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText("title = 'fake'");
    UpdateAction updateAction = new UpdateActionImpl(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest updateRequest = new CswTransactionRequest();
    updateRequest.getUpdateActions().add(updateAction);
    updateRequest.setVersion(CswConstants.VERSION_2_0_2);
    updateRequest.setService(CswConstants.CSW);
    updateRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(updateRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(2));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
    assertThat(updates.size(), is(2));
    Metacard firstUpdate = updates.get(0).getValue();
    assertThat(firstUpdate.getId(), is("123"));
    assertThat(firstUpdate.getTitle(), is("foo"));
    assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
    Metacard secondUpdate = updates.get(1).getValue();
    assertThat(secondUpdate.getId(), is("789"));
    assertThat(secondUpdate.getTitle(), is("foo"));
    assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) UpdateActionImpl(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateActionImpl) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 27 with QueryConstraintType

use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.

the class CswQueryFactoryTest method testMultipleQueryFilterTransformers.

@Test
public void testMultipleQueryFilterTransformers() throws CswException {
    List<String> namespaces = Arrays.asList("{namespace}one", "{namespace}two");
    QueryConstraintType constraint = mock(QueryConstraintType.class);
    when(constraint.isSetCqlText()).thenReturn(true);
    when(constraint.getCqlText()).thenReturn(CQL_CONTEXTUAL_LIKE_QUERY);
    for (String namespace : namespaces) {
        QueryRequest request = mock(QueryRequest.class);
        addQueryFilterTransformer(namespace, request);
        QueryRequest result = queryFactory.getQuery(constraint, namespace);
        assertThat(result, equalTo(request));
    }
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 28 with QueryConstraintType

use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.

the class CswQueryFactoryTest method testPostGetRecordsFunctionCQLQuery.

@Test
public void testPostGetRecordsFunctionCQLQuery() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    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_CONTEXTUAL_FUNCTION_QUERY);
    query.setConstraint(constraint);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    QueryRequest queryRequest = queryFactory.getQuery(grr);
    QueryImpl frameworkQuery = (QueryImpl) queryRequest.getQuery();
    Filter queryFilter = ((QueryImpl) frameworkQuery.getFilter()).getFilter();
    assertThat(queryFilter, instanceOf(PropertyIsEqualTo.class));
    PropertyIsEqualTo equalTo = (PropertyIsEqualTo) queryFilter;
    assertThat(equalTo.getExpression1(), instanceOf(Function.class));
    Function function = (Function) equalTo.getExpression1();
    assertThat(equalTo.getExpression2(), instanceOf(Literal.class));
    Literal literal = (Literal) equalTo.getExpression2();
    assertThat(function.getName(), is("proximity"));
    assertThat(function.getParameters().get(0).evaluate(null), is(CONTEXTUAL_TEST_ATTRIBUTE));
    assertThat(function.getParameters().get(1).evaluate(null), is(1L));
    assertThat(function.getParameters().get(2).evaluate(null), is(CQL_CONTEXTUAL_PATTERN));
    assertThat(literal.getValue(), is(true));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Function(org.opengis.filter.expression.Function) QueryImpl(ddf.catalog.operation.impl.QueryImpl) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType) Test(org.junit.Test)

Example 29 with QueryConstraintType

use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.

the class CswQueryFactoryTest method ogcSpatialQuery.

/**
 * Runs a binary Spatial OGC Query, verifying that the right filter class is generated based on
 * OGC Filter
 *
 * @param spatialOps BinarySpatialOps query
 * @throws UnsupportedQueryException
 * @throws SourceUnavailableException
 * @throws FederationException
 * @throws CswException
 */
private <N extends BinarySpatialOperator> void ogcSpatialQuery(Class<N> clz, JAXBElement<BinarySpatialOpType> spatialOps) 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.setSpatialOps(spatialOps);
    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();
    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 : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) FilterType(net.opengis.filter.v_1_1_0.FilterType) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryType(net.opengis.cat.csw.v_2_0_2.QueryType)

Example 30 with QueryConstraintType

use of net.opengis.cat.csw.v_2_0_2.QueryConstraintType in project ddf by codice.

the class CswEndpointTest method testPostGetRecordsHits.

@Test
public void testPostGetRecordsHits() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    grr.setResultType(ResultType.HITS);
    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.getResultType(), is(ResultType.HITS));
}
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)

Aggregations

QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)40 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)25 QName (javax.xml.namespace.QName)22 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)22 JAXBElement (javax.xml.bind.JAXBElement)20 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)20 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)14 QueryRequest (ddf.catalog.operation.QueryRequest)11 Metacard (ddf.catalog.data.Metacard)10 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)10 Serializable (java.io.Serializable)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FilterType (net.opengis.filter.v_1_1_0.FilterType)9 QueryImpl (ddf.catalog.operation.impl.QueryImpl)8 HashMap (java.util.HashMap)8 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)8 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.actions.UpdateAction)8 Result (ddf.catalog.data.Result)7 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)7