/alaspatial/src/main/java/org/ala/spatial/web/services/ALOCWSController.java

http://alageospatialportal.googlecode.com/ · Java · 121 lines · 85 code · 17 blank · 19 comment · 12 complexity · ef47f1140f8b21f63059c517187c8439 MD5 · raw file

  1. /**
  2. * ************************************************************************
  3. * Copyright (C) 2010 Atlas of Living Australia All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with the
  7. * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  11. * the specific language governing rights and limitations under the License.
  12. * *************************************************************************
  13. */
  14. package org.ala.spatial.web.services;
  15. import javax.servlet.http.HttpServletRequest;
  16. import org.ala.layers.intersect.SimpleRegion;
  17. import org.ala.layers.intersect.SimpleShapeFile;
  18. import org.ala.spatial.analysis.index.LayerFilter;
  19. import org.ala.spatial.util.AlaspatialProperties;
  20. import org.ala.spatial.util.AnalysisJobAloc;
  21. import org.ala.spatial.util.AnalysisQueue;
  22. import org.springframework.stereotype.Controller;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RequestMethod;
  25. import org.springframework.web.bind.annotation.ResponseBody;
  26. /**
  27. * ALOC webservices.
  28. *
  29. * @author ajay
  30. */
  31. @Controller
  32. public class ALOCWSController {
  33. @RequestMapping(value = "/ws/aloc", method = RequestMethod.POST)
  34. public @ResponseBody
  35. String aloc(HttpServletRequest req) {
  36. String pid = "";
  37. try {
  38. long currTime = System.currentTimeMillis();
  39. String currentPath = AlaspatialProperties.getBaseOutputDir();
  40. String groupCount = req.getParameter("gc");
  41. String area = req.getParameter("area");
  42. String resolution = req.getParameter("res");
  43. if (resolution == null) {
  44. resolution = "0.01";
  45. }
  46. LayerFilter[] filter = null;
  47. SimpleRegion region = null;
  48. if (area != null && area.startsWith("ENVELOPE")) {
  49. filter = LayerFilter.parseLayerFilters(area);
  50. } else {
  51. region = SimpleShapeFile.parseWKT(req.getParameter("area"));
  52. }
  53. pid = Long.toString(currTime);
  54. AnalysisJobAloc aja = new AnalysisJobAloc(pid, currentPath, req.getParameter("envlist"), Integer.parseInt(groupCount), region, filter, area, resolution);
  55. StringBuffer inputs = new StringBuffer();
  56. inputs.append("pid:").append(pid);
  57. inputs.append(";gc:").append(groupCount);
  58. inputs.append(";area:").append(area);
  59. inputs.append(";envlist:").append(req.getParameter("envlist"));
  60. inputs.append(";resolution:").append(resolution);
  61. aja.setInputs(inputs.toString());
  62. AnalysisQueue.addJob(aja);
  63. } catch (Exception e) {
  64. e.printStackTrace(System.out);
  65. }
  66. return pid;
  67. }
  68. @RequestMapping(value = "/ws/aloc/estimate", method = {RequestMethod.POST, RequestMethod.GET})
  69. public @ResponseBody
  70. String alocEstimate(HttpServletRequest req) {
  71. String pid = "";
  72. try {
  73. long currTime = System.currentTimeMillis();
  74. String currentPath = AlaspatialProperties.getBaseOutputDir();
  75. String groupCount = req.getParameter("gc");
  76. String area = req.getParameter("area");
  77. String resolution = req.getParameter("res");
  78. if (resolution == null) {
  79. resolution = "0.01";
  80. }
  81. LayerFilter[] filter = null;
  82. SimpleRegion region = null;
  83. if (area != null && area.startsWith("ENVELOPE")) {
  84. filter = LayerFilter.parseLayerFilters(area);
  85. } else {
  86. region = SimpleShapeFile.parseWKT(req.getParameter("area"));
  87. }
  88. pid = Long.toString(currTime);
  89. AnalysisJobAloc aja = new AnalysisJobAloc(pid, currentPath, req.getParameter("envlist"), Integer.parseInt(groupCount), region, filter, area, resolution);
  90. StringBuffer inputs = new StringBuffer();
  91. inputs.append("pid:").append(pid);
  92. inputs.append(";gc:").append(groupCount);
  93. inputs.append(";area:").append(area);
  94. inputs.append(";envlist:").append(req.getParameter("envlist"));
  95. inputs.append(";resolution:").append(resolution);
  96. aja.setInputs(inputs.toString());
  97. //AnalysisQueue.addJob(aja);
  98. return String.valueOf(aja.getEstimate());
  99. } catch (Exception e) {
  100. e.printStackTrace(System.out);
  101. }
  102. return "";
  103. }
  104. }