source: trunk/www/my_base/user/submit_user.jsp @ 7605

Last change on this file since 7605 was 7605, checked in by Nicklas Nordborg, 4 years ago

References #2151: Pre-compile all JSP pages before releases

Getting rid of a lot of unchecked warnings. Most of them are solved by changed the API in several BASE core clases to use implict casting of return types instead of explicit (this moved the 'unchecked' warning to the API method from the caller). Example:

// Before
ItemContext cc = ...
Hardware hardware = (Hardware)cc.getObject("item");
// After
Hardware hardware = cc.getObject("item");

In most cases both the old and new version of the code will work, but if the returned object is using a "type" parameter it will not compile:

// This will not compile!
Set<AnnotatedItem> items = (Set<AnnotatedItem>)cc.getObject("AnnotatedItems");
// But this will!
Set<AnnotatedItem> items = cc.getObject("AnnotatedItems");

Note that existing compiled code will still work, but that some changes may be needed when compiling agains BASE 3.15. The issues should be easy to solve (eg. remove an explict cast).

Extensions that uses JSP files that works in BASE 3.14 may stop working in BASE 3.15 since the compilation of the JSP files happens on the BASE server as they are accessed.

Another issues is that there are still a lot of unchecked warnings related to the JSON library. This build on regular Map and List API:s but has not specified generic type parameters so there is no way to get rid of those warnings without fixing the JSON library source code. The latest released version is from 2012 so it is not likely that this should happen unless we do it ourselves (the warnings are really annoying so maybe we should!).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1<%-- $Id: submit_user.jsp 7605 2019-02-26 10:10:15Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Johan Enell, Nicklas Nordborg, Martin Svensson
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  This page will save user information and preferences.
25
26  @param cmd The command to execute
27    - SaveSettings: Save the settings from the settings.jsp page.
28    - SavePreferences: Save preferences from the preferences.jsp page.
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page pageEncoding="UTF-8" session="false"
34  import="net.sf.basedb.core.SessionControl"
35  import="net.sf.basedb.core.DbControl"
36  import="net.sf.basedb.core.Item"
37  import="net.sf.basedb.core.User"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.ExtendedProperty"
40  import="net.sf.basedb.core.ExtendedProperties"
41  import="net.sf.basedb.util.EmailUtil"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
48  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
49  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
50  import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction"
51  import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer"
52  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
53  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
54  import="net.sf.basedb.clients.web.extensions.JspContext"
55  import="java.util.Arrays"
56  import="java.util.Collections"
57  import="java.util.List"
58  import="java.util.Map"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%
62SessionControl sc = Base.getExistingSessionControl(pageContext, true);
63String ID = sc.getId();
64String cmd = request.getParameter("cmd");
65String message = "";
66String root = request.getContextPath()+"/";
67
68String forward = null;
69DbControl dc = sc.newDbControl();
70try
71{
72  if ("SaveSettings".equals(cmd))
73  {
74    String email = Values.getStringOrNull(request.getParameter("email"));
75    if (email != null && !HTML.isValidEmail(email))
76    {
77      throw new WebException("popup", "Invalid email address",
78        "The email address {1} is not a valid email address.",
79        HTML.encodeTags(email)
80      );
81    }
82    User user = sc.getSessionSetting("user");
83    dc.reattachItem(user, false);
84
85    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user);
86    ExtensionsInvoker<OnSaveAction> invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information");
87    try
88    {
89      // Contact information tab
90      user.setEmail(email);
91      boolean useDeviceVerification = Values.getBoolean(request.getParameter("useDeviceVerification"));
92      if (!useDeviceVerification) user.disableDeviceVerification();
93      if (EmailUtil.isEnabled())
94      {
95        user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
96        if (useDeviceVerification && !user.getUseDeviceVerification())
97        {
98          // Send a verification code for verifying the email address
99          forward = "verify_email.jsp?ID="+ID;
100        }
101      }
102      user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
103      user.setAddress(Values.getStringOrNull(request.getParameter("address")));
104      user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
105      user.setFax(Values.getStringOrNull(request.getParameter("fax")));
106      user.setUrl(Values.getStringOrNull(request.getParameter("url")));
107 
108      // Password tab
109      String password = Values.getStringOrNull(request.getParameter("password"));
110      if (password != null) user.setPassword(password);
111 
112      // Other settings tab
113      user.setDescription(Values.getStringOrNull(request.getParameter("description")));
114 
115      // Extended properties
116      List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true);
117      if (extendedProperties != null)
118      {
119        Map<String, String[]> parameters = request.getParameterMap();
120        for (ExtendedProperty ep : extendedProperties)
121        {
122          if (ep.isRestrictedEdit()) continue;
123          String name = ep.getName();
124          if (parameters.containsKey("ep."+name))
125          {
126            Formatter<?> formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
127            Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
128            user.setExtended(name, value);
129          }
130        }
131      }
132     
133      // OnSave extensions
134      invoker.render(OnSaveRenderer.ON_SAVE);
135      dc.commit();
136      invoker.render(OnSaveRenderer.ON_COMMIT);
137      message = "Information saved";
138    }
139    catch (Exception ex)
140    {
141      invoker.render(OnSaveRenderer.onRollback(ex));
142      throw ex;
143    }
144    finally
145    {
146      sc.setSessionSetting("user", null);
147    }
148  }
149  else if ("VerifyEmail".equals(cmd))
150  {
151    String verificationCode = request.getParameter("verificationCode");
152    User user = sc.getSessionSetting("user");
153    dc.reattachItem(user, false);
154    user.enableDeviceVerification(verificationCode);
155    message = "The email has been verified";
156    dc.commit();
157  }
158  else if ("SavePreferences".equals(cmd))
159  {
160    User user = User.getById(dc, sc.getLoggedInUserId());
161    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user);
162    ExtensionsInvoker<OnSaveAction> invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information");
163    try
164    {
165      int newScale = Values.getInt(request.getParameter("scale"), 100);
166      sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
167      sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
168      sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
169      sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
170      ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
171      int maxRecent = Base.getMaxRecent(sc);
172   
173      String toolbar = request.getParameter("toolbar");
174      boolean hasImages = true;
175      boolean hasText = true;
176      if ("text".equals(toolbar))
177      {
178        hasImages = false;
179      }
180      else if ("images".equals(toolbar))
181      {
182        hasText = false;
183      }
184      sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
185      sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
186      String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
187      String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
188      String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
189      sc.setUserClientSetting("ratiocolor.min", minColor);
190      sc.setUserClientSetting("ratiocolor.mid", midColor);
191      sc.setUserClientSetting("ratiocolor.max", maxColor);
192      cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
193     
194      String dateFormat = request.getParameter("date_format");
195      String dateTimeFormat = request.getParameter("datetime_format");
196      FormatterSettings.setDateFormat(sc, dateFormat);
197      FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
198      cc.setRecent("dateFormats", dateFormat, maxRecent);
199      cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
200 
201      int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
202      FormatterSettings.setNumDecimals(sc, numDecimals);
203     
204      sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
205     
206      sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page")));
207     
208      // Plugins tab
209      sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
210      sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
211      sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
212     
213      // Recent items tab
214      int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
215      sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
216      sc.setSessionSetting("appearance.recent", newMaxUsed);
217      int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
218      sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
219      sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
220 
221      String[] stickyItems = request.getParameterValues("sticky_items");
222      sc.setUserClientSetting("menu.mostRecent", 
223        stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
224     
225      // Roles tab
226      String[] inactiveRoles = request.getParameterValues("inactiveRoles");
227      sc.setUserClientSetting("inactiveRoles", inactiveRoles == null ? null : Values.getString(Arrays.asList(inactiveRoles), ":", true));
228     
229      // OnSave extensions
230      invoker.render(OnSaveRenderer.ON_SAVE);
231      dc.commit();
232      invoker.render(OnSaveRenderer.ON_COMMIT);
233      message = "Preferences saved";
234    }
235    catch (Exception ex)
236    {
237      invoker.render(OnSaveRenderer.onRollback(ex));
238      throw ex;
239    }
240  }
241  else if ("ReloadPermissions".equals(cmd))
242  {
243    sc.reloadPermissions();
244    sc.reloadSettings(true, false);
245    sc.setSessionSetting("menu.standard.html", null);
246    message = "Permissions reloaded";
247  }
248  else if ("ResetFilters".equals(cmd))
249  {
250    boolean inDatabase = Values.getBoolean(request.getParameter("database"));
251    String itemType = Values.getStringOrNull(request.getParameter("item_type"));
252    Item item = itemType == null ? null : Item.valueOf(itemType);
253    int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase);
254    message = numDeleted + " list settings deleted";
255  }
256  else
257  {
258    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
259  }
260}
261finally
262{
263  if (dc != null) dc.close();
264}
265
266if (forward != null)
267{
268  pageContext.forward(forward);
269}
270else
271{
272  response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message));
273}
274%>
275
Note: See TracBrowser for help on using the repository browser.