View Javadoc
1   package net.sumaris.server.http.rest;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Server
6    * %%
7    * Copyright (C) 2018 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
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          // TODO parse filter from filterQuery
73  
74          int offset = offsetParam != null ? offsetParam.intValue() : 0;
75          int size = sizeParam != null ? sizeParam.intValue() : 100;
76          // Limit to 1000 rows
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  }