/alaspatial/src/main/java/org/ala/spatial/web/services/ALOCWSController.java
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 */ 14package org.ala.spatial.web.services; 15 16import javax.servlet.http.HttpServletRequest; 17import org.ala.layers.intersect.SimpleRegion; 18import org.ala.layers.intersect.SimpleShapeFile; 19import org.ala.spatial.analysis.index.LayerFilter; 20import org.ala.spatial.util.AlaspatialProperties; 21import org.ala.spatial.util.AnalysisJobAloc; 22import org.ala.spatial.util.AnalysisQueue; 23import org.springframework.stereotype.Controller; 24import org.springframework.web.bind.annotation.RequestMapping; 25import org.springframework.web.bind.annotation.RequestMethod; 26import org.springframework.web.bind.annotation.ResponseBody; 27 28/** 29 * ALOC webservices. 30 * 31 * @author ajay 32 */ 33@Controller 34public class ALOCWSController { 35 36 @RequestMapping(value = "/ws/aloc", method = RequestMethod.POST) 37 public @ResponseBody 38 String aloc(HttpServletRequest req) { 39 String pid = ""; 40 try { 41 42 long currTime = System.currentTimeMillis(); 43 44 String currentPath = AlaspatialProperties.getBaseOutputDir(); 45 String groupCount = req.getParameter("gc"); 46 String area = req.getParameter("area"); 47 48 String resolution = req.getParameter("res"); 49 if (resolution == null) { 50 resolution = "0.01"; 51 } 52 53 LayerFilter[] filter = null; 54 SimpleRegion region = null; 55 if (area != null && area.startsWith("ENVELOPE")) { 56 filter = LayerFilter.parseLayerFilters(area); 57 } else { 58 region = SimpleShapeFile.parseWKT(req.getParameter("area")); 59 } 60 61 pid = Long.toString(currTime); 62 AnalysisJobAloc aja = new AnalysisJobAloc(pid, currentPath, req.getParameter("envlist"), Integer.parseInt(groupCount), region, filter, area, resolution); 63 StringBuffer inputs = new StringBuffer(); 64 inputs.append("pid:").append(pid); 65 inputs.append(";gc:").append(groupCount); 66 inputs.append(";area:").append(area); 67 inputs.append(";envlist:").append(req.getParameter("envlist")); 68 inputs.append(";resolution:").append(resolution); 69 aja.setInputs(inputs.toString()); 70 AnalysisQueue.addJob(aja); 71 72 } catch (Exception e) { 73 e.printStackTrace(System.out); 74 } 75 return pid; 76 } 77 78 @RequestMapping(value = "/ws/aloc/estimate", method = {RequestMethod.POST, RequestMethod.GET}) 79 public @ResponseBody 80 String alocEstimate(HttpServletRequest req) { 81 String pid = ""; 82 try { 83 84 long currTime = System.currentTimeMillis(); 85 86 String currentPath = AlaspatialProperties.getBaseOutputDir(); 87 String groupCount = req.getParameter("gc"); 88 String area = req.getParameter("area"); 89 90 String resolution = req.getParameter("res"); 91 if (resolution == null) { 92 resolution = "0.01"; 93 } 94 95 LayerFilter[] filter = null; 96 SimpleRegion region = null; 97 if (area != null && area.startsWith("ENVELOPE")) { 98 filter = LayerFilter.parseLayerFilters(area); 99 } else { 100 region = SimpleShapeFile.parseWKT(req.getParameter("area")); 101 } 102 103 pid = Long.toString(currTime); 104 AnalysisJobAloc aja = new AnalysisJobAloc(pid, currentPath, req.getParameter("envlist"), Integer.parseInt(groupCount), region, filter, area, resolution); 105 StringBuffer inputs = new StringBuffer(); 106 inputs.append("pid:").append(pid); 107 inputs.append(";gc:").append(groupCount); 108 inputs.append(";area:").append(area); 109 inputs.append(";envlist:").append(req.getParameter("envlist")); 110 inputs.append(";resolution:").append(resolution); 111 aja.setInputs(inputs.toString()); 112 //AnalysisQueue.addJob(aja); 113 114 return String.valueOf(aja.getEstimate()); 115 116 } catch (Exception e) { 117 e.printStackTrace(System.out); 118 } 119 return ""; 120 } 121}