1108 |
04 Jun 09 |
nicklas |
1 |
|
1108 |
04 Jun 09 |
nicklas |
2 |
<%@page import="net.sf.basedb.core.query.Restrictions"%> |
1108 |
04 Jun 09 |
nicklas |
3 |
<%@page import="net.sf.basedb.core.UserDefaultSetting"%><%-- $Id $ |
1102 |
29 May 09 |
nicklas |
4 |
------------------------------------------------------------------ |
1102 |
29 May 09 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
1102 |
29 May 09 |
nicklas |
6 |
|
1102 |
29 May 09 |
nicklas |
7 |
This file is part of BASE - BioArray Software Environment. |
1102 |
29 May 09 |
nicklas |
8 |
Available at http://base.thep.lu.se/ |
1102 |
29 May 09 |
nicklas |
9 |
|
1102 |
29 May 09 |
nicklas |
10 |
BASE is free software; you can redistribute it and/or |
1102 |
29 May 09 |
nicklas |
11 |
modify it under the terms of the GNU General Public License |
1102 |
29 May 09 |
nicklas |
12 |
as published by the Free Software Foundation; either version 3 |
1102 |
29 May 09 |
nicklas |
13 |
of the License, or (at your option) any later version. |
1102 |
29 May 09 |
nicklas |
14 |
|
1102 |
29 May 09 |
nicklas |
15 |
BASE is distributed in the hope that it will be useful, |
1102 |
29 May 09 |
nicklas |
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1102 |
29 May 09 |
nicklas |
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1102 |
29 May 09 |
nicklas |
18 |
GNU General Public License for more details. |
1102 |
29 May 09 |
nicklas |
19 |
|
1102 |
29 May 09 |
nicklas |
20 |
You should have received a copy of the GNU General Public License |
1102 |
29 May 09 |
nicklas |
21 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
1102 |
29 May 09 |
nicklas |
22 |
------------------------------------------------------------------ |
1102 |
29 May 09 |
nicklas |
23 |
|
1102 |
29 May 09 |
nicklas |
24 |
@author Nicklas |
1102 |
29 May 09 |
nicklas |
25 |
--%> |
1102 |
29 May 09 |
nicklas |
26 |
<%@ page |
1102 |
29 May 09 |
nicklas |
27 |
pageEncoding="UTF-8" |
1102 |
29 May 09 |
nicklas |
28 |
session="false" |
1102 |
29 May 09 |
nicklas |
29 |
import="net.sf.basedb.core.Application" |
1102 |
29 May 09 |
nicklas |
30 |
import="net.sf.basedb.core.SessionControl" |
1102 |
29 May 09 |
nicklas |
31 |
import="net.sf.basedb.core.DbControl" |
1102 |
29 May 09 |
nicklas |
32 |
import="net.sf.basedb.core.User" |
1108 |
04 Jun 09 |
nicklas |
33 |
import="net.sf.basedb.core.UserDefaultSetting" |
1108 |
04 Jun 09 |
nicklas |
34 |
import="net.sf.basedb.core.ItemQuery" |
1102 |
29 May 09 |
nicklas |
35 |
import="net.sf.basedb.core.Presets" |
1108 |
04 Jun 09 |
nicklas |
36 |
import="net.sf.basedb.core.query.Restrictions" |
1108 |
04 Jun 09 |
nicklas |
37 |
import="net.sf.basedb.core.query.Hql" |
1108 |
04 Jun 09 |
nicklas |
38 |
import="net.sf.basedb.core.query.Expressions" |
1102 |
29 May 09 |
nicklas |
39 |
import="net.sf.basedb.core.Presets.Preset" |
1102 |
29 May 09 |
nicklas |
40 |
import="net.sf.basedb.clients.web.Base" |
1102 |
29 May 09 |
nicklas |
41 |
import="net.sf.basedb.clients.web.WebException" |
1102 |
29 May 09 |
nicklas |
42 |
import="net.sf.basedb.clients.web.util.HTML" |
1102 |
29 May 09 |
nicklas |
43 |
import="net.sf.basedb.util.Values" |
1108 |
04 Jun 09 |
nicklas |
44 |
import="java.util.List" |
1102 |
29 May 09 |
nicklas |
45 |
%> |
1108 |
04 Jun 09 |
nicklas |
46 |
<%! |
1108 |
04 Jun 09 |
nicklas |
47 |
private void savePreset(DbControl dc, Presets presets) |
1108 |
04 Jun 09 |
nicklas |
48 |
{ |
1108 |
04 Jun 09 |
nicklas |
49 |
SessionControl sc = dc.getSessionControl(); |
1108 |
04 Jun 09 |
nicklas |
50 |
String setting = "net.sf.basedb.genepattern.options"; |
1108 |
04 Jun 09 |
nicklas |
51 |
String xml = presets.asXml(); |
1108 |
04 Jun 09 |
nicklas |
52 |
|
1108 |
04 Jun 09 |
nicklas |
53 |
// Save to memory |
1108 |
04 Jun 09 |
nicklas |
54 |
sc.setUserDefaultSetting(setting, xml); |
1108 |
04 Jun 09 |
nicklas |
55 |
|
1108 |
04 Jun 09 |
nicklas |
56 |
// Save to db |
1108 |
04 Jun 09 |
nicklas |
57 |
User user = User.getById(dc, sc.getLoggedInUserId()); |
1108 |
04 Jun 09 |
nicklas |
58 |
ItemQuery<UserDefaultSetting> query = UserDefaultSetting.getQuery(user); |
1108 |
04 Jun 09 |
nicklas |
59 |
query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(setting))); |
1108 |
04 Jun 09 |
nicklas |
60 |
List<UserDefaultSetting> result = query.list(dc); |
1108 |
04 Jun 09 |
nicklas |
61 |
UserDefaultSetting gpServers = null; |
1108 |
04 Jun 09 |
nicklas |
62 |
if (result.size() > 0) |
1108 |
04 Jun 09 |
nicklas |
63 |
{ |
1108 |
04 Jun 09 |
nicklas |
64 |
gpServers = result.get(0); |
1108 |
04 Jun 09 |
nicklas |
65 |
gpServers.setValue(xml); |
1108 |
04 Jun 09 |
nicklas |
66 |
} |
1108 |
04 Jun 09 |
nicklas |
67 |
else |
1108 |
04 Jun 09 |
nicklas |
68 |
{ |
1108 |
04 Jun 09 |
nicklas |
69 |
gpServers = UserDefaultSetting.getNew(dc, user, setting, xml); |
1108 |
04 Jun 09 |
nicklas |
70 |
dc.saveItem(gpServers); |
1108 |
04 Jun 09 |
nicklas |
71 |
} |
1108 |
04 Jun 09 |
nicklas |
72 |
} |
1108 |
04 Jun 09 |
nicklas |
73 |
%> |
1102 |
29 May 09 |
nicklas |
74 |
<% |
1102 |
29 May 09 |
nicklas |
75 |
SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
1102 |
29 May 09 |
nicklas |
76 |
String ID = sc.getId(); |
1102 |
29 May 09 |
nicklas |
77 |
String cmd = request.getParameter("cmd"); |
1102 |
29 May 09 |
nicklas |
78 |
String root = request.getContextPath()+"/"; |
1102 |
29 May 09 |
nicklas |
79 |
|
1102 |
29 May 09 |
nicklas |
80 |
String redirect = null; |
1102 |
29 May 09 |
nicklas |
81 |
String message = null; |
1108 |
04 Jun 09 |
nicklas |
82 |
DbControl dc = null; |
1102 |
29 May 09 |
nicklas |
83 |
try |
1102 |
29 May 09 |
nicklas |
84 |
{ |
1102 |
29 May 09 |
nicklas |
85 |
if ("SaveServer".equals(cmd)) |
1102 |
29 May 09 |
nicklas |
86 |
{ |
1108 |
04 Jun 09 |
nicklas |
87 |
dc = sc.newDbControl(); |
1108 |
04 Jun 09 |
nicklas |
88 |
String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options"); |
1102 |
29 May 09 |
nicklas |
89 |
Presets presets = new Presets(); |
1102 |
29 May 09 |
nicklas |
90 |
if (presetsXml != null) presets.loadFrom(presetsXml); |
1106 |
02 Jun 09 |
nicklas |
91 |
String originalGpServer = request.getParameter("originalGpServer"); |
1102 |
29 May 09 |
nicklas |
92 |
String gpServer = request.getParameter("gpServer"); |
1102 |
29 May 09 |
nicklas |
93 |
Preset server = presets.getPreset(gpServer); |
1106 |
02 Jun 09 |
nicklas |
94 |
if ("".equals(originalGpServer)) |
1106 |
02 Jun 09 |
nicklas |
95 |
{ |
1106 |
02 Jun 09 |
nicklas |
96 |
// Adding a new server - check if one already exists |
1106 |
02 Jun 09 |
nicklas |
97 |
if (server.getSetting("server.login") != null) |
1106 |
02 Jun 09 |
nicklas |
98 |
{ |
1106 |
02 Jun 09 |
nicklas |
99 |
throw new WebException("popup", "Server exists", "The server {1} already exists", gpServer); |
1106 |
02 Jun 09 |
nicklas |
100 |
} |
1106 |
02 Jun 09 |
nicklas |
101 |
} |
1106 |
02 Jun 09 |
nicklas |
102 |
else if (!gpServer.equals(originalGpServer)) |
1106 |
02 Jun 09 |
nicklas |
103 |
{ |
1106 |
02 Jun 09 |
nicklas |
104 |
// The URL of an existing server has been modified |
1106 |
02 Jun 09 |
nicklas |
105 |
presets.deletePreset(originalGpServer); |
1106 |
02 Jun 09 |
nicklas |
106 |
} |
1102 |
29 May 09 |
nicklas |
107 |
server.setSetting("server.login", request.getParameter("gpLogin")); |
1102 |
29 May 09 |
nicklas |
108 |
server.setSetting("server.password", request.getParameter("gpPassword")); |
1126 |
15 Jun 09 |
nicklas |
109 |
server.setSetting("base.url", request.getParameter("baseUrl")); |
1108 |
04 Jun 09 |
nicklas |
110 |
savePreset(dc, presets); |
1108 |
04 Jun 09 |
nicklas |
111 |
dc.commit(); |
1106 |
02 Jun 09 |
nicklas |
112 |
message = gpServer + " saved"; |
1102 |
29 May 09 |
nicklas |
113 |
} |
1102 |
29 May 09 |
nicklas |
114 |
else if ("RemoveServer".equals(cmd)) |
1102 |
29 May 09 |
nicklas |
115 |
{ |
1108 |
04 Jun 09 |
nicklas |
116 |
dc = sc.newDbControl(); |
1108 |
04 Jun 09 |
nicklas |
117 |
String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options"); |
1102 |
29 May 09 |
nicklas |
118 |
Presets presets = new Presets(); |
1102 |
29 May 09 |
nicklas |
119 |
if (presetsXml != null) presets.loadFrom(presetsXml); |
1102 |
29 May 09 |
nicklas |
120 |
String gpServer = request.getParameter("gpServer"); |
1102 |
29 May 09 |
nicklas |
121 |
presets.deletePreset(gpServer); |
1108 |
04 Jun 09 |
nicklas |
122 |
savePreset(dc, presets); |
1108 |
04 Jun 09 |
nicklas |
123 |
dc.commit(); |
1126 |
15 Jun 09 |
nicklas |
124 |
message = gpServer + " deleted"; |
1102 |
29 May 09 |
nicklas |
125 |
} |
1102 |
29 May 09 |
nicklas |
126 |
else |
1102 |
29 May 09 |
nicklas |
127 |
{ |
1102 |
29 May 09 |
nicklas |
128 |
throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
1102 |
29 May 09 |
nicklas |
129 |
} |
1102 |
29 May 09 |
nicklas |
130 |
} |
1102 |
29 May 09 |
nicklas |
131 |
finally |
1108 |
04 Jun 09 |
nicklas |
132 |
{ |
1108 |
04 Jun 09 |
nicklas |
133 |
if (dc != null) dc.close(); |
1108 |
04 Jun 09 |
nicklas |
134 |
} |
1102 |
29 May 09 |
nicklas |
135 |
if (message == null) |
1102 |
29 May 09 |
nicklas |
136 |
{ |
1102 |
29 May 09 |
nicklas |
137 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=0&wait=0"); |
1102 |
29 May 09 |
nicklas |
138 |
} |
1102 |
29 May 09 |
nicklas |
139 |
else |
1102 |
29 May 09 |
nicklas |
140 |
{ |
1102 |
29 May 09 |
nicklas |
141 |
response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message)); |
1102 |
29 May 09 |
nicklas |
142 |
} |
1126 |
15 Jun 09 |
nicklas |
143 |
%> |