source: extensions/net.sf.basedb.genepattern/trunk/resources/submit.jsp @ 1108

Last change on this file since 1108 was 1108, checked in by Nicklas Nordborg, 14 years ago

Fixes #221: Configure GenePattern? server

The settings are now saved to the databas as user default settings.

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