Commit bfbb667e authored by Noel Alonso's avatar Noel Alonso
Browse files

Añade control de nulos y reestructura código

parent 084c3944
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -57,14 +57,14 @@ public class ObjectCollectingSeriesController extends RSeriesController<ObjectCo
	@ResponseBody
	public SuperDTO findClassificationList(@Valid @RequestBody DataQueryDTO queryDTO, BindingResult bindingResult) {

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		AggsPropertiesDTO agg = new AggsPropertiesDTO();
		agg.setField("classificationList");
		queryDTO.addAgg(agg);
		queryDTO.setSize(0);

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		return service.findClassificationList(queryDTO);
	}

@@ -72,14 +72,14 @@ public class ObjectCollectingSeriesController extends RSeriesController<ObjectCo
	@ResponseBody
	public SuperDTO findClassification(@Valid @RequestBody DataQueryDTO queryDTO, BindingResult bindingResult) {

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		AggsPropertiesDTO agg = new AggsPropertiesDTO();
		agg.setField("classification");
		queryDTO.addAgg(agg);
		queryDTO.setSize(0);

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		return service.findClassificationStatistics(queryDTO);
	}

@@ -87,15 +87,14 @@ public class ObjectCollectingSeriesController extends RSeriesController<ObjectCo
	@ResponseBody
	public SuperDTO findTemporalData(@Valid @RequestBody DataQueryDTO queryDTO, BindingResult bindingResult) {

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		AggsPropertiesDTO agg = new AggsPropertiesDTO();
		agg.setField("temporaldata");
		queryDTO.addAgg(agg);

		queryDTO.setSize(0);

		if (bindingResult != null && bindingResult.hasErrors())
			throw new DTONotValidException(bindingResult);

		return service.findTemporalDataStatistics(queryDTO);
	}

+10 −3
Original line number Diff line number Diff line
@@ -58,22 +58,26 @@ public class ObjectCollectingSeriesESService
		this.repository = repository;
	}

	@SuppressWarnings("unchecked")
	public ElasticSearchDTO findClassificationList(DataQueryDTO query) {

		SeriesSearchWrapper<ObjectCollectingSeries> response = repository.find(query);

		if (response == null || response.getAggregations() == null)
			return new ElasticSearchDTO(null, 0);

		ClassificationsForListDTO dtoOut = Mappers.getMapper(ObjectCollectingSeriesESMapper.class)
			.convertToList(response.getAggregations());

		return new ElasticSearchDTO(dtoOut.getClassification(), dtoOut.getClassification().size());
	}

	@SuppressWarnings("unchecked")
	public ElasticSearchDTO findClassificationStatistics(DataQueryDTO query) {

		SeriesSearchWrapper<ObjectCollectingSeries> response = repository.find(query);

		if (response == null || response.getAggregations() == null)
			return new ElasticSearchDTO(null, 0);

		ClassificationsForPieChartDTO dtoOut = Mappers.getMapper(ObjectCollectingSeriesESMapper.class)
			.convertToPieChart(response.getAggregations());

@@ -85,9 +89,12 @@ public class ObjectCollectingSeriesESService

		SeriesSearchWrapper<ObjectCollectingSeries> response = repository.find(query);

		DataHistogramDTO dtoOut = Mappers.getMapper(DataHistogramESMapper.class).map(response.getAggregations());
		if (response == null || response.getAggregations() == null)
			return new ElasticSearchDTO(null, 0);

		DataHistogramDTO dtoOut = Mappers.getMapper(DataHistogramESMapper.class).map(response.getAggregations());
		dtoOut.setDataDefinitionIds((List<Integer>) query.getTerms().get("dataDefinition"));

		return new ElasticSearchDTO(dtoOut, dtoOut.getData().size());
	}