Search in sources :

Example 21 with QueryConstraintType

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

the class TestCswEndpoint 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);
    when(catalogFramework.query(argument.capture())).thenReturn(getQueryResponse());
    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 22 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();
    assertThat(frameworkQuery.getFilter(), instanceOf(clz));
    @SuppressWarnings("unchecked") N spatial = (N) frameworkQuery.getFilter();
    assertThat(((LiteralExpressionImpl) spatial.getExpression2()).getValue(), is(polygon));
    assertThat(((AttributeExpressionImpl) spatial.getExpression1()).getPropertyName(), is(SPATIAL_TEST_ATTRIBUTE));
}
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 23 with QueryConstraintType

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

the class TestCswEndpoint method testPostGetRecordsResults.

@Test
public void testPostGetRecordsResults() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    GetRecordsType grr = createDefaultPostRecordsRequest();
    grr.setResultType(ResultType.RESULTS);
    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);
    ElementSetNameType esnt = new ElementSetNameType();
    esnt.setValue(ElementSetType.SUMMARY);
    query.setElementSetName(esnt);
    JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
    grr.setAbstractQuery(jaxbQuery);
    final String exampleSchema = CswConstants.CSW_OUTPUT_SCHEMA;
    grr.setOutputSchema(exampleSchema);
    final String exampleMime = "application/xml";
    grr.setOutputFormat(exampleMime);
    CswRecordCollection collection = csw.getRecords(grr);
    assertThat(collection.getMimeType(), is(exampleMime));
    assertThat(collection.getOutputSchema(), is(exampleSchema));
    assertThat(collection.getSourceResponse(), notNullValue());
    assertThat(collection.getResultType(), is(ResultType.RESULTS));
    assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY));
}
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) 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) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Test(org.junit.Test)

Example 24 with QueryConstraintType

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

the class TransactionRequestConverter method parseUpdateAction.

private UpdateAction parseUpdateAction(HierarchicalStreamReader reader, UnmarshallingContext context) {
    Map<String, String> xmlnsAttributeToUriMappings = getXmlnsAttributeToUriMappingsFromContext(context);
    Map<String, String> prefixToUriMappings = getPrefixToUriMappingsFromXmlnsAttributes(xmlnsAttributeToUriMappings);
    String typeName = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.TYPE_NAME_PARAMETER), CswConstants.CSW_RECORD);
    String handle = StringUtils.defaultIfEmpty(reader.getAttribute(CswConstants.HANDLE_PARAMETER), "");
    // Move down to the content of the <Update>.
    reader.moveDown();
    UpdateAction updateAction;
    // Do we have a list of <RecordProperty> elements or a new <csw:Record>?
    if (reader.getNodeName().contains("RecordProperty")) {
        Map<String, Serializable> cswRecordProperties = new HashMap<>();
        while (reader.getNodeName().contains("RecordProperty")) {
            String cswField;
            Serializable newValue = null;
            // Move down to the <Name>.
            reader.moveDown();
            if (reader.getNodeName().contains("Name")) {
                String attribute = reader.getValue();
                cswField = CswRecordConverter.getCswAttributeFromAttributeName(attribute);
            } else {
                throw new ConversionException("Missing Parameter Value: missing a Name in a RecordProperty.");
            }
            // Move back up to the <RecordProperty>.
            reader.moveUp();
            String attrName = DefaultCswRecordMap.getDefaultMetacardFieldForPrefixedString(cswField);
            cswRecordProperties.put(attrName, null);
            // Is there a <Value>?
            while (reader.hasMoreChildren()) {
                // Move down to the <Value>.
                reader.moveDown();
                if (reader.getNodeName().contains("Value")) {
                    newValue = getRecordPropertyValue(reader, attrName);
                } else {
                    throw new ConversionException("Invalid Parameter Value: invalid element in a RecordProperty.");
                }
                Serializable currentValue = cswRecordProperties.get(attrName);
                if (currentValue != null) {
                    if (currentValue instanceof List) {
                        ((List) currentValue).add(newValue);
                    } else {
                        LinkedList<Serializable> list = new LinkedList<>();
                        list.add(currentValue);
                        list.add(newValue);
                        cswRecordProperties.put(attrName, list);
                    }
                } else {
                    cswRecordProperties.put(attrName, newValue);
                }
                // Back to the <RecordProperty>.
                reader.moveUp();
            }
            // Back to the <Update>, look for the next <RecordProperty>.
            reader.moveUp();
            if (!reader.hasMoreChildren()) {
                // Constraint, which is required.
                throw new ConversionException("Missing Parameter Value: missing a Constraint.");
            }
            // What's the next element in the <Update>?
            reader.moveDown();
        }
        // Now there should be a <Constraint> element.
        if (reader.getNodeName().contains("Constraint")) {
            StringWriter writer = new StringWriter();
            XStreamAttributeCopier.copyXml(reader, writer, xmlnsAttributeToUriMappings);
            QueryConstraintType constraint = getElementFromXml(writer.toString(), QueryConstraintType.class);
            // For any CSW attributes that map to basic metacard attributes (e.g. title,
            // modified date, etc.), update the basic metacard attributes as well.
            Map<String, String> cswToMetacardAttributeNames = DefaultCswRecordMap.getDefaultCswRecordMap().getCswToMetacardAttributeNames();
            Map<String, Serializable> cswRecordPropertiesWithMetacardAttributes = new HashMap<>(cswRecordProperties);
            for (Entry<String, Serializable> recordProperty : cswRecordProperties.entrySet()) {
                String cswAttributeName = recordProperty.getKey();
                // basic metacard attribute.
                if (cswToMetacardAttributeNames.containsKey(cswAttributeName)) {
                    String metacardAttrName = cswToMetacardAttributeNames.get(cswAttributeName);
                    // If this basic metacard attribute hasn't already been set, set it.
                    if (!cswRecordPropertiesWithMetacardAttributes.containsKey(metacardAttrName)) {
                        Attribute metacardAttr = cswRecordConverter.getMetacardAttributeFromCswAttribute(cswAttributeName, recordProperty.getValue(), metacardAttrName);
                        cswRecordPropertiesWithMetacardAttributes.put(metacardAttrName, metacardAttr.getValue());
                    }
                }
            }
            updateAction = new UpdateAction(cswRecordPropertiesWithMetacardAttributes, typeName, handle, constraint, prefixToUriMappings);
        } else {
            throw new ConversionException("Missing Parameter Value: missing a Constraint.");
        }
    } else {
        context.put(CswConstants.TRANSFORMER_LOOKUP_KEY, TransformerManager.ID);
        context.put(CswConstants.TRANSFORMER_LOOKUP_VALUE, typeName);
        Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class, delegatingTransformer);
        updateAction = new UpdateAction(metacard, typeName, handle);
        // Move back to the <Update>.
        reader.moveUp();
    }
    return updateAction;
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) Serializable(java.io.Serializable) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) LinkedList(java.util.LinkedList) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

QueryConstraintType (net.opengis.cat.csw.v_2_0_2.QueryConstraintType)24 ArrayList (java.util.ArrayList)17 QName (javax.xml.namespace.QName)14 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)14 JAXBElement (javax.xml.bind.JAXBElement)13 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)13 Test (org.junit.Test)12 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 FilterType (net.opengis.filter.v_1_1_0.FilterType)7 CswTransactionRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest)7 Metacard (ddf.catalog.data.Metacard)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)5 QueryRequest (ddf.catalog.operation.QueryRequest)5 Serializable (java.io.Serializable)5 UpdateAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction)5 HashMap (java.util.HashMap)4 DeleteType (net.opengis.cat.csw.v_2_0_2.DeleteType)4 DeleteAction (org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.DeleteAction)4 Result (ddf.catalog.data.Result)3 QueryResponse (ddf.catalog.operation.QueryResponse)3