Search in sources :

Example 26 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestCswEndpoint method testPostRetrieveProductGetRecordById.

@Test
public void testPostRetrieveProductGetRecordById() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
    final GetRecordByIdType getRecordByIdType = new GetRecordByIdType();
    getRecordByIdType.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
    getRecordByIdType.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
    getRecordByIdType.setId(Collections.singletonList("123"));
    setUpMocksForProductRetrieval(true);
    CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, null);
    assertThat(cswRecordCollection.getResource(), is(notNullValue()));
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordByIdType(net.opengis.cat.csw.v_2_0_2.GetRecordByIdType) Test(org.junit.Test)

Example 27 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestCswEndpoint method testRetrieveProductGetRecordByIdWithRange.

@Test
public void testRetrieveProductGetRecordByIdWithRange() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
    final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
    getRecordByIdRequest.setId("123");
    getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
    getRecordByIdRequest.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
    setUpMocksForProductRetrieval(true);
    CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, RANGE_VALUE);
    assertThat(cswRecordCollection.getResource(), is(notNullValue()));
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) Test(org.junit.Test)

Example 28 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class TestCswEndpoint method testRetrieveProductGetRecordById.

@Test
public void testRetrieveProductGetRecordById() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
    final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
    getRecordByIdRequest.setId("123");
    getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
    getRecordByIdRequest.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
    setUpMocksForProductRetrieval(true);
    CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, null);
    assertThat(cswRecordCollection.getResource(), is(notNullValue()));
}
Also used : CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) Test(org.junit.Test)

Example 29 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class CswQueryResponseTransformer method buildCollection.

private CswRecordCollection buildCollection(SourceResponse sourceResponse, Map<String, Serializable> arguments) {
    CswRecordCollection recordCollection = new CswRecordCollection();
    recordCollection.setNumberOfRecordsMatched(sourceResponse.getHits());
    recordCollection.setNumberOfRecordsReturned(sourceResponse.getResults().size());
    recordCollection.setStartPosition(sourceResponse.getRequest().getQuery().getStartIndex());
    Object elementSetTypeArg = arguments.get(CswConstants.ELEMENT_SET_TYPE);
    if (elementSetTypeArg instanceof ElementSetType) {
        ElementSetType elementSetType = (ElementSetType) elementSetTypeArg;
        recordCollection.setElementSetType(elementSetType);
    }
    Object elementNamesArg = arguments.get(CswConstants.ELEMENT_NAMES);
    if (elementNamesArg instanceof QName[]) {
        QName[] qnames = (QName[]) elementNamesArg;
        if (qnames.length > 0) {
            List<QName> elementNames = new ArrayList();
            for (QName entry : qnames) {
                elementNames.add(entry);
            }
            recordCollection.setElementName(elementNames);
        }
    }
    Object isByIdQuery = arguments.get(CswConstants.IS_BY_ID_QUERY);
    if (isByIdQuery != null) {
        recordCollection.setById((Boolean) isByIdQuery);
    }
    Object arg = arguments.get((CswConstants.GET_RECORDS));
    if (arg != null && arg instanceof GetRecordsType) {
        recordCollection.setRequest((GetRecordsType) arg);
    }
    Object resultType = arguments.get(CswConstants.RESULT_TYPE_PARAMETER);
    if (resultType instanceof ResultType) {
        recordCollection.setResultType((ResultType) resultType);
    }
    Object outputSchema = arguments.get(CswConstants.OUTPUT_SCHEMA_PARAMETER);
    if (outputSchema instanceof String) {
        recordCollection.setOutputSchema((String) outputSchema);
    } else {
        recordCollection.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    }
    Object doWriteNamespaces = arguments.get(CswConstants.WRITE_NAMESPACES);
    if (doWriteNamespaces instanceof Boolean) {
        recordCollection.setDoWriteNamespaces((Boolean) doWriteNamespaces);
    }
    return recordCollection;
}
Also used : QName(javax.xml.namespace.QName) ElementSetType(net.opengis.cat.csw.v_2_0_2.ElementSetType) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ArrayList(java.util.ArrayList) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ResultType(net.opengis.cat.csw.v_2_0_2.ResultType)

Example 30 with CswRecordCollection

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.

the class GetRecordsResponseConverter method unmarshal.

/**
     * Parses GetRecordsResponse XML of this form:
     * <p>
     * <pre>
     * {@code
     *  <csw:GetRecordsResponse xmlns:csw="http://www.opengis.net/cat/csw">
     *      <csw:SearchStatus status="subset" timestamp="2013-05-01T02:13:36+0200"/>
     *      <csw:SearchResults elementSet="full" nextRecord="11"
     *          numberOfRecordsMatched="479" numberOfRecordsReturned="10"
     *          recordSchema="csw:Record">
     *          <csw:Record xmlns:csw="http://www.opengis.net/cat/csw">
     *          ...
     *          </csw:Record>
     *          <csw:Record xmlns:csw="http://www.opengis.net/cat/csw">
     *          ...
     *          </csw:Record>
     *  }
     * </pre>
     */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    if (transformProvider == null) {
        throw new ConversionException("Unable to locate Converter for outputSchema: " + CswConstants.CSW_OUTPUT_SCHEMA);
    }
    CswRecordCollection cswRecords = new CswRecordCollection();
    List<Metacard> metacards = cswRecords.getCswRecords();
    XStreamAttributeCopier.copyXmlNamespaceDeclarationsIntoContext(reader, context);
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        if (reader.getNodeName().contains("SearchResults")) {
            setSearchResults(reader, cswRecords);
            // <csw:Record> into a Metacard
            while (reader.hasMoreChildren()) {
                // move down to the <csw:Record> tag
                reader.moveDown();
                String name = reader.getNodeName();
                LOGGER.debug("node name = {}", name);
                Metacard metacard = (Metacard) context.convertAnother(null, MetacardImpl.class, transformProvider);
                metacards.add(metacard);
                // move back up to the <SearchResults> parent of the
                // <csw:Record> tags
                reader.moveUp();
            }
        }
        reader.moveUp();
    }
    LOGGER.debug("Unmarshalled {} metacards", metacards.size());
    if (LOGGER.isTraceEnabled()) {
        int index = 1;
        for (Metacard m : metacards) {
            LOGGER.trace("metacard {}: ", index);
            LOGGER.trace("    id = {}", m.getId());
            LOGGER.trace("    title = {}", m.getTitle());
            // Some CSW services return an empty bounding box, i.e., no lower
            // and/or upper corner positions
            Attribute boundingBoxAttr = m.getAttribute("BoundingBox");
            if (boundingBoxAttr != null) {
                LOGGER.trace("    bounding box = {}", boundingBoxAttr.getValue());
            }
            index++;
        }
    }
    return cswRecords;
}
Also used : ConversionException(javax.measure.converter.ConversionException) Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)51 Test (org.junit.Test)26 ByteArrayInputStream (java.io.ByteArrayInputStream)21 Matchers.anyString (org.mockito.Matchers.anyString)18 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)17 JAXBElement (javax.xml.bind.JAXBElement)12 Metacard (ddf.catalog.data.Metacard)11 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)11 XStream (com.thoughtworks.xstream.XStream)10 ArrayList (java.util.ArrayList)10 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 QName (javax.xml.namespace.QName)9 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)8 Resource (ddf.catalog.resource.Resource)8 Result (ddf.catalog.data.Result)7 Ignore (jdk.nashorn.internal.ir.annotations.Ignore)7 ElementSetNameType (net.opengis.cat.csw.v_2_0_2.ElementSetNameType)7 GetRecordsResponseType (net.opengis.cat.csw.v_2_0_2.GetRecordsResponseType)7 SearchResultsType (net.opengis.cat.csw.v_2_0_2.SearchResultsType)7 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)7