Search in sources :

Example 16 with Data

use of org.n52.io.response.dataset.Data in project arctic-sea by 52North.

the class EmbeddedServerIT method connectEmbeddedMode.

@Test
public void connectEmbeddedMode() throws Exception {
    settings.setNodeConnectionMode(ElasticsearchSettingsKeys.CONNECTION_MODE_EMBEDDED_SERVER);
    adminHandler.init();
    Map<String, Object> data = new HashMap<>();
    data.put("test", "test-string");
    IndexResponse idx = dataHandler.persist(data);
    Thread.sleep(2000);
    String ret = dataHandler.getClient().prepareGet(idx.getIndex(), idx.getType(), idx.getId()).get().getSourceAsString();
    Assert.assertNotNull(ret);
    adminHandler.destroy();
    try {
        FileUtils.deleteDirectory(new File("./elasticsearch"));
    } catch (IOException e) {
        logger.info(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) IOException(java.io.IOException) File(java.io.File) SpringBaseTest(org.n52.iceland.statistics.basetests.SpringBaseTest) Test(org.junit.Test)

Example 17 with Data

use of org.n52.io.response.dataset.Data in project arctic-sea by 52North.

the class UVFEncoder method encodeToUvf.

private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
    List<OmObservation> mergeObservations = mergeTotoList(observationStream);
    String ending = getLineEnding(contentType);
    String filename = getFilename(mergeObservations);
    File uvfFile = new File(tempDir, filename);
    try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
        for (OmObservation o : mergeObservations) {
            if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
                String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
                LOGGER.error(errorMessage);
                throw new EncodingException(errorMessage);
            }
            /*
                 * HEADER: Metadata
                 */
            writeFunktionInterpretation(fw, o, ending);
            writeIndex(fw, ending);
            writeMessGroesse(fw, o, ending);
            writeMessEinheit(fw, o, ending);
            writeMessStellennummer(fw, o, ending);
            writeMessStellenname(fw, o, ending);
            /*
                 * HEADER: Lines 1 - 4
                 */
            writeLine1(fw, ending);
            TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
            writeLine2(fw, o, temporalBBox, ending);
            writeLine3(fw, o, ending);
            writeLine4(fw, temporalBBox, ending);
            /*
                 * Observation Data
                 */
            writeObservationValue(fw, o, ending);
        }
    }
    return uvfFile;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) FileOutputStream(java.io.FileOutputStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 18 with Data

use of org.n52.io.response.dataset.Data in project arctic-sea by 52North.

the class SensorMLDecoderV20 method parseDataInterfaceType.

protected SmlDataInterface parseDataInterfaceType(DataInterfaceType xbDataInterface) throws DecodingException {
    SmlDataInterface dataInterface = new SmlDataInterface();
    // TODO implement- no funding at the moment available
    // When starting implementation: Do not forget to activate the already
    // available unit tests
    Object data = decodeXmlElement(xbDataInterface.getData());
    if (data instanceof SweDataStream) {
        dataInterface.setData((SweDataStream) data);
    }
    if (xbDataInterface.isSetInterfaceParameters()) {
        Object parameter = decodeXmlElement(xbDataInterface.getInterfaceParameters());
        if (parameter instanceof SweDataRecord) {
            dataInterface.setInputParameters((SweDataRecord) parameter);
        }
    // TODO throw exception if not instance of SweDataRecord
    }
    return dataInterface;
}
Also used : SweDataStream(org.n52.shetland.ogc.swe.SweDataStream) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) DescribedObject(org.n52.shetland.ogc.sensorML.v20.DescribedObject) XmlObject(org.apache.xmlbeans.XmlObject) SmlDataInterface(org.n52.shetland.ogc.sensorML.v20.SmlDataInterface)

Example 19 with Data

use of org.n52.io.response.dataset.Data in project arctic-sea by 52North.

the class SensorMLDecoderV101 method parseCapabilities.

/**
 * Parses the capabilities, processing and removing special insertion metadata
 *
 * @param abstractProcess The AbstractProcess to which capabilities and insertion metadata are added
 * @param capabilitiesArray XML capabilities
 *
 * @throws DecodingException if an error occurs
 */
private void parseCapabilities(final AbstractProcess abstractProcess, final Capabilities[] capabilitiesArray) throws DecodingException {
    for (final Capabilities xbcaps : capabilitiesArray) {
        final SmlCapabilities caps = new SmlCapabilities();
        if (xbcaps.isSetName()) {
            caps.setName(xbcaps.getName());
        }
        if (xbcaps.isSetAbstractDataRecord()) {
            final Object o = decodeXmlElement(xbcaps.getAbstractDataRecord());
            if (o instanceof DataRecord) {
                final DataRecord record = (DataRecord) o;
                caps.setDataRecord(record).setName(xbcaps.getName());
            } else {
                throw new DecodingException(XmlHelper.getLocalName(xbcaps), "Error while parsing the capabilities of the SensorML (the " + "capabilities data record is not of type DataRecordPropertyType)!");
            }
        } else if (xbcaps.isSetHref()) {
            caps.setHref(xbcaps.getHref());
            if (xbcaps.isSetTitle()) {
                caps.setTitle(xbcaps.getTitle());
            }
        }
        if (caps.isSetName()) {
            abstractProcess.addCapabilities(caps);
        }
    }
}
Also used : SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) Capabilities(net.opengis.sensorML.x101.CapabilitiesDocument.Capabilities) SmlCapabilities(org.n52.shetland.ogc.sensorML.elements.SmlCapabilities) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) DataRecord(org.n52.shetland.ogc.swe.DataRecord)

Example 20 with Data

use of org.n52.io.response.dataset.Data in project arctic-sea by 52North.

the class SpecimenEncoderv20 method createSpecimen.

private XmlObject createSpecimen(SfSpecimen specimen) throws EncodingException {
    SFSpecimenDocument sfsd = SFSpecimenDocument.Factory.newInstance(getXmlOptions());
    if (specimen.isSetXml()) {
        try {
            final XmlObject feature = XmlObject.Factory.parse(specimen.getXml(), getXmlOptions());
            XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), specimen.getGmlId(), null);
            if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SPEC) && feature instanceof SFSpecimenType) {
                sfsd.setSFSpecimen((SFSpecimenType) feature);
                addName(sfsd.getSFSpecimen(), specimen);
                addDescription(sfsd.getSFSpecimen(), specimen);
                return sfsd;
            }
            addName(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
            addDescription(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
            return feature;
        } catch (final XmlException xmle) {
            throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid specimen description!", xmle);
        }
    }
    final SFSpecimenType sfst = sfsd.addNewSFSpecimen();
    // TODO: CHECK for all fields set gml:id
    addId(sfst, specimen);
    addIdentifier(sfst, specimen);
    // set type
    addFeatureType(sfst, specimen);
    addName(sfst, specimen);
    addDescription(sfst, specimen);
    // set sampledFeatures
    addSampledFeatures(sfst, specimen);
    addParameter(sfst, specimen);
    // set specimen specific data
    addMaterialClass(sfst, specimen);
    addSamplingTime(sfst, specimen);
    addSamplingMethod(sfst, specimen);
    addSamplingLocation(sfst, specimen);
    addProcessingDetails(sfst, specimen);
    addSize(sfst, specimen);
    addCurrentLocation(sfst, specimen);
    addSpecimenType(sfst, specimen);
    specimen.wasEncoded();
    return sfsd;
}
Also used : SFSpecimenType(net.opengis.samplingSpecimen.x20.SFSpecimenType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) SFSpecimenDocument(net.opengis.samplingSpecimen.x20.SFSpecimenDocument)

Aggregations

IoParameters (org.n52.io.request.IoParameters)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 Data (org.n52.io.response.dataset.Data)13 IOException (java.io.IOException)12 QuantityValue (org.n52.io.response.dataset.quantity.QuantityValue)11 HashMap (java.util.HashMap)6 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)6 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)6 InputStream (java.io.InputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)5 IoParseException (org.n52.io.IoParseException)5 File (java.io.File)4 Test (org.junit.Test)4 InternalServerException (org.n52.web.exception.InternalServerException)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 BigDecimal (java.math.BigDecimal)3 ElasticsearchAwareTest (org.n52.iceland.statistics.basetests.ElasticsearchAwareTest)3 ResultTimeClassifiedData (org.n52.io.format.ResultTimeClassifiedData)3 RawDataService (org.n52.series.spi.srv.RawDataService)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3