Search in sources :

Example 1 with ConversionException

use of javax.measure.converter.ConversionException 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

Attribute (ddf.catalog.data.Attribute)1 Metacard (ddf.catalog.data.Metacard)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ConversionException (javax.measure.converter.ConversionException)1 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)1