1 package net.sumaris.server.http.rest;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.google.common.collect.ImmutableList;
26 import io.leangen.graphql.annotations.GraphQLArgument;
27 import io.leangen.graphql.annotations.GraphQLContext;
28 import io.leangen.graphql.annotations.GraphQLQuery;
29 import net.sumaris.core.dao.referential.location.Locations;
30 import net.sumaris.core.extraction.dao.trip.rdb.AggregationRdbTripDao;
31 import net.sumaris.core.extraction.service.AggregationService;
32 import net.sumaris.core.extraction.service.ExtractionService;
33 import net.sumaris.core.extraction.vo.*;
34 import net.sumaris.server.http.geojson.GeoJsonGeometries;
35 import net.sumaris.server.http.geojson.extraction.GeoJsonExtractions;
36 import org.apache.commons.lang3.StringUtils;
37 import org.geojson.*;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.http.MediaType;
40 import org.springframework.stereotype.Controller;
41 import org.springframework.stereotype.Service;
42 import org.springframework.transaction.annotation.Transactional;
43 import org.springframework.web.bind.annotation.*;
44
45 import javax.websocket.server.PathParam;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49 import java.util.stream.Collectors;
50
51 @RestController
52 public class AggregationRestService {
53
54 @Autowired
55 private AggregationService aggregationService;
56
57 @ResponseBody
58 @RequestMapping(value = "aggregation/{type}/{space}/geojson", method = RequestMethod.GET,
59 produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
60 public FeatureCollection getGeoAggregation(@PathVariable(name = "type") String typeLabel,
61 @PathVariable(name = "space") String spaceStrata,
62 @PathParam(value = "offset") Integer offsetParam,
63 @PathParam(value = "size") Integer sizeParam,
64 @PathParam(value = "time") String timeStrata,
65 @PathParam(value = "agg") String aggStrata,
66 @PathParam(value = "q") String filterQuery) {
67
68 AggregationTypeVOregationTypeVO.html#AggregationTypeVO">AggregationTypeVO type = new AggregationTypeVO();
69 type.setLabel(typeLabel);
70
71 ExtractionFilterVO filter = null;
72
73
74 int offset = offsetParam != null ? offsetParam.intValue() : 0;
75 int size = sizeParam != null ? sizeParam.intValue() : 100;
76
77 if (size > 1000) size = 1000;
78
79 AggregationStrataVOtionStrataVO.html#AggregationStrataVO">AggregationStrataVO strata = new AggregationStrataVO();
80 strata.setTimeColumnName(StringUtils.isNotBlank(timeStrata) ? timeStrata : AggregationRdbTripDao.COLUMN_YEAR);
81 strata.setSpaceColumnName(StringUtils.isNotBlank(spaceStrata) ? spaceStrata : AggregationRdbTripDao.COLUMN_SQUARE);
82 strata.setAggColumnName(StringUtils.isNotBlank(aggStrata) ? aggStrata : AggregationRdbTripDao.COLUMN_STATION_COUNT);
83 strata.setTechColumnName(null);
84
85 return GeoJsonExtractions.toFeatureCollection(aggregationService.read(
86 type,
87 filter,
88 strata,
89 offset, size,
90 null, null),
91 strata.getSpaceColumnName());
92 }
93
94
95 }