Search in sources :

Example 11 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class PreRenderingJob method executeInternal.

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    if (interrupted) {
        return;
    }
    LOGGER.info("Start prerendering task");
    final Stopwatch stopwatch = Stopwatch.startStopwatch();
    final JobDetail details = context.getJobDetail();
    JobDataMap jobDataMap = details.getJobDataMap();
    taskConfigPrerendering = readJobConfig(jobDataMap.getString(JOB_DATA_CONFIG_FILE));
    webappFolder = jobDataMap.getString(JOB_DATA_WEBAPP_FOLDER);
    List<RenderingConfig> phenomenonStyles = taskConfigPrerendering.getPhenomenonStyles();
    List<RenderingConfig> styles = taskConfigPrerendering.getDatasetStyles();
    for (RenderingConfig config : phenomenonStyles) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put(Parameters.PHENOMENA, config.getId());
        parameters.put(Parameters.FILTER_DATASET_TYPES, "timeseries");
        parameters.put(Parameters.FILTER_OBSERVATION_TYPES, "simple");
        parameters.put(Parameters.FILTER_VALUE_TYPES, "quantity");
        IoParameters query = IoParameters.createFromSingleValueMap(parameters);
        for (DatasetOutput<?> metadata : datasetService.getCondensedParameters(query)) {
            String timeseriesId = metadata.getId();
            renderConfiguredIntervals(timeseriesId, config);
            if (interrupted) {
                return;
            }
        }
    }
    for (RenderingConfig config : styles) {
        renderConfiguredIntervals(config.getId(), config);
        if (interrupted) {
            return;
        }
    }
    LOGGER.debug("prerendering took '{}'", stopwatch.stopInSeconds());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) Stopwatch(org.n52.web.common.Stopwatch) IoParameters(org.n52.io.request.IoParameters) RenderingConfig(org.n52.io.task.PreRenderingConfig.RenderingConfig)

Example 12 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class StationsParameterController method getItem.

@Override
@RequestMapping(value = "/{item}", method = RequestMethod.GET)
public ModelAndView getItem(@PathVariable("item") String procedureId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query, HttpServletResponse response) {
    IoParameters parameters = createParameters(query, httpLocale, response);
    // TODO check parameters and throw BAD_REQUEST if invalid
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    Object result = parameterService.getParameter(procedureId, parameters);
    logRequestTime(stopwatch);
    if (result == null) {
        throw new ResourceNotFoundException("Found no station with given id.");
    }
    return new ModelAndView().addObject(result);
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class StationsParameterController method getCollection.

@Override
@RequestMapping(method = RequestMethod.GET)
public ModelAndView getCollection(HttpServletResponse response, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE, required = false) String httpLocale, @RequestParam(required = false) MultiValueMap<String, String> query) {
    IoParameters map = createParameters(query, httpLocale, response).respectBackwardsCompatibility();
    OutputCollection<?> result;
    if (map.isExpanded()) {
        Stopwatch stopwatch = Stopwatch.startStopwatch();
        result = parameterService.getExpandedParameters(map);
        logRequestTime(stopwatch);
    } else {
        Stopwatch stopwatch = Stopwatch.startStopwatch();
        result = parameterService.getCondensedParameters(map);
        logRequestTime(stopwatch);
    }
    // XXX refactor (is redundant here)
    if (map.containsParameter("limit") || map.containsParameter("offset")) {
        Long elementcount = this.counter.getStationCount();
        if (elementcount != -1) {
            OffsetBasedPagination obp = new OffsetBasedPagination(map.getOffset(), map.getLimit());
            Paginated paginated = new Paginated(obp, elementcount);
            String collectionHref = createCollectionUrl(getCollectionName());
            PageLinkUtil.addPagingHeaders(collectionHref, response, paginated);
        }
    }
    return new ModelAndView().addObject(result.getItems());
}
Also used : Paginated(org.n52.web.common.Paginated) Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) OffsetBasedPagination(org.n52.web.common.OffsetBasedPagination) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class TimeseriesDataController method getTimeseriesData.

private DataCollection<Data<QuantityValue>> getTimeseriesData(IoParameters parameters) {
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    DataCollection<Data<QuantityValue>> timeseriesData = parameters.isGeneralize() ? new GeneralizingQuantityService(timeseriesDataService).getData(parameters) : timeseriesDataService.getData(parameters);
    LOGGER.debug("Processing request took {} seconds.", stopwatch.stopInSeconds());
    return timeseriesData;
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) GeneralizingQuantityService(org.n52.io.type.quantity.generalize.GeneralizingQuantityService) Data(org.n52.io.response.dataset.Data)

Example 15 with Stopwatch

use of org.n52.web.common.Stopwatch in project arctic-sea by 52North.

the class Service method get.

@RequestMapping(method = RequestMethod.GET)
public void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    try {
        getBinding(request).doGetOperation(request, response);
    } catch (HTTPException exception) {
        onHttpException(request, response, exception);
    } finally {
        logResponse(request, response, currentCount, stopwatch);
    }
}
Also used : HTTPException(org.n52.iceland.exception.HTTPException) Stopwatch(com.google.common.base.Stopwatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Stopwatch (org.n52.web.common.Stopwatch)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 IoParameters (org.n52.io.request.IoParameters)8 Stopwatch (com.google.common.base.Stopwatch)5 HTTPException (org.n52.iceland.exception.HTTPException)5 ModelAndView (org.springframework.web.servlet.ModelAndView)4 HashMap (java.util.HashMap)2 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)2 JobDataMap (org.quartz.JobDataMap)2 JobDetail (org.quartz.JobDetail)2 Binding (org.n52.iceland.binding.Binding)1 OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)1 RenderingConfig (org.n52.io.PrerenderingJobConfig.RenderingConfig)1 GeneralizingQuantityService (org.n52.io.quantity.generalize.GeneralizingQuantityService)1 Data (org.n52.io.response.dataset.Data)1 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)1 RenderingConfig (org.n52.io.task.PreRenderingConfig.RenderingConfig)1 GeneralizingQuantityService (org.n52.io.type.quantity.generalize.GeneralizingQuantityService)1 OffsetBasedPagination (org.n52.web.common.OffsetBasedPagination)1 Paginated (org.n52.web.common.Paginated)1