diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ba0749c --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + 4.0.0 + + com.emkatsom + EasyHarvestLog + 1.0-SNAPSHOT + war + + EasyHarvestLog + + + ${project.build.directory}/endorsed + UTF-8 + + + + + org.apache.httpcomponents + httpclient + 4.2.5 + + + com.google.code.gson + gson + 2.3.1 + + + javax + javaee-web-api + 7.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + ${endorsed.dir} + + + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + false + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.1 + + + validate + + copy + + + ${endorsed.dir} + true + + + javax + javaee-endorsed-api + 6.0 + jar + + + + + + + + + + diff --git a/src/main/java/com/emkatsom/logcat/Globals.java b/src/main/java/com/emkatsom/logcat/Globals.java new file mode 100644 index 0000000..b3a8587 --- /dev/null +++ b/src/main/java/com/emkatsom/logcat/Globals.java @@ -0,0 +1,24 @@ +package com.emkatsom.logcat; + +public class Globals { + + public static String raw_data = "raw"; + public static String orientation_data = "orientation"; + public static String location_data = "location"; + + /* + * PC + */ + /* + public static String server_url = "http://localhost:8084/Server/webresources/tasks"; + public static String db_path = "C:/EasyHarvestLog"; + /**/ + + /* + * HOST + */ + /**/ + public static String server_url = "http://83.212.109.118:8080/Server/webresources/tasks"; + public static String db_path = "/var/lib/tomcat6/webapps/db"; + /**/ +} diff --git a/src/main/webapp/META-INF/context.xml b/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000..80520ae --- /dev/null +++ b/src/main/webapp/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..906a585 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,35 @@ +<%@page import="com.emkatsom.logcat.*"%> +<%@page language="java" %> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + LogCat + + +

LogCat

+

+
+ .../tasks/ + + /getdata + + + +
+ + diff --git a/src/main/webapp/view.jsp b/src/main/webapp/view.jsp new file mode 100644 index 0000000..1d65826 --- /dev/null +++ b/src/main/webapp/view.jsp @@ -0,0 +1,285 @@ +<%@page import="com.emkatsom.logcat.*"%> + +<%@page import="java.io.*"%> +<%@page import="java.util.*"%> + +<%@page import="com.google.gson.*"%> + +<%@page import="org.apache.http.client.methods.HttpGet"%> +<%@page import="org.apache.http.client.HttpClient"%> +<%@page import="org.apache.http.HttpResponse"%> +<%@page import="org.apache.http.impl.client.DefaultHttpClient"%> + +<%@page language="java" %> + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + + <% + String TAG = "LogCat: "; + + String id = request.getParameter("id"); + String download = request.getParameter("download"); + String delete = request.getParameter("delete"); + String type = request.getParameter("type"); + %> + View - <%=id%> - LogCat + + + + + + +
+ <% + String html = ""; + String dataUrl = Globals.server_url + "/" + id + "/getdata"; + + HttpClient httpClient = new DefaultHttpClient(); + HttpResponse httpResponse = null; + + List data = new ArrayList(); + + InputStream in = null; + try { + HttpGet httpGet = new HttpGet(dataUrl); + httpResponse = httpClient.execute(httpGet); + in = httpResponse.getEntity().getContent(); + } catch (Exception e) { + System.out.println(TAG + e.getMessage()); + html = "
    " + "Oops!" + "" + "
"; + out.println(html); + } + + /**/ +// FileOutputStream outputStream = new FileOutputStream(new File(Globals.db_path + "/" + id + ".dat")); +// int read = 0; +// byte[] bytes = new byte[1024]; +// while ((read = in.read(bytes)) != -1) { +// outputStream.write(bytes, 0, read); +// } +// outputStream.close(); + /**/ + + ObjectInputStream ois; + + try { +// ois = new ObjectInputStream(new FileInputStream(Globals.db_path + "/" + id + ".dat")); + + ois = new ObjectInputStream(in); + data = (List) ois.readObject(); + + ois.close(); + in.close(); + +// new File(Globals.db_path + "/" + id + ".dat").delete(); + + } catch (Exception e) { + System.out.println(TAG + e.getMessage()); +// html = "
    " + "Empty." + "" + "
"; + out.println(html); + } + + if (Globals.raw_data.equals(type)) { + html = "
    "; + for (Object o : data) { + Map m = (Map) o; + + html += "
  1. " + + new Date((Long) m.get("timestamp") / 1000000L).toString() + "" + + " task[" + m.get("task") + "]" + + "@" + m.get("device") + ":" + + " " + m.get("sensor") + "" + + "" + Arrays.toString((double[]) m.get("values")) + "" + + "
  2. "; + } + if (data.isEmpty()) { + html += "Empty."; + } + html += "
"; + out.println(html); + } else if (Globals.orientation_data.equals(type)) { + html = "
    "; + for (Object o : data) { + Map m = (Map) o; + + double[] values = (double[]) m.get("values"); + double x = values[0]; + double y = values[1]; + double z = values[2]; + + html += "
  1. " + //+ m.get("timestamp") + "" + + new Date(Long.valueOf(m.get("timestamp").toString()) / 1000000L).toString() + "" + + " task[" + m.get("task") + "]" + + "@" + m.get("device") + ":"; + + if (x > 9 && y > 0 && y < 1 && z > 0 && z < 1) { + html += " LEFT"; + } else if (x < -9 && y > 0 && y < 1 && z > 0 && z < 1) { + html += " RIGHT"; + } else if (z > 9.5) { + html += " UP"; + } else if (z < -9.5) { + html += " DOWN"; + } + + html += "
  2. "; + } + if (data.isEmpty()) { + html += "Empty."; + } + html += "
"; + out.println(html); + } else if (Globals.location_data.equals(type)) { + List list = new ArrayList(); + + for (Object o : data) { + Map m = (Map) o; + + double[] loc = (double[]) m.get("values"); + Object[] info = { + "
" + + new Date(Long.valueOf(m.get("timestamp").toString()) / 1000000L).toString() + "
" + + " task[" + m.get("task") + "]" + "@" + m.get("device") + "
" + + "" + Arrays.toString((double[]) m.get("values")) + + "
", + loc[0], + loc[1] + }; + + list.add(info); + + } + + Gson gson = new Gson(); + + out.print(""); + %> + + +
+ + + + <% + } + + if ("off".equals(download) + && "off".equals(delete)) { + } else if ("on".equals(download) + && "off".equals(delete)) { + } else if ("on".equals(download) + && "on".equals(delete)) { + } else { + } + %> + + +