ClimateDataController.java
/*
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys.server.api.v1;
import org.genesys.server.api.ApiBaseController;
import org.genesys.server.exception.NotFoundElement;
import org.genesys.server.model.impl.TileClimate;
import org.genesys.server.service.ClimateDataService;
import org.genesys.worldclim.WorldClimUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
@RestController("climateApi1")
@PreAuthorize("isAuthenticated()")
@RequestMapping(ClimateDataController.CONTROLLER_URL)
@Api(tags = { "climate" })
public class ClimateDataController extends ApiBaseController {
/** The Constant CONTROLLER_URL. */
public static final String CONTROLLER_URL = ApiBaseController.APIv1_BASE + "/climate";
@Autowired
private ClimateDataService climateDataService;
@GetMapping("/current/{latitude},{longitude}")
public TileClimate getCurrentClimate(@PathVariable("latitude") double latitude, @PathVariable("longitude") double longitude) {
Long tileIndex = WorldClimUtil.getWorldclim25Tile(longitude, latitude);
if (tileIndex == null) {
throw new NotFoundElement("No current climate data for specified (lat, lon)");
}
return climateDataService.climateForTile(tileIndex);
}
@GetMapping("/past/{latitude},{longitude}")
public TileClimate getPastClimate(@PathVariable("latitude") double latitude, @PathVariable("longitude") double longitude) {
throw new NotFoundElement("Past climate data not available");
}
@GetMapping("/future/{latitude},{longitude}")
public TileClimate getFutureClimate(@PathVariable("latitude") double latitude, @PathVariable("longitude") double longitude) {
throw new NotFoundElement("Future climate data not available");
}
}