Search in sources :

Example 26 with IoParameters

use of org.n52.io.request.IoParameters in project series-rest-api by 52North.

the class ResourcesController method getResources.

@RequestMapping("/")
public ModelAndView getResources(@RequestParam(required = false) MultiValueMap<String, String> parameters) {
    IoParameters query = QueryParameters.createFromQuery(parameters);
    query = IoParameters.ensureBackwardsCompatibility(query);
    return new ModelAndView().addObject(createResources(query));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with IoParameters

use of org.n52.io.request.IoParameters in project series-rest-api by 52North.

the class ResourcesController method createResources.

protected List<ResourceCollection> createResources(IoParameters params) {
    IoParameters parameters = IoParameters.ensureBackwardsCompatibility(params);
    I18N i18n = I18N.getMessageLocalizer(parameters.getLocale());
    ResourceCollection services = add("services", "Service Provider", i18n.get("msg.web.resources.services"));
    ResourceCollection stations = add("stations", "Station", i18n.get("msg.web.resources.stations"));
    ResourceCollection timeseries = add("timeseries", "Timeseries", i18n.get("msg.web.resources.timeseries"));
    ResourceCollection categories = add("categories", "Category", i18n.get("msg.web.resources.categories"));
    ResourceCollection offerings = add("offerings", "Offering", i18n.get("msg.web.resources.offerings"));
    ResourceCollection features = add("features", "Feature", i18n.get("msg.web.resources.features"));
    ResourceCollection procedures = add("procedures", "Procedure", i18n.get("msg.web.resources.procedures"));
    ResourceCollection phenomena = add("phenomena", "Phenomenon", i18n.get("msg.web.resources.phenomena"));
    if (parameters.isExpanded()) {
        services.setSize(getMetadataService().getServiceCount(parameters));
        if (new FilterResolver(parameters).shallBehaveBackwardsCompatible()) {
            // ensure backwards compatibility
            stations.setSize(getMetadataService().getStationCount());
            timeseries.setSize(getMetadataService().getTimeseriesCount());
        }
        categories.setSize(getMetadataService().getCategoryCount(parameters));
        offerings.setSize(getMetadataService().getOfferingCount(parameters));
        features.setSize(getMetadataService().getFeatureCount(parameters));
        procedures.setSize(getMetadataService().getProcedureCount(parameters));
        phenomena.setSize(getMetadataService().getPhenomenaCount(parameters));
    }
    List<ResourceCollection> resources = new ArrayList<>();
    resources.add(services);
    resources.add(stations);
    resources.add(timeseries);
    resources.add(categories);
    resources.add(offerings);
    resources.add(features);
    resources.add(procedures);
    resources.add(phenomena);
    // since 2.0.0
    ResourceCollection platforms = add("platforms", "Platforms", i18n.get("msg.web.resources.platforms"));
    ResourceCollection datasets = add("datasets", "Datasets", i18n.get("msg.web.resources.datasets"));
    ResourceCollection geometries = add("geometries", "Geometries", i18n.get("msg.web.resources.geometries"));
    resources.add(platforms);
    resources.add(datasets);
    resources.add(geometries);
    if (parameters.isExpanded()) {
        platforms.setSize(getMetadataService().getPlatformCount(parameters));
        datasets.setSize(getMetadataService().getDatasetCount(parameters));
    }
    return resources;
}
Also used : FilterResolver(org.n52.io.request.FilterResolver) ArrayList(java.util.ArrayList) IoParameters(org.n52.io.request.IoParameters) I18N(org.n52.io.I18N)

Example 28 with IoParameters

use of org.n52.io.request.IoParameters in project series-rest-api by 52North.

the class SearchController method searchResources.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView searchResources(@RequestParam String q, @RequestHeader(value = "accept-language") String locale, @RequestParam(required = false) MultiValueMap<String, String> parameters) {
    IoParameters map = QueryParameters.createFromQuery(parameters).extendWith(Parameters.SEARCH_TERM, q).extendWith(Parameters.LOCALE, locale);
    IoParameters query = IoParameters.ensureBackwardsCompatibility(map);
    return new ModelAndView().addObject(searchService.searchResources(query));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with IoParameters

use of org.n52.io.request.IoParameters in project series-rest-api by 52North.

the class TimeseriesDataController method getTimeseriesAsCsv.

private void getTimeseriesAsCsv(String timeseriesId, IoParameters query, HttpServletResponse response) throws IoHandlerException, DatasetFactoryException, URISyntaxException, MalformedURLException, IOException {
    checkIfUnknownTimeseries(query, timeseriesId);
    RequestSimpleParameterSet parameters = RequestSimpleParameterSet.createForSingleSeries(timeseriesId, query);
    checkAgainstTimespanRestriction(parameters.getTimespan());
    parameters.setGeneralize(query.isGeneralize());
    parameters.setExpanded(query.isExpanded());
    response.setCharacterEncoding("UTF-8");
    if (Boolean.parseBoolean(query.getOther(MimeType.APPLICATION_ZIP.name()))) {
        response.setContentType(MimeType.APPLICATION_ZIP.toString());
    } else {
        response.setContentType(MimeType.TEXT_CSV.toString());
    }
    createIoFactory(parameters).createHandler(MimeType.TEXT_CSV.toString()).writeBinary(response.getOutputStream());
}
Also used : RequestSimpleParameterSet(org.n52.io.request.RequestSimpleParameterSet)

Example 30 with IoParameters

use of org.n52.io.request.IoParameters in project series-rest-api by 52North.

the class TimeseriesDataController method getAsZippedCsv.

@RequestMapping(value = "/{timeseriesId}/getData", produces = { "application/zip" }, method = RequestMethod.GET)
public void getAsZippedCsv(HttpServletResponse response, @PathVariable String timeseriesId, @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).extendWith(MimeType.APPLICATION_ZIP.name(), Boolean.TRUE.toString());
    response.setContentType(MimeType.APPLICATION_ZIP.getMimeType());
    getTimeseriesAsCsv(timeseriesId, map, response);
}
Also used : IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IoParameters (org.n52.io.request.IoParameters)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)20 RequestSimpleParameterSet (org.n52.io.request.RequestSimpleParameterSet)14 ModelAndView (org.springframework.web.servlet.ModelAndView)7 Test (org.junit.Test)5 IntervalWithTimeZone (org.n52.io.IntervalWithTimeZone)4 Stopwatch (org.n52.web.common.Stopwatch)4 IoStyleContext (org.n52.io.IoStyleContext)3 RequestStyledParameterSet (org.n52.io.request.RequestStyledParameterSet)3 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 I18N (org.n52.io.I18N)1