-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortalDBService.java
52 lines (40 loc) · 1.97 KB
/
PortalDBService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.dronerecon.ws;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class PortalDBService extends HttpServlet{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json;charset=utf-8");
response.addHeader("Access-Control-Allow-Origin", "*");
PrintWriter out = response.getWriter();
// ############
// Get 5 parameter values from the request object (these are passed in from part 1 code).
// "area_id" : String type
// "tilex" : int type (Reference part 1 of Project 2 for converting string to int).
// "tiley"
// "r"
// "g"
// ############
String area_id = request.getParameter("area_id");
int tilex = Integer.parseInt(request.getParameter("tilex"));
int tiley = Integer.parseInt(request.getParameter("tiley"));
int r = Integer.parseInt(request.getParameter("r"));
int g = Integer.parseInt(request.getParameter("g"));
// ############
// Instantiate a DBManager instance.
// ############
DBManager oDBManager = new DBManager();
// Set DB location (Currently uses current DB file name and adds direct path from C drive before it).
oDBManager.DBLocation = System.getProperty("catalina.base") + "\\webapps\\dronereconportal\\db\\" + oDBManager.DBLocation;
//*** IMPORTANT: For Mac Users, comment out the above and use below line:
//oDBManager.DBLocation = System.getProperty("catalina.base") + "/webapps/dronereconportal/db/" + oDBManager.DBLocation;
// ############
// Call insertAreaGridTile on db manager object and pass the 5 values from above.
// ############
oDBManager.insertAreaGridTile(area_id, tilex, tiley, r, g);
// Response with confirmation of DB record written.
out.println("{\"success\":true}");
}
}