Search in sources :

Example 11 with Data

use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.

the class DataController method getSeriesAsCsv.

@RequestMapping(value = "/{seriesId}/data", produces = { "text/csv" }, method = RequestMethod.GET)
public void getSeriesAsCsv(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    LOGGER.debug("get data collection csv for '{}' with query: {}", seriesId, map);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    checkForUnknownDatasetIds(map, seriesId);
    response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
    if (Boolean.parseBoolean(map.getOther("zip"))) {
        response.setContentType(MimeType.APPLICATION_ZIP.toString());
    } else {
        response.setContentType(MimeType.TEXT_CSV.toString());
    }
    final String datasetType = parameters.getValueType();
    createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(MimeType.TEXT_CSV.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Data

use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.

the class DataController method getSeriesAsZippedCsv.

@RequestMapping(value = "/{seriesId}/data", produces = { "application/zip" }, method = RequestMethod.GET)
public void getSeriesAsZippedCsv(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) throws Exception {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    LOGGER.debug("get data collection zip for '{}' with query: {}", seriesId, map);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    checkForUnknownDatasetIds(map, seriesId);
    response.setCharacterEncoding(DEFAULT_RESPONSE_ENCODING);
    response.setContentType(MimeType.APPLICATION_ZIP.toString());
    final String datasetType = parameters.getValueType();
    createIoFactory(datasetType).withSimpleRequest(parameters).createHandler(MimeType.APPLICATION_ZIP.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Data

use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.

the class DataController method getRawSeriesData.

@RequestMapping(value = "/{seriesId}/data", method = RequestMethod.GET, params = { RawFormats.RAW_FORMAT })
public void getRawSeriesData(HttpServletResponse response, @PathVariable String seriesId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    checkForUnknownDatasetIds(map, seriesId);
    LOGGER.debug("getSeriesCollection() with query: {}", map);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(seriesId, map);
    writeRawData(parameters, response);
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Data

use of org.n52.io.response.dataset.Data in project series-rest-api by 52North.

the class TimeseriesDataController method processRawDataRequest.

private void processRawDataRequest(HttpServletResponse response, RequestSimpleParameterSet query) {
    if (!timeseriesDataService.supportsRawData()) {
        throwNewRawDataQueryNotSupportedException();
    }
    final RawDataService rawDataService = timeseriesDataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(query)) {
        if (inputStream == null) {
            throw new ResourceNotFoundException("No raw data found.");
        }
        response.setContentType(query.getFormat());
        IOUtils.copyLarge(inputStream, response.getOutputStream());
    } catch (IOException e) {
        throw new InternalServerException("Error while querying raw data", e);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 15 with Data

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

the class ElasticsearchAdminHandler method initTransportMode.

/**
 * Starts client mode in {@link TransportClient} remote mode
 */
private void initTransportMode() {
    Objects.requireNonNull(settings.getClusterName());
    Objects.requireNonNull(settings.getClusterNodes());
    Settings.Builder tcSettings = Settings.settingsBuilder();
    tcSettings.put("cluster.name", settings.getClusterName());
    TransportClient cl = TransportClient.builder().settings(tcSettings).build();
    // nodes has format host[:port]
    settings.getClusterNodes().stream().forEach(i -> {
        InetSocketTransportAddress address = null;
        if (i.contains(":")) {
            try {
                String[] split = i.split(":");
                address = new InetSocketTransportAddress(InetAddress.getByName(split[0]), Integer.valueOf(split[1]));
            } catch (UnknownHostException e) {
                logConnectionError(i, e);
            }
        } else {
            try {
                // default communication port
                address = new InetSocketTransportAddress(InetAddress.getByName(i), 9300);
            } catch (UnknownHostException e) {
                logConnectionError(i, e);
            }
        }
        if (address != null) {
            cl.addTransportAddress(address);
        }
    });
    this.client = cl;
    logger.info("ElasticSearch data handler starting in Remote mode");
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) UnknownHostException(java.net.UnknownHostException) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings) ElasticsearchSettings(org.n52.iceland.statistics.api.ElasticsearchSettings)

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