PageRenderTime 59ms CodeModel.GetById 48ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://alageospatialportal.googlecode.com/
Java | 69 lines | 52 code | 12 blank | 5 comment | 4 complexity | 8d57399b58b10ada9577e55105dbf04d MD5 | raw file
 1package org.ala.spatial.web.services;
 2
 3import java.net.URLDecoder;
 4import javax.servlet.http.HttpServletRequest;
 5import org.ala.spatial.analysis.service.LoadedPoints;
 6import org.ala.spatial.analysis.service.LoadedPointsService;
 7import org.springframework.stereotype.Controller;
 8import org.springframework.web.bind.annotation.RequestMapping;
 9import org.springframework.web.bind.annotation.RequestMethod;
10import org.springframework.web.bind.annotation.ResponseBody;
11
12/**
13 *
14 * @author adam
15 */
16@Controller
17@RequestMapping("/ws/points/")
18public class PointsWSController {
19
20    @RequestMapping(value = "/register", method = RequestMethod.POST)
21    public
22    @ResponseBody
23    String register(HttpServletRequest req) {
24
25        try {
26
27            String[] pointsString = req.getParameter("points").split("\n");
28            String idss = req.getParameter("ids");
29            String[] ids = null;
30            if (idss != null) {
31                ids = idss.split("\n");
32            }
33            String name = URLDecoder.decode(req.getParameter("name"), "UTF-8");
34
35            double[][] points = new double[pointsString.length][2];
36            String[] line;
37            int count = 0;
38            for (int i = 0; i < pointsString.length; i++) {
39                line = pointsString[i].split(",");
40                try {
41                    points[count][0] = Double.parseDouble(line[0]);
42                    points[count][1] = Double.parseDouble(line[1]);
43                    count++;
44                } catch (Exception e) {
45                }
46            }
47
48            //resize
49            double[][] pointsTrimmed = new double[count][2];
50            for (int i = 0; i < count; i++) {
51                pointsTrimmed[i][0] = points[i][0];
52                pointsTrimmed[i][1] = points[i][1];
53            }
54            points = pointsTrimmed;
55
56            String id = String.valueOf(System.currentTimeMillis());
57
58            LoadedPointsService.addCluster(id, new LoadedPoints(points, name, ids));
59
60            return id;
61
62        } catch (Exception e) {
63            System.out.println("Error processing Sampling request:");
64            e.printStackTrace(System.out);
65        }
66
67        return "";
68    }
69}