Commit 02525ca8 authored by Noel Alonso's avatar Noel Alonso
Browse files

Contempla casos en los no hay datos para windrose

parent b2d65097
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@ package es.redmic.timeseriesview.dto.windrose;
import java.util.ArrayList;
import java.util.List;

import es.redmic.exception.elasticsearch.ESTermQueryException;

public class WindroseDataDTO extends RangesOfSplitsDTO {

	private List<WindroseSectorDTO> data = new ArrayList<WindroseSectorDTO>();
@@ -35,13 +33,10 @@ public class WindroseDataDTO extends RangesOfSplitsDTO {

	private void setLimits(Double min, Double max, Integer partitionNumber) {

		if (min == null || max == null || (min > max) || min == max || partitionNumber == null || partitionNumber == 0)
			throw new ESTermQueryException("partitionNumber", partitionNumber.toString());
		List<LimitsDTO> limits = new ArrayList<LimitsDTO>();

		double partitionLength = (max - min) / partitionNumber;

		List<LimitsDTO> limits = new ArrayList<LimitsDTO>();

		double limit = min;
		for (int i = 0; i < partitionNumber; i++) {
			limits.add(new LimitsDTO(limit, limit + partitionLength));
+16 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import org.springframework.stereotype.Repository;
import es.redmic.elasticsearchlib.timeseries.repository.RTimeSeriesESRepository;
import es.redmic.exception.common.ExceptionType;
import es.redmic.exception.common.InternalException;
import es.redmic.exception.common.NoContentException;
import es.redmic.models.es.common.query.dto.AggsPropertiesDTO;
import es.redmic.models.es.common.query.dto.DataQueryDTO;
import es.redmic.models.es.data.common.model.DataSearchWrapper;
@@ -56,12 +57,23 @@ public class WindRoseESRepository extends RTimeSeriesESRepository<TimeSeries, Da

		DataSearchWrapper<TimeSeries> responseStats = (DataSearchWrapper<TimeSeries>) find(query);

		if (responseStats.getAggregations() == null || responseStats.getAggregations().getAttributes() == null) {
			LOGGER.debug("No es posible realizar los cálculos");
			throw new InternalException(ExceptionType.INTERNAL_EXCEPTION);
		if (noContent(responseStats)) {
			LOGGER.error("No es posible realizar los cálculos. No se ha obtenido resultados");
			throw new NoContentException();
		}

		return getAttributeFromAggregations(responseStats, "stats#value");
	}

	private boolean noContent(DataSearchWrapper<TimeSeries> response) {

		boolean nullResult = response.getAggregations() == null || response.getAggregations().getAttributes() == null;
		return (nullResult || getAttributeFromAggregations(response, "stats#value").get("count").equals(0));
	}

		return (Map<String, Object>) responseStats.getAggregations().getAttributes().get("stats#value");
	@SuppressWarnings({ "unchecked" })
	private Map<String, Object> getAttributeFromAggregations(DataSearchWrapper<TimeSeries> response, String attribute) {
		return (Map<String, Object>) response.getAggregations().getAttributes().get(attribute);
	}

	@SuppressWarnings({ "serial", "unchecked" })