Changeset 1108


Ignore:
Timestamp:
Jun 4, 2009, 9:18:10 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #221: Configure GenePattern? server

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

Location:
extensions/net.sf.basedb.genepattern/trunk/resources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.genepattern/trunk/resources/edit_server.jsp

    r1106 r1108  
    5050
    5151final String gpServer = Values.getStringOrNull(request.getParameter("gpServer"));
    52 String presetsXml = sc.getUserClientSetting("net.sf.basedb.genepattern.options");
     52String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options");
    5353Presets presets = new Presets();
    5454if (presetsXml != null) presets.loadFrom(presetsXml);
  • extensions/net.sf.basedb.genepattern/trunk/resources/options.jsp

    r1106 r1108  
    5454  dc = sc.newDbControl();
    5555  final User user = User.getById(dc, sc.getLoggedInUserId());
    56   String presetsXml = sc.getUserClientSetting("net.sf.basedb.genepattern.options");
     56  String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options");
    5757  Presets presets = new Presets();
    5858  if (presetsXml != null) presets.loadFrom(presetsXml);
  • extensions/net.sf.basedb.genepattern/trunk/resources/submit.jsp

    r1106 r1108  
    1 <%-- $Id $
     1
     2<%@page import="net.sf.basedb.core.query.Restrictions"%>
     3<%@page import="net.sf.basedb.core.UserDefaultSetting"%><%-- $Id $
    24  ------------------------------------------------------------------
    35  Copyright (C) 2009 Nicklas Nordborg
     
    2931  import="net.sf.basedb.core.DbControl"
    3032  import="net.sf.basedb.core.User"
     33  import="net.sf.basedb.core.UserDefaultSetting"
     34  import="net.sf.basedb.core.ItemQuery"
    3135  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"
    3239  import="net.sf.basedb.core.Presets.Preset"
    3340  import="net.sf.basedb.clients.web.Base"
     
    3542  import="net.sf.basedb.clients.web.util.HTML"
    3643  import="net.sf.basedb.util.Values"
     44  import="java.util.List"
    3745%>
    38 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     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%>
    3974<%
    4075SessionControl sc = Base.getExistingSessionControl(pageContext, true);
     
    4580String redirect = null;
    4681String message = null;
    47 
     82DbControl dc = null;
    4883try
    4984{
    5085  if ("SaveServer".equals(cmd))
    5186  {
    52     String presetsXml = sc.getUserClientSetting("net.sf.basedb.genepattern.options");
     87    dc = sc.newDbControl();
     88    String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options");
    5389    Presets presets = new Presets();
    5490    if (presetsXml != null) presets.loadFrom(presetsXml);
     
    71107    server.setSetting("server.login", request.getParameter("gpLogin"));
    72108    server.setSetting("server.password", request.getParameter("gpPassword"));
    73     sc.setUserClientSetting("net.sf.basedb.genepattern.options", presets.asXml());
     109    savePreset(dc, presets);
     110    dc.commit();
    74111    message = gpServer + " saved";
    75112  }
    76113  else if ("RemoveServer".equals(cmd))
    77114  {
    78     String presetsXml = sc.getUserClientSetting("net.sf.basedb.genepattern.options");
     115    dc = sc.newDbControl();
     116    String presetsXml = sc.getUserDefaultSetting("net.sf.basedb.genepattern.options");
    79117    Presets presets = new Presets();
    80118    if (presetsXml != null) presets.loadFrom(presetsXml);
    81119    String gpServer = request.getParameter("gpServer");
    82120    presets.deletePreset(gpServer);
    83     sc.setUserClientSetting("net.sf.basedb.genepattern.options", presets.asXml());
     121    savePreset(dc, presets);
     122    dc.commit();
    84123    message = gpServer + " deleted";   
    85124  }
     
    90129}
    91130finally
    92 {}
     131{
     132  if (dc != null) dc.close();
     133}
    93134if (message == null)
    94135{
Note: See TracChangeset for help on using the changeset viewer.