First commit

This commit is contained in:
Manos 2015-11-08 02:22:14 +02:00
parent 099185796f
commit f22cdf2321
5 changed files with 432 additions and 0 deletions

86
pom.xml Normal file
View File

@ -0,0 +1,86 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.emkatsom</groupId>
<artifactId>EasyHarvestLog</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>EasyHarvestLog</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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";
/**/
}

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/LogCat"/>

35
src/main/webapp/index.jsp Normal file
View File

@ -0,0 +1,35 @@
<%@page import="com.emkatsom.logcat.*"%>
<%@page language="java" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LogCat</title>
</head>
<body>
<h1>LogCat</h1>
<h2></h2>
<form action="./view.jsp">
.../tasks/
<input name="id" required="required" type="text" placeholder="id"/>
/getdata
<select name="type">
<option value="<%=Globals.raw_data%>" selected><%=Globals.raw_data%></option>
<option value="<%=Globals.orientation_data%>"><%=Globals.orientation_data%></option>
<option value="<%=Globals.location_data%>"><%=Globals.location_data%></option>
</select>
<!--
<br>
<input name="download" type="checkbox"><label>Download</label>
<br>
<input name="delete" type="checkbox"><label>Delete</label>
<br>
<br>
-->
<input type="submit" value="OK">
</form>
</body>
</html>

285
src/main/webapp/view.jsp Normal file
View File

@ -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"%>
<!DOCTYPE html>
<html>
<head>
<style>
*{ padding: 0px; margin: 0px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
body, html { height: 100%; width: 100%; }
ol {
padding: 10px 100px 10px 35px;
}
#data {
}
#map {
width: 100%;
height: 100%;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<%
String TAG = "LogCat: ";
String id = request.getParameter("id");
String download = request.getParameter("download");
String delete = request.getParameter("delete");
String type = request.getParameter("type");
%>
<title>View - <%=id%> - LogCat</title>
<script type="text/javascript">
$(document).ready(function () {
refresh();
});
function refresh() {
setTimeout(function () {
var id = getRequestParameter('id');
var type = getRequestParameter('type');
try {
$('#content').load('view.jsp?id=' + id + '&type=' + type + ' #content', update());
// alert(id + " and " + type);
}
catch (err) {
$('#content').load('view.jsp?id=' + id + '&type=' + type + ' #content');
}
refresh();
}, 3000);
}
function getRequestParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
</script>
</head>
<body>
<!--
<form id="form" action="./index.jsp">
<input type="submit" value="BACK">
</form>
-->
<div id="content">
<%
String html = "";
String dataUrl = Globals.server_url + "/" + id + "/getdata";
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = null;
List<Object> data = new ArrayList<Object>();
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 = "<ol>" + "Oops!" + "" + "</ol>";
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<Object>) ois.readObject();
ois.close();
in.close();
// new File(Globals.db_path + "/" + id + ".dat").delete();
} catch (Exception e) {
System.out.println(TAG + e.getMessage());
// html = "<ol>" + "Empty." + "" + "</ol>";
out.println(html);
}
if (Globals.raw_data.equals(type)) {
html = "<ol>";
for (Object o : data) {
Map m = (Map) o;
html += "<li>"
+ new Date((Long) m.get("timestamp") / 1000000L).toString() + ""
+ " task[" + m.get("task") + "]"
+ "@" + m.get("device") + ":"
+ " " + m.get("sensor") + ""
+ "" + Arrays.toString((double[]) m.get("values")) + ""
+ "</li>";
}
if (data.isEmpty()) {
html += "Empty.";
}
html += "</ol>";
out.println(html);
} else if (Globals.orientation_data.equals(type)) {
html = "<ol>";
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 += "<li>"
//+ 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 += "</li>";
}
if (data.isEmpty()) {
html += "Empty.";
}
html += "</ol>";
out.println(html);
} else if (Globals.location_data.equals(type)) {
List<Object[]> list = new ArrayList<Object[]>();
for (Object o : data) {
Map m = (Map) o;
double[] loc = (double[]) m.get("values");
Object[] info = {
"<div style=\"text-align: center;\";>"
+ new Date(Long.valueOf(m.get("timestamp").toString()) / 1000000L).toString() + "<br>"
+ " task[" + m.get("task") + "]" + "@" + m.get("device") + "<br>"
+ "" + Arrays.toString((double[]) m.get("values"))
+ "</div>",
loc[0],
loc[1]
};
list.add(info);
}
Gson gson = new Gson();
out.print("<div id=\"data\" hidden>" + gson.toJson(list) + "</div>");
%>
</div>
<div id="map"></div>
<script type="text/javascript">
var map;
init();
var infowindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var loc_len = 0;
update();
function update() {
var data = document.getElementById('data').innerHTML;
var locations = JSON.parse(data);
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
latlngbounds.extend(marker.position);
}
if (loc_len !== locations.length) {
map.fitBounds(latlngbounds);
loc_len = locations.length;
if (loc_len === 0) {
init();
}
}
}
function init() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: 0, lng: 0}
});
}
</script>
<%
}
if ("off".equals(download)
&& "off".equals(delete)) {
} else if ("on".equals(download)
&& "off".equals(delete)) {
} else if ("on".equals(download)
&& "on".equals(delete)) {
} else {
}
%>
</body>
</html>