5402 |
06 Sep 10 |
nicklas |
1 |
<%-- $Id$ |
5402 |
06 Sep 10 |
nicklas |
2 |
------------------------------------------------------------------ |
5402 |
06 Sep 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5402 |
06 Sep 10 |
nicklas |
4 |
|
5402 |
06 Sep 10 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
5402 |
06 Sep 10 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
5402 |
06 Sep 10 |
nicklas |
7 |
|
5402 |
06 Sep 10 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
5402 |
06 Sep 10 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
5402 |
06 Sep 10 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
5402 |
06 Sep 10 |
nicklas |
11 |
of the License, or (at your option) any later version. |
5402 |
06 Sep 10 |
nicklas |
12 |
|
5402 |
06 Sep 10 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
5402 |
06 Sep 10 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5402 |
06 Sep 10 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5402 |
06 Sep 10 |
nicklas |
16 |
GNU General Public License for more details. |
5402 |
06 Sep 10 |
nicklas |
17 |
|
5402 |
06 Sep 10 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
5402 |
06 Sep 10 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5402 |
06 Sep 10 |
nicklas |
20 |
------------------------------------------------------------------ |
5402 |
06 Sep 10 |
nicklas |
21 |
|
5402 |
06 Sep 10 |
nicklas |
22 |
@author Nicklas |
5402 |
06 Sep 10 |
nicklas |
23 |
--%> |
5556 |
28 Jan 11 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
5402 |
06 Sep 10 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
5402 |
06 Sep 10 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
5402 |
06 Sep 10 |
nicklas |
27 |
import="net.sf.basedb.core.Job" |
5402 |
06 Sep 10 |
nicklas |
28 |
import="net.sf.basedb.clients.web.Base" |
5402 |
06 Sep 10 |
nicklas |
29 |
import="net.sf.basedb.util.Values" |
5556 |
28 Jan 11 |
nicklas |
30 |
import="net.sf.basedb.util.error.ThrowableUtil" |
5402 |
06 Sep 10 |
nicklas |
31 |
import="net.sf.basedb.clients.web.WebException" |
5402 |
06 Sep 10 |
nicklas |
32 |
import="net.sf.basedb.clients.web.util.HTML" |
5556 |
28 Jan 11 |
nicklas |
33 |
import="org.json.simple.JSONObject" |
5402 |
06 Sep 10 |
nicklas |
34 |
import="java.util.Date" |
5402 |
06 Sep 10 |
nicklas |
35 |
%> |
5402 |
06 Sep 10 |
nicklas |
36 |
<% |
6124 |
13 Sep 12 |
nicklas |
37 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
5402 |
06 Sep 10 |
nicklas |
38 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
5402 |
06 Sep 10 |
nicklas |
39 |
final String ID = sc.getId(); |
5402 |
06 Sep 10 |
nicklas |
40 |
final String cmd = request.getParameter("cmd"); |
5402 |
06 Sep 10 |
nicklas |
41 |
final String root = request.getContextPath()+"/"; |
5402 |
06 Sep 10 |
nicklas |
42 |
final int itemId = Values.getInt(request.getParameter("item_id")); |
5402 |
06 Sep 10 |
nicklas |
43 |
out.clear(); |
5556 |
28 Jan 11 |
nicklas |
44 |
JSONObject json = new JSONObject(); |
5556 |
28 Jan 11 |
nicklas |
45 |
json.put("status", "ok"); |
5402 |
06 Sep 10 |
nicklas |
46 |
DbControl dc = null; |
5402 |
06 Sep 10 |
nicklas |
47 |
try |
5402 |
06 Sep 10 |
nicklas |
48 |
{ |
5402 |
06 Sep 10 |
nicklas |
49 |
if ("GetProgress".equals(cmd)) |
5402 |
06 Sep 10 |
nicklas |
50 |
{ |
7954 |
12 May 21 |
nicklas |
51 |
dc = sc.newDbControl(":Get job progress"); |
5402 |
06 Sep 10 |
nicklas |
52 |
Job job = Job.getById(dc, itemId); |
6432 |
14 Mar 14 |
nicklas |
53 |
job.requestStatusUpdate(); |
5556 |
28 Jan 11 |
nicklas |
54 |
json.put("id", job.getId()); |
5556 |
28 Jan 11 |
nicklas |
55 |
json.put("jobStatus", job.getStatus().name()); |
5556 |
28 Jan 11 |
nicklas |
56 |
json.put("message", HTML.niceFormat(job.getStatusMessage())); |
5556 |
28 Jan 11 |
nicklas |
57 |
json.put("percentComplete", job.getPercentComplete()); |
5402 |
06 Sep 10 |
nicklas |
58 |
Date started = job.getStarted(); |
5402 |
06 Sep 10 |
nicklas |
59 |
if (started != null) |
5402 |
06 Sep 10 |
nicklas |
60 |
{ |
5402 |
06 Sep 10 |
nicklas |
61 |
Date ended = job.getEnded(); |
5402 |
06 Sep 10 |
nicklas |
62 |
if (ended == null) ended = new Date(); |
5402 |
06 Sep 10 |
nicklas |
63 |
long runningTime = ended.getTime() - started.getTime(); |
5556 |
28 Jan 11 |
nicklas |
64 |
json.put("runningTime", Values.formatTime(runningTime / 1000)); |
5402 |
06 Sep 10 |
nicklas |
65 |
} |
5402 |
06 Sep 10 |
nicklas |
66 |
dc.commit(); |
5402 |
06 Sep 10 |
nicklas |
67 |
} |
5402 |
06 Sep 10 |
nicklas |
68 |
else |
5402 |
06 Sep 10 |
nicklas |
69 |
{ |
5402 |
06 Sep 10 |
nicklas |
70 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
5402 |
06 Sep 10 |
nicklas |
71 |
} |
5402 |
06 Sep 10 |
nicklas |
72 |
} |
5556 |
28 Jan 11 |
nicklas |
73 |
catch (Throwable t) |
5556 |
28 Jan 11 |
nicklas |
74 |
{ |
5556 |
28 Jan 11 |
nicklas |
75 |
t.printStackTrace(); |
5556 |
28 Jan 11 |
nicklas |
76 |
json.clear(); |
5556 |
28 Jan 11 |
nicklas |
77 |
json.put("status", "error"); |
5556 |
28 Jan 11 |
nicklas |
78 |
json.put("message", t.getMessage()); |
5556 |
28 Jan 11 |
nicklas |
79 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
5556 |
28 Jan 11 |
nicklas |
80 |
} |
5402 |
06 Sep 10 |
nicklas |
81 |
finally |
5402 |
06 Sep 10 |
nicklas |
82 |
{ |
5556 |
28 Jan 11 |
nicklas |
83 |
json.writeJSONString(out); |
5556 |
28 Jan 11 |
nicklas |
84 |
out.flush(); |
5402 |
06 Sep 10 |
nicklas |
85 |
if (dc != null) dc.close(); |
5402 |
06 Sep 10 |
nicklas |
86 |
} |
5402 |
06 Sep 10 |
nicklas |
87 |
%> |