6544 |
30 Sep 14 |
nicklas |
1 |
<%-- $Id $ |
6544 |
30 Sep 14 |
nicklas |
2 |
------------------------------------------------------------------ |
6544 |
30 Sep 14 |
nicklas |
Copyright (C) 2011 Nicklas Nordborg |
6544 |
30 Sep 14 |
nicklas |
4 |
|
6544 |
30 Sep 14 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
6544 |
30 Sep 14 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
6544 |
30 Sep 14 |
nicklas |
7 |
|
6544 |
30 Sep 14 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or |
6544 |
30 Sep 14 |
nicklas |
9 |
modify it under the terms of the GNU General Public License |
6544 |
30 Sep 14 |
nicklas |
10 |
as published by the Free Software Foundation; either version 3 |
6544 |
30 Sep 14 |
nicklas |
11 |
of the License, or (at your option) any later version. |
6544 |
30 Sep 14 |
nicklas |
12 |
|
6544 |
30 Sep 14 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, |
6544 |
30 Sep 14 |
nicklas |
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6544 |
30 Sep 14 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6544 |
30 Sep 14 |
nicklas |
16 |
GNU General Public License for more details. |
6544 |
30 Sep 14 |
nicklas |
17 |
|
6544 |
30 Sep 14 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
6544 |
30 Sep 14 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6544 |
30 Sep 14 |
nicklas |
20 |
------------------------------------------------------------------ |
6544 |
30 Sep 14 |
nicklas |
21 |
|
6544 |
30 Sep 14 |
nicklas |
22 |
@author Nicklas |
6544 |
30 Sep 14 |
nicklas |
23 |
--%> |
6544 |
30 Sep 14 |
nicklas |
24 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
6544 |
30 Sep 14 |
nicklas |
25 |
import="net.sf.basedb.core.SessionControl" |
6544 |
30 Sep 14 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
6544 |
30 Sep 14 |
nicklas |
27 |
import="net.sf.basedb.core.User" |
6544 |
30 Sep 14 |
nicklas |
28 |
import="net.sf.basedb.core.Message" |
6544 |
30 Sep 14 |
nicklas |
29 |
import="net.sf.basedb.core.ItemQuery" |
6544 |
30 Sep 14 |
nicklas |
30 |
import="net.sf.basedb.core.Type" |
6544 |
30 Sep 14 |
nicklas |
31 |
import="net.sf.basedb.core.query.Restrictions" |
6544 |
30 Sep 14 |
nicklas |
32 |
import="net.sf.basedb.core.query.Expressions" |
6544 |
30 Sep 14 |
nicklas |
33 |
import="net.sf.basedb.core.query.Hql" |
6544 |
30 Sep 14 |
nicklas |
34 |
import="net.sf.basedb.util.error.ThrowableUtil" |
6544 |
30 Sep 14 |
nicklas |
35 |
import="net.sf.basedb.clients.web.Base" |
6544 |
30 Sep 14 |
nicklas |
36 |
import="java.util.List" |
6544 |
30 Sep 14 |
nicklas |
37 |
import="org.json.simple.JSONObject" |
6544 |
30 Sep 14 |
nicklas |
38 |
%> |
6544 |
30 Sep 14 |
nicklas |
39 |
<% |
6544 |
30 Sep 14 |
nicklas |
40 |
response.setHeader("Cache-Control", "no-cache, max-age=0"); |
6544 |
30 Sep 14 |
nicklas |
41 |
final SessionControl sc = Base.getSessionControl(pageContext, false); |
6544 |
30 Sep 14 |
nicklas |
42 |
final String ID = sc == null ? "" : sc.getId(); |
6544 |
30 Sep 14 |
nicklas |
43 |
final String cmd = request.getParameter("cmd"); |
6544 |
30 Sep 14 |
nicklas |
44 |
out.clear(); |
6544 |
30 Sep 14 |
nicklas |
45 |
JSONObject json = new JSONObject(); |
6544 |
30 Sep 14 |
nicklas |
46 |
json.put("status", "ok"); |
6544 |
30 Sep 14 |
nicklas |
47 |
DbControl dc = null; |
6544 |
30 Sep 14 |
nicklas |
48 |
try |
6544 |
30 Sep 14 |
nicklas |
49 |
{ |
6544 |
30 Sep 14 |
nicklas |
50 |
if ("GetFootnoteMessages".equals(cmd)) |
6544 |
30 Sep 14 |
nicklas |
51 |
{ |
6544 |
30 Sep 14 |
nicklas |
52 |
String broadcastTitle = (String)application.getAttribute("broadcast.title"); |
6544 |
30 Sep 14 |
nicklas |
53 |
json.put("broadcast", broadcastTitle); |
6544 |
30 Sep 14 |
nicklas |
54 |
|
6544 |
30 Sep 14 |
nicklas |
55 |
if (sc != null && sc.isLoggedIn()) |
6544 |
30 Sep 14 |
nicklas |
56 |
{ |
7954 |
12 May 21 |
nicklas |
57 |
dc = sc.newDbControl(":Get footnote messages"); |
6544 |
30 Sep 14 |
nicklas |
58 |
long numNewMessages = Message.countUnreadMessages(dc, null, false); |
6544 |
30 Sep 14 |
nicklas |
59 |
|
6544 |
30 Sep 14 |
nicklas |
60 |
json.put("newMessages", numNewMessages); |
6544 |
30 Sep 14 |
nicklas |
61 |
|
6544 |
30 Sep 14 |
nicklas |
62 |
if (numNewMessages == 1) |
6544 |
30 Sep 14 |
nicklas |
63 |
{ |
6544 |
30 Sep 14 |
nicklas |
64 |
User user = User.getById(dc, sc.getLoggedInUserId()); |
6544 |
30 Sep 14 |
nicklas |
65 |
ItemQuery<Message> query = Message.getQuery(user); |
6544 |
30 Sep 14 |
nicklas |
66 |
query.restrict( |
6544 |
30 Sep 14 |
nicklas |
67 |
Restrictions.eq( |
6544 |
30 Sep 14 |
nicklas |
68 |
Hql.property("read"), |
6544 |
30 Sep 14 |
nicklas |
69 |
Expressions.parameter("read") |
6544 |
30 Sep 14 |
nicklas |
70 |
) |
6544 |
30 Sep 14 |
nicklas |
71 |
); |
6544 |
30 Sep 14 |
nicklas |
72 |
query.setParameter("read", false, Type.BOOLEAN); |
6544 |
30 Sep 14 |
nicklas |
73 |
List<Message> messages = query.list(dc); |
6544 |
30 Sep 14 |
nicklas |
74 |
Message message = messages.get(0); |
6544 |
30 Sep 14 |
nicklas |
75 |
|
6544 |
30 Sep 14 |
nicklas |
76 |
JSONObject jsonMessage = new JSONObject(); |
6544 |
30 Sep 14 |
nicklas |
77 |
jsonMessage.put("id", message.getId()); |
6544 |
30 Sep 14 |
nicklas |
78 |
jsonMessage.put("name", message.getName()); |
6544 |
30 Sep 14 |
nicklas |
79 |
jsonMessage.put("from", message.getFrom()); |
6544 |
30 Sep 14 |
nicklas |
80 |
json.put("message", jsonMessage); |
6544 |
30 Sep 14 |
nicklas |
81 |
} |
6544 |
30 Sep 14 |
nicklas |
82 |
} |
6544 |
30 Sep 14 |
nicklas |
83 |
} |
6544 |
30 Sep 14 |
nicklas |
84 |
} |
6544 |
30 Sep 14 |
nicklas |
85 |
catch (Throwable t) |
6544 |
30 Sep 14 |
nicklas |
86 |
{ |
6544 |
30 Sep 14 |
nicklas |
87 |
t.printStackTrace(); |
6544 |
30 Sep 14 |
nicklas |
88 |
json.clear(); |
6544 |
30 Sep 14 |
nicklas |
89 |
json.put("status", "error"); |
6544 |
30 Sep 14 |
nicklas |
90 |
json.put("message", t.getMessage()); |
6544 |
30 Sep 14 |
nicklas |
91 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
6544 |
30 Sep 14 |
nicklas |
92 |
} |
6544 |
30 Sep 14 |
nicklas |
93 |
finally |
6544 |
30 Sep 14 |
nicklas |
94 |
{ |
6544 |
30 Sep 14 |
nicklas |
95 |
json.writeJSONString(out); |
6544 |
30 Sep 14 |
nicklas |
96 |
out.flush(); |
6544 |
30 Sep 14 |
nicklas |
97 |
if (dc != null) dc.close(); |
6544 |
30 Sep 14 |
nicklas |
98 |
} |
6544 |
30 Sep 14 |
nicklas |
99 |
%> |