Skip to content

Commit

Permalink
fix the issue #1 for milestone0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lu Han committed Jan 7, 2014
1 parent fc31519 commit b949a04
Show file tree
Hide file tree
Showing 23 changed files with 274 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public AtupDevice createDevice(@Context final HttpHeaders headers, final AtupDev
@Consumes(MediaType.APPLICATION_JSON)
public AtupDevice updateDevice(@Context final HttpHeaders headers, final AtupDevice deviceInfo) {
try {
fillUser(headers, deviceInfo);
if (deviceInfo.getUser() == null) {
fillUser(headers, deviceInfo);
}
final AtupDevice atupDevice = service.updateDevice(deviceInfo);
return atupDevice;
} catch (final Exception e) {
Expand All @@ -69,6 +71,15 @@ public AtupDeviceListInfo getDevicesByUser(@Context final HttpHeaders headers) {
return result;
}

@GET
@Path("all")
@Produces(MediaType.APPLICATION_JSON)
public AtupDeviceListInfo getDevices() {
final List<AtupDevice> devices = service.getDeviceList();
final AtupDeviceListInfo result = new AtupDeviceListInfo(devices);
return result;
}

@POST
@Path("detect")
public void detect() throws ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public AtupDevice updateDevice(final AtupDevice device) {
public List<AtupDevice> getDeviceList(final Integer userId) {
return dao.findDevicesByUser(userId);
}

public List<AtupDevice> getDeviceList() {
return dao.findAll();
}
}
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/cases/testCase.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Test Case Page</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/cases/testCase.js"></script>
<script type="text/javascript">
Expand Down
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/cases/testCases.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Test Case List</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/cases/testCases.js"></script>
<script type="text/javascript">
Expand Down
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/cases/testResult.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Test Result Page</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/results/result.js"></script>
<script type="text/javascript">
Expand Down
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/cases/testResults.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Test Result List</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/results/testResults.js"></script>
<script type="text/javascript">
Expand Down
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/cases/testSuite.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Test Suite Page</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/cases/testSuite.js"></script>
<script type="text/javascript">
Expand Down
4 changes: 1 addition & 3 deletions atup-page/src/main/webapp/cases/testSuites.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="text/html;charset=utf-8">
<title>Test Suite List</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/cases/testSuites.js"></script>
<script type="text/javascript">
Expand Down
5 changes: 3 additions & 2 deletions atup-page/src/main/webapp/devices/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<html>
<head>
<title>Device Page</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/devices/device.js"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
checkSignIn();
initial();
});
</script>
</head>
Expand Down Expand Up @@ -37,6 +37,7 @@ <h5>Update Device</h5>
<input type="text" id="deviceType" name="deviceType" value=""/></div>
<div><span style='width:130px;display:inline-block;'>Device Status:</span>
<input type="text" id="deviceStatus" name="deviceStatus" value=""/></div>
<div><span style='width:130px;display:inline-block;'>User:</span><select id="userList"></select></div>
<div>
<input id="updateButton" type="button" value="Update" onclick="updateDevice();"/>
</div>
Expand Down
8 changes: 4 additions & 4 deletions atup-page/src/main/webapp/devices/devices.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<html>
<head>
<title>Device List</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/devices/devices.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
loadDevices();
});
jQuery(document).ready(function () {
loadDevices();
});
</script>
</head>
<body>
Expand Down
1 change: 0 additions & 1 deletion atup-page/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<script src="webjars/jquery/2.0.3/jquery.js"></script>
<script src="js/atupConstant.js"></script>
<script src="js/atupRest.js"></script>
<script src="js/index.js"></script>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion atup-page/src/main/webapp/jobs/jobsQueue.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<title>Test Job Page</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/jobs/testJob.js"></script>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion atup-page/src/main/webapp/jobs/runningJobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<html>
<head>
<title>Device List</title>
<meta content="text/html;charset=utf-8">
<script src="../webjars/jquery/2.0.3/jquery.js"></script>
<script src="../js/atupConstant.js"></script>
<script src="../js/atupRest.js"></script>
<script src="../js/jobs/testJobs.js"></script>
<script type="text/javascript">
Expand Down
32 changes: 0 additions & 32 deletions atup-page/src/main/webapp/js/atupConstant.js

This file was deleted.

140 changes: 43 additions & 97 deletions atup-page/src/main/webapp/js/atupRest.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
var storage = window.sessionStorage;

var HOST = "http://localhost:8080/";
var ATUP_CASE_BASE_URI = 'atup-case/rest-api';
var ATUP_DEVICE_BASE_URI = 'atup-device/rest-api';
var ATUP_USER_BASE_URI = 'atup-user/rest-api';
var ATUP_PAGE_BASE_URI = 'atup-page/';

var TEST_SUITE_PATH = "/testsuites";
var TEST_CASE_PATH = "/testcases";
var TEST_RESULT_PATH = "/testresults";
var TEST_JOB_PATH = "/testjobs";

var USER_PATH = "/users";
var DEVICE_PATH = "/devices";
var SIGNIN_PATH = "/users/signin";

var NO_RESULT = "There's no result from the server";

var GET_METHOD = 'GET';
var POST_METHOD = 'POST';
var PUT_METHOD = 'PUT';
var DELETE_METHOD = 'DELETE';

var SPAN_BEGIN = "<span style='width:100px;display:inline-block;'>";
var SPAN_BEGIN1 = "<span style='width:150px;display:inline-block;'>";
var SPAN_BEGIN2 = "<span style='width:200px;display:inline-block;'>";

var ROLE_ADMIN = 1;
var ROLE_JOB_KILLER = 2;
var ROLE_DEVICE_MANAGER = 3;
var ROLE_USER = 4;

function rest(restUrl, httpMethod, param, callback) {
rest0(restUrl, httpMethod, param, "application/json", "json", callback)
}
Expand All @@ -13,7 +46,7 @@ function rest0(restUrl, httpMethod, param, contenttype, datatype, callback) {
try {
if (data === null || data === undefined) {
resultLine.html(NO_RESULT);
} else if (data.statusCode != normal_status) {
} else if (data.statusCode && data.statusCode != normal_status) {
resultLine.html("Error:" + data.errorInfo);
} else if (callback != null) {
resultLine.html("");
Expand Down Expand Up @@ -54,100 +87,13 @@ function checkSignIn() {
var welcomeDiv = jQuery('#topDiv').html("Welcome " + user);
}
}
// https://github.com/blueimp/JavaScript-MD5
// https://raw.github.com/blueimp/JavaScript-MD5/master/js/md5.min.js
!function (a) {
"use strict";
function b(a, b) {
var c = (65535 & a) + (65535 & b), d = (a >> 16) + (b >> 16) + (c >> 16);
return d << 16 | 65535 & c
}

function c(a, b) {
return a << b | a >>> 32 - b
}

function d(a, d, e, f, g, h) {
return b(c(b(b(d, a), b(f, h)), g), e)
}

function e(a, b, c, e, f, g, h) {
return d(b & c | ~b & e, a, b, f, g, h)
}

function f(a, b, c, e, f, g, h) {
return d(b & e | c & ~e, a, b, f, g, h)
}

function g(a, b, c, e, f, g, h) {
return d(b ^ c ^ e, a, b, f, g, h)
}

function h(a, b, c, e, f, g, h) {
return d(c ^ (b | ~e), a, b, f, g, h)
}

function i(a, c) {
a[c >> 5] |= 128 << c % 32, a[(c + 64 >>> 9 << 4) + 14] = c;
var d, i, j, k, l, m = 1732584193, n = -271733879, o = -1732584194, p = 271733878;
for (d = 0; d < a.length; d += 16)i = m, j = n, k = o, l = p, m = e(m, n, o, p, a[d], 7, -680876936), p = e(p, m, n, o, a[d + 1], 12, -389564586), o = e(o, p, m, n, a[d + 2], 17, 606105819), n = e(n, o, p, m, a[d + 3], 22, -1044525330), m = e(m, n, o, p, a[d + 4], 7, -176418897), p = e(p, m, n, o, a[d + 5], 12, 1200080426), o = e(o, p, m, n, a[d + 6], 17, -1473231341), n = e(n, o, p, m, a[d + 7], 22, -45705983), m = e(m, n, o, p, a[d + 8], 7, 1770035416), p = e(p, m, n, o, a[d + 9], 12, -1958414417), o = e(o, p, m, n, a[d + 10], 17, -42063), n = e(n, o, p, m, a[d + 11], 22, -1990404162), m = e(m, n, o, p, a[d + 12], 7, 1804603682), p = e(p, m, n, o, a[d + 13], 12, -40341101), o = e(o, p, m, n, a[d + 14], 17, -1502002290), n = e(n, o, p, m, a[d + 15], 22, 1236535329), m = f(m, n, o, p, a[d + 1], 5, -165796510), p = f(p, m, n, o, a[d + 6], 9, -1069501632), o = f(o, p, m, n, a[d + 11], 14, 643717713), n = f(n, o, p, m, a[d], 20, -373897302), m = f(m, n, o, p, a[d + 5], 5, -701558691), p = f(p, m, n, o, a[d + 10], 9, 38016083), o = f(o, p, m, n, a[d + 15], 14, -660478335), n = f(n, o, p, m, a[d + 4], 20, -405537848), m = f(m, n, o, p, a[d + 9], 5, 568446438), p = f(p, m, n, o, a[d + 14], 9, -1019803690), o = f(o, p, m, n, a[d + 3], 14, -187363961), n = f(n, o, p, m, a[d + 8], 20, 1163531501), m = f(m, n, o, p, a[d + 13], 5, -1444681467), p = f(p, m, n, o, a[d + 2], 9, -51403784), o = f(o, p, m, n, a[d + 7], 14, 1735328473), n = f(n, o, p, m, a[d + 12], 20, -1926607734), m = g(m, n, o, p, a[d + 5], 4, -378558), p = g(p, m, n, o, a[d + 8], 11, -2022574463), o = g(o, p, m, n, a[d + 11], 16, 1839030562), n = g(n, o, p, m, a[d + 14], 23, -35309556), m = g(m, n, o, p, a[d + 1], 4, -1530992060), p = g(p, m, n, o, a[d + 4], 11, 1272893353), o = g(o, p, m, n, a[d + 7], 16, -155497632), n = g(n, o, p, m, a[d + 10], 23, -1094730640), m = g(m, n, o, p, a[d + 13], 4, 681279174), p = g(p, m, n, o, a[d], 11, -358537222), o = g(o, p, m, n, a[d + 3], 16, -722521979), n = g(n, o, p, m, a[d + 6], 23, 76029189), m = g(m, n, o, p, a[d + 9], 4, -640364487), p = g(p, m, n, o, a[d + 12], 11, -421815835), o = g(o, p, m, n, a[d + 15], 16, 530742520), n = g(n, o, p, m, a[d + 2], 23, -995338651), m = h(m, n, o, p, a[d], 6, -198630844), p = h(p, m, n, o, a[d + 7], 10, 1126891415), o = h(o, p, m, n, a[d + 14], 15, -1416354905), n = h(n, o, p, m, a[d + 5], 21, -57434055), m = h(m, n, o, p, a[d + 12], 6, 1700485571), p = h(p, m, n, o, a[d + 3], 10, -1894986606), o = h(o, p, m, n, a[d + 10], 15, -1051523), n = h(n, o, p, m, a[d + 1], 21, -2054922799), m = h(m, n, o, p, a[d + 8], 6, 1873313359), p = h(p, m, n, o, a[d + 15], 10, -30611744), o = h(o, p, m, n, a[d + 6], 15, -1560198380), n = h(n, o, p, m, a[d + 13], 21, 1309151649), m = h(m, n, o, p, a[d + 4], 6, -145523070), p = h(p, m, n, o, a[d + 11], 10, -1120210379), o = h(o, p, m, n, a[d + 2], 15, 718787259), n = h(n, o, p, m, a[d + 9], 21, -343485551), m = b(m, i), n = b(n, j), o = b(o, k), p = b(p, l);
return[m, n, o, p]
}

function j(a) {
var b, c = "";
for (b = 0; b < 32 * a.length; b += 8)c += String.fromCharCode(a[b >> 5] >>> b % 32 & 255);
return c
}

function k(a) {
var b, c = [];
for (c[(a.length >> 2) - 1] = void 0, b = 0; b < c.length; b += 1)c[b] = 0;
for (b = 0; b < 8 * a.length; b += 8)c[b >> 5] |= (255 & a.charCodeAt(b / 8)) << b % 32;
return c
}

function l(a) {
return j(i(k(a), 8 * a.length))
}

function m(a, b) {
var c, d, e = k(a), f = [], g = [];
for (f[15] = g[15] = void 0, e.length > 16 && (e = i(e, 8 * a.length)), c = 0; 16 > c; c += 1)f[c] = 909522486 ^ e[c], g[c] = 1549556828 ^ e[c];
return d = i(f.concat(k(b)), 512 + 8 * b.length), j(i(g.concat(d), 640))
}

function n(a) {
var b, c, d = "0123456789abcdef", e = "";
for (c = 0; c < a.length; c += 1)b = a.charCodeAt(c), e += d.charAt(b >>> 4 & 15) + d.charAt(15 & b);
return e
}

function o(a) {
return unescape(encodeURIComponent(a))
}

function p(a) {
return l(o(a))
}

function q(a) {
return n(p(a))
}

function r(a, b) {
return m(o(a), o(b))
}

function s(a, b) {
return n(r(a, b))
}

function t(a, b, c) {
return b ? c ? r(b, a) : s(b, a) : c ? p(a) : q(a)
function getValue(query, key) {
var vars = query.split("&");
for (i = 0; i < vars.length; i++) {
var parts = vars[i].split("=");
if (parts[0] == key) {
return parts[1];
}
}

"function" == typeof define && define.amd ? define(function () {
return t
}) : a.md5 = t
}(this);
return null;
}
35 changes: 34 additions & 1 deletion atup-page/src/main/webapp/js/devices/device.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
var query = window.location.search.substring(1);

function initial() {
checkSignIn();
if (query) {
jQuery("#deviceIp").val(getValue(query, "deviceIp"));
jQuery("#deviceName").val(getValue(query, "deviceName"));
jQuery("#deviceType").val(getValue(query, "deviceType"));
jQuery("#deviceStatus").val(getValue(query, "deviceStatus"));
}
rest(HOST + ATUP_USER_BASE_URI + USER_PATH, GET_METHOD, null, renderUserList);
}

function renderUserList(data) {
var list = data.userList;
var html = "";
var userId;
if (query) {
userId = getValue(query, "userId");
}
jQuery.each(list, function (i, user) {
if (user.userId == userId) {
html += "<option selected='selected' value='";
} else {
html += "<option value='";
}
html += user.userId + "'>";
html += user.userName + "</option>";
});
jQuery("#userList").empty().append(html);
}

function createDevice() {
var deviceIp = $("#deviceIp0").val();
var deviceName = $("#deviceName0").val();
Expand All @@ -10,7 +42,8 @@ function updateDevice() {
var deviceName = $("#deviceName").val();
var deviceType = $("#deviceType").val();
var deviceStatus = $("#deviceStatus").val();
var putData = JSON.stringify({deviceHost: deviceIp, deviceName: deviceName, deviceType: deviceType, deviceStatus: deviceStatus});
var userId = $("#userList").val();
var putData = JSON.stringify({deviceHost: deviceIp, deviceName: deviceName, deviceType: deviceType, deviceStatus: deviceStatus, user: {userId: userId}});
rest(HOST + ATUP_DEVICE_BASE_URI + DEVICE_PATH, PUT_METHOD, putData, renderEdit);
}
function renderEdit(data) {
Expand Down
Loading

0 comments on commit b949a04

Please sign in to comment.