source: trunk/www/my_base/projects/index.jsp @ 3847

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

Fixes #788: Select project default platforms / variant

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 13.1 KB
Line 
1<%-- $Id: index.jsp 3847 2007-10-17 05:52:56Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 2
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.BasicItem"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.Project"
35  import="net.sf.basedb.core.User"
36  import="net.sf.basedb.core.Group"
37  import="net.sf.basedb.core.Platform"
38  import="net.sf.basedb.core.PlatformVariant"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultIterator"
41  import="net.sf.basedb.core.Permission"
42  import="net.sf.basedb.core.ItemContext"
43  import="net.sf.basedb.core.MultiPermissions"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.ItemAlreadyExistsException"
46  import="net.sf.basedb.core.RawDataType"
47  import="net.sf.basedb.core.RawDataTypes"
48  import="net.sf.basedb.util.RemovableUtil"
49  import="net.sf.basedb.util.OwnableUtil"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.PermissionUtil"
52  import="net.sf.basedb.clients.web.WebException"
53  import="net.sf.basedb.util.Values"
54  import="net.sf.basedb.clients.web.util.HTML"
55  import="java.util.Enumeration"
56  import="java.util.Set"
57  import="java.util.HashSet"
58  import="java.util.List"
59  import="java.util.ArrayList"
60  import="java.util.Collections"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%!
64  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description,actions");
65  private static final Item itemType = Item.PROJECT;
66%>
67<%
68final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
69final String ID = sc.getId();
70final String cmd = request.getParameter("cmd");
71final String root = request.getContextPath()+"/";
72final String mode = request.getParameter("mode");
73final String callback = request.getParameter("callback");
74final String itemId = request.getParameter("item_id");
75final String listPage = "list_projects.jsp?ID="+ID
76  +(mode == null ? "" : "&mode="+mode)
77  +(callback == null ? "" : "&callback="+callback)
78  +(itemId == null ? "" : "&item_id="+itemId);
79final String viewPage = "view_project.jsp?ID="+ID;
80final String editPage = "edit_project.jsp?ID="+ID;
81
82String forward = null;
83String redirect = null;
84String message = null;
85DbControl dc = null;
86
87try
88{
89  if (cmd == null || "List".equals(cmd))
90  {
91    // Display the list page without updatinging the current context
92    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
93    redirect = listPage;
94  }
95  else if ("UpdateContext".equals(cmd))
96  {
97    // Display the list page after updating the current context from the request parameters
98    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
99    redirect = listPage;
100  }
101  else if ("LoadContext".equals(cmd))
102  {
103    // Display the list page after loading a saved context
104    int contextId = Values.getInt(request.getParameter("context"));
105    Base.loadContext(sc, contextId, defaultContext);
106    redirect = listPage;
107  }
108
109  else if ("ViewItem".equals(cmd))
110  {
111    // Display the view page for a single item
112    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
113    forward = viewPage;
114  }
115  else if ("EditItem".equals(cmd))
116  {
117    // Display the edit page for a single item (should be opened in a popup)
118    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
119    redirect = editPage;
120  }
121  else if ("NewItem".equals(cmd))
122  {
123    // Display the edit page for a new item (should be opened in a popup)
124    if (!sc.hasPermission(Permission.CREATE, itemType))
125    {
126      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
127    }
128    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
129    cc.setId(0);
130    redirect = editPage;
131  }
132  else if ("UpdateItem".equals(cmd))
133  {
134    // Update the properties on an item (will close the popup)
135    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
136    dc = sc.newDbControl();
137    Project project = (Project)cc.getObject("item");
138    if (project == null)
139    {
140      project = Project.getNew(dc);
141      message = "Project created";
142      dc.saveItem(project);
143    }
144    else
145    {
146      dc.reattachItem(project);
147      message = "Project updated";
148    }
149    project.setName(Values.getStringOrNull(request.getParameter("name")));
150    project.setDescription(Values.getStringOrNull(request.getParameter("description")));
151   
152    // Members tab
153    String[] modifiedUsers = Values.getString(request.getParameter("modifiedUsers")).split(",");
154    for (int i = 0; i < modifiedUsers.length; ++i)
155    {
156      int userId = Values.getInt(modifiedUsers[i], -1);
157      if (userId != -1) 
158      {
159        Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("U"+userId), 0));
160        project.setPermissions(User.getById(dc, userId), permissions);
161      }
162    }
163
164    String[] modifiedGroups = Values.getString(request.getParameter("modifiedGroups")).split(",");
165    for (int i = 0; i < modifiedGroups.length; ++i)
166    {
167      int groupId = Values.getInt(modifiedGroups[i], -1);
168      if (groupId != -1) 
169      {
170        Set<Permission> permissions = PermissionUtil.getPermissions(Values.getInt(request.getParameter("G"+groupId), 0));
171        project.setPermissions(Group.getById(dc, groupId), permissions);
172      }
173    }
174   
175    // Default tab
176   
177    Platform platform = null;
178    PlatformVariant variant = null;
179    RawDataType rdt = null;
180    if (request.getParameter("platform") != null)
181    {
182      String[] pv = request.getParameter("platform").split(":");
183      int platformId = Values.getInt(pv[0], -1);
184      int variantId = pv.length > 1 ? Values.getInt(pv[1], -1) : -1;
185      if (platformId > 0) platform =  Platform.getById(dc, platformId);
186      if (variantId > 0) variant = PlatformVariant.getById(dc, variantId);
187    }
188    if (variant != null) rdt = variant.getRawDataType();
189    if (rdt == null && platform != null) rdt = platform.getRawDataType();
190    if (rdt == null) rdt = RawDataTypes.getRawDataType( request.getParameter("rawdatatype"));
191    project.setDefaultItem(dc, platform, Project.Default.PLATFORM);
192    project.setDefaultItem(dc, variant, Project.Default.PLATFORM_VARIANT);
193    project.setDefaultRawDataType(rdt);   
194   
195    for (Project.Default d : Project.Default.values())
196    {
197      String selectDefault = "value_"+d.getName();
198      if (d.getItemType() != null)
199      {
200        int selectId = Values.getInt(request.getParameter(selectDefault), -1);     
201        if (selectId >= 0)
202        {
203          BasicItem item = selectId == 0 ? null : d.getItemType().getById(dc, selectId);
204          project.setDefaultItem(dc, item, d);
205        }
206      }
207    }
208   
209    dc.commit();
210    cc.removeObject("item");
211  }
212  else if ("DeleteItem".equals(cmd))
213  {
214    // Delete a single item and then return to the view page
215    dc = sc.newDbControl();
216    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
217    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), true);
218    dc.commit();
219    redirect = viewPage;
220  }
221  else if ("DeleteItems".equals(cmd))
222  {
223    // Delete all selected items on the list page
224    dc = sc.newDbControl();
225    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
226    int numTotal = cc.getSelected().size();
227    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
228    dc.commit();
229    if (numTotal != numRemoved)
230    {
231      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
232    }
233    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
234  }
235  else if ("RestoreItem".equals(cmd))
236  {
237    // Restore a single item and then return to the view page
238    dc = sc.newDbControl();
239    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
240    RemovableUtil.setRemoved(dc, itemType, Collections.singleton(cc.getId()), false);
241    dc.commit();
242    redirect = viewPage;
243  }
244  else if ("RestoreItems".equals(cmd))
245  {
246    // Restore all selected items on the list page
247    dc = sc.newDbControl();
248    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
249    int numTotal = cc.getSelected().size();
250    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
251    dc.commit();
252    if (numTotal != numRemoved)
253    {
254      message = (numRemoved == 0 ? "No" : "Only "+numRemoved+" of "+numTotal) + " items could be restored, because you have no WRITE permission";
255    }
256    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
257  }
258  else if ("TakeOwnershipOfItem".equals(cmd))
259  {
260    // Take ownership a single item and then return to the view page
261    dc = sc.newDbControl();
262    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
263    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
264    dc.commit();
265    redirect = viewPage;
266  }
267  else if ("TakeOwnershipOfItems".equals(cmd))
268  {
269    // Take ownership all selected items on the list page
270    dc = sc.newDbControl();
271    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
272    int numTotal = cc.getSelected().size();
273    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
274    dc.commit();
275    if (numTotal != numOwned)
276    {
277      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
278    }
279    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
280  }
281  else if ("ExportItems".equals(cmd))
282  {
283    // Run an export plugin in a list context
284    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
285    final ItemQuery<Project> query = Project.getQuery();
286    cc.configureQuery(query, true);
287    cc.setQuery(query);
288    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+projects";
289  }
290  else if ("ExportItem".equals(cmd))
291  {
292    // Run an export plugin in single-item context
293    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
294    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+project";
295  }
296  else if ("ImportItems".equals(cmd))
297  {
298    // Run an import plugin in a list context
299    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
300    final ItemQuery<Project> query = Project.getQuery();
301    cc.configureQuery(query, true);
302    cc.setQuery(query);
303    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+projects";
304  }
305  else if ("ImportItem".equals(cmd))
306  {
307    // Run an import plugin in single-item context
308    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
309    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+project";
310  }
311  else if ("RunListPlugin".equals(cmd))
312  {
313    // Run another plugin in a list context
314    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
315    final ItemQuery<Project> query = Project.getQuery();
316    cc.configureQuery(query, true);
317    cc.setQuery(query);
318    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
319  }
320  else if ("RunPlugin".equals(cmd))
321  {
322    // Run another plugin in single-item context
323    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
324    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
325  }
326  else
327  {
328    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
329  }
330}
331finally
332{
333  if (dc != null) dc.close();
334}
335
336if (forward != null)
337{
338  pageContext.forward(forward);
339}
340else if (redirect != null)
341{
342  response.sendRedirect(redirect);
343}
344else if (message == null)
345{
346  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
347}
348else
349{
350  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
351}
352%>
353
Note: See TracBrowser for help on using the repository browser.