Newer
Older
task-bldg / src / main / java / osm / surveyor / task / plateau / PlateauService.java
@haya4 haya4 on 28 Apr 1 KB Plateau API test
  1. package osm.surveyor.task.plateau;
  2.  
  3. import java.nio.file.Files;
  4. import java.nio.file.Path;
  5.  
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.stereotype.Service;
  8.  
  9. @Service
  10. public class PlateauService {
  11.  
  12. @Value("${task-bldg.plateau.dir}")
  13. private String dir; // task-bldg.plateau.dir=plateau-data
  14. public Boolean getPlateauStatus() throws Exception {
  15. try {
  16. Path base = Path.of(dir);
  17. if (Files.exists(base)) {
  18. return Boolean.valueOf(true);
  19. }
  20. else {
  21. return Boolean.valueOf(false);
  22. }
  23. }
  24. catch (Exception e) {
  25. return Boolean.valueOf(false);
  26. }
  27. }
  28.  
  29. public String getPlateau(String citycode) {
  30. try {
  31. Path base = Path.of(dir);
  32. if (Files.exists(base)) {
  33. Files.createDirectory(base);
  34. }
  35. Path city = Path.of(dir, citycode);
  36. if (Files.exists(city)) {
  37. Files.createDirectory(city);
  38. }
  39. return "OK";
  40. }
  41. catch (Exception e) {
  42. return e.toString();
  43. }
  44.  
  45. /*
  46. Path path = Path.of(dir.toString(), fileName);
  47. PathResource resource = new PathResource(path);
  48. try {
  49. RestTemplate restTemplate = new RestTemplate();
  50. System.out.println(String.format("INFO: httpGet(%s)", url));
  51. ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
  52. HttpStatus httpStatus = response.getStatusCode();
  53. if (httpStatus.isError()) {
  54. System.out.println("ERROE: Can not access '"+ url +"'");
  55. throw new Exception("ERROE: Can not access '"+ url +"'");
  56. }
  57. String body = response.getBody();
  58. return body;
  59. }
  60. catch (Exception e) {
  61. return e.toString();
  62. }
  63. */
  64. }
  65. }