source: trunk/www/admin/pluginconfigurations/view_configuration.jsp @ 5425

Last change on this file since 5425 was 5425, checked in by Nicklas Nordborg, 13 years ago

References #1514: Fix character encoding of jsp files

I hope this fixes most of the issues, including the reporter list filtering in many places. Let's keep an eye open for more issues until it is time to release 2.16

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.0 KB
Line 
1<%-- $Id: view_configuration.jsp 5425 2010-09-23 13:30:07Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.SystemItems"
30  import="net.sf.basedb.core.Group"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.PluginDefinition"
36  import="net.sf.basedb.core.PluginConfiguration"
37  import="net.sf.basedb.core.ParameterInfo"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.BasicItem"
40  import="net.sf.basedb.core.File"
41  import="net.sf.basedb.core.MultiPermissions"
42  import="net.sf.basedb.core.Nameable"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.PluginDefinition"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.core.plugin.Plugin"
47  import="net.sf.basedb.core.Project"
48  import="net.sf.basedb.util.JarClassLoader"
49  import="net.sf.basedb.util.ToStringComparator"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
52  import="net.sf.basedb.clients.web.PermissionUtil"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="net.sf.basedb.clients.web.util.NameablePluginAdaptor"
56  import="net.sf.basedb.util.formatter.Formatter"
57  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
58  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
59  import="net.sf.basedb.clients.web.extensions.JspContext"
60  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
61  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
62  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
63  import="java.util.Map"
64  import="java.util.Set"
65  import="java.util.TreeSet"
66  import="java.util.List"
67  import="java.util.Collections"
68  import="java.util.Date"
69%>
70<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
71<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
72<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
73<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
74<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
75<%!
76  private static final Item itemType = Item.PLUGINCONFIGURATION;
77  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
78%>
79<%
80final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
81final String ID = sc.getId();
82final String root = request.getContextPath() + "/";
83final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
84final int itemId = cc.getId();
85final String tab = Values.getString(request.getParameter("tab"), "properties");
86final float scale = Base.getScale(sc);
87final DbControl dc = sc.newDbControl();
88try
89{
90  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
91  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
92
93  String title = null;
94  PluginConfiguration configuration = PluginConfiguration.getById(dc, itemId);
95 
96  final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
97  final boolean writePermission = configuration.hasPermission(Permission.WRITE);
98  final boolean deletePermission = configuration.hasPermission(Permission.DELETE);
99  final boolean sharePermission = configuration.hasPermission(Permission.SET_PERMISSION);
100  final boolean setOwnerPermission = configuration.hasPermission(Permission.SET_OWNER);
101  final boolean isRemoved = configuration.isRemoved();
102  final boolean isUsed = isRemoved && configuration.isUsed();
103  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
104  final boolean isOwner = configuration.isOwner();
105
106  final Set<GuiContext> contexts = new TreeSet<GuiContext>(new ToStringComparator<GuiContext>(false));
107  PluginDefinition plugin = null;
108  Nameable nameableProxy = null;
109  boolean readPlugin = true;
110  boolean configurable = false;
111  try
112  {
113    plugin = configuration.getPluginDefinition();
114    nameableProxy = new NameablePluginAdaptor(plugin);
115    contexts.addAll(plugin.getGuiContexts());
116    configurable = plugin.isInteractive() && plugin.supportsConfigurations();
117  }
118  catch (PermissionDeniedException ex)
119  {
120    readPlugin = false;
121  }
122  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, configuration);
123  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
124  %>
125  <base:page title="<%=title%>">
126  <base:head scripts="table.js,tabcontrol.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css">
127    <ext:scripts context="<%=jspContext%>" />
128    <ext:stylesheets context="<%=jspContext%>" />
129    <script language="JavaScript">
130    function editItem()
131    {
132      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
133    }
134    function copyItem()
135    {
136      Main.copyItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
137    }
138    function shareItem()
139    {
140      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareConfiguration', 600, 400);
141    }
142    function deleteItem()
143    {
144      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
145    }
146    function restoreItem()
147    {
148      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
149    }
150    function deleteItemPermanently()
151    {
152      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
153    }
154    function itemDeleted()
155    {
156      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
157    }
158    function showUsingItems()
159    {
160      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
161    }
162    function setOwner()
163    {
164      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
165    }
166    function runPlugin(cmd)
167    {
168      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
169    }
170    function configure()
171    {
172      Main.openPopup('../../common/plugin/index.jsp?ID=<%=ID%>&cmd=ConfigurePlugin&pluginconfiguration_id=<%=itemId%>', 'ConfigurePlugin', 800, 600);
173    }
174    function switchTab(tabControlId, tabId)
175    {
176      if (TabControl.isActive(tabControlId, tabId)) return;
177      if (tabId == 'history' && tabId != '<%=tab%>')
178      {
179        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
180      }
181      else
182      {
183        TabControl.setActiveTab(tabControlId, tabId);
184      }
185    }
186    </script>
187  </base:head>
188  <base:body>
189    <p>
190    <p:path>
191      <p:pathelement title="Plugin configurations" href="<%="index.jsp?ID="+ID%>" />
192      <p:pathelement title="<%=HTML.encodeTags(configuration.getName())%>" />
193    </p:path>
194   
195    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
196    <t:tab id="properties" title="Properties">
197    <tbl:toolbar
198      >
199      <tbl:button 
200        disabled="<%=writePermission ? false : true%>" 
201        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
202        onclick="editItem()" 
203        title="Edit&hellip;" 
204        tooltip="<%=writePermission ? "Edit this plugin configuration" : "You do not have permission to edit this plugin configuration"%>" 
205      />
206      <tbl:button 
207        disabled="<%=!createPermission%>" 
208        image="<%=createPermission ? "copy.gif" : "copy_disabled.gif"%>"
209        onclick="copyItem()" 
210        title="Copy&hellip;" 
211        tooltip="<%=createPermission ? "Create a copy of this configuration" : "You do not have permission to create new configurations"%>"
212      />
213      <tbl:button 
214        disabled="<%=deletePermission ? false : true%>" 
215        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
216        onclick="deleteItem()" 
217        title="Delete"
218        visible="<%=!configuration.isRemoved()%>"
219        tooltip="<%=deletePermission ? "Delete this plugin configuration" : "You do not have permission to delete this plugin configuration"%>" 
220      />
221      <tbl:button 
222        disabled="<%=writePermission ? false : true%>" 
223        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
224        onclick="restoreItem()" 
225        title="Restore"
226        visible="<%=configuration.isRemoved()%>"
227        tooltip="<%=writePermission ? "Restore this plugin configuration" : "You do not have permission to restore this plugin configuration"%>" 
228      />
229      <tbl:button 
230        disabled="<%=sharePermission ? false : true%>"
231        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
232        onclick="shareItem()" 
233        title="Share&hellip;" 
234        tooltip="<%=sharePermission ? "Share this plugin configuration to other user, groups and projects" : "You do not have permission to share this plugin configuration"%>"
235      />
236      <tbl:button 
237        disabled="<%=setOwnerPermission ? false : true%>"
238        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
239        onclick="setOwner()" 
240        title="Set owner&hellip;"
241        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
242      />
243      <tbl:button 
244        image="import.gif" 
245        onclick="runPlugin('ImportItem')" 
246        title="Import&hellip;" 
247        tooltip="Import data" 
248        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
249      />
250      <tbl:button 
251        image="export.gif" 
252        onclick="runPlugin('ExportItem')" 
253        title="Export&hellip;" 
254        tooltip="Export data" 
255        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
256      />
257      <tbl:button 
258        image="runplugin.gif" 
259        onclick="runPlugin('RunPlugin')" 
260        title="Run plugin&hellip;" 
261        tooltip="Run a plugin" 
262        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
263      />
264      <tbl:button
265        image="runplugin.gif"
266        onclick="configure()"
267        title="Configure&hellip;"
268        tooltip="Configure this plugin"
269        visible="<%=configurable && writePermission%>"
270      />
271      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
272        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
273      <tbl:button
274        image="help.gif"
275        onclick="<%="Main.openHelp('" + ID +"', 'pluginconfiguration.view.properties')"%>"
276        title="Help&hellip;"
277        tooltip="Get help about this page"
278      />
279      </tbl:toolbar>
280    <div class="boxedbottom">
281      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(configuration)%></i></div>
282      <%
283      if (configuration.isRemoved() || configuration.isShared())
284      {
285        %>
286        <div class="itemstatus">
287          <base:icon 
288            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
289            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
290            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
291            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
292          <base:icon image="used.gif" 
293            onclick="showUsingItems()"
294            tooltip="Show the items that are using this one"
295            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
296          <base:icon image="shared.gif" 
297            visible="<%=configuration.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
298        </div>
299        <%
300      }
301      %>
302      <table class="form" cellspacing="0">
303      <tr>
304        <td class="prompt">Name</td>
305        <td><%=HTML.encodeTags(configuration.getName())%></td>
306      </tr>
307      <tr>
308        <td class="prompt">Registered</td>
309        <td><%=dateFormatter.format(configuration.getEntryDate())%></td>
310      </tr>
311      <tr>
312        <td class="prompt">Plugin</td>
313        <td>
314          <%=Base.getLinkedName(ID, nameableProxy, plugin == null, true)%>
315        </td>
316      </tr>
317      <tr>
318        <td class="prompt">Type</td>
319        <td><%=plugin == null ? "<i>- denied -</i>" : plugin.getMainType().toString()%></td>
320      </tr>
321      <tr>
322        <td class="prompt">Owner</td>
323        <td><base:propertyvalue item="<%=configuration%>" property="owner" /></td>
324      </tr>
325      <tr valign="top">
326        <td class="prompt">Description</td>
327        <td><%=HTML.niceFormat(configuration.getDescription())%></td>
328      </tr>
329      </table>
330   
331      <%   
332      // Tables with users/groups/projects that this item is shared to
333      MultiPermissions mp = new MultiPermissions(Collections.singleton(configuration));
334      List<User> users = mp.getUsers().list(dc);
335      List<Group> groups = mp.getGroups().list(dc);
336      List<Project> projects = mp.getProjects().list(dc);
337      int totalShare = users.size() + groups.size() + projects.size();
338     
339      if (totalShare > 0)
340      {
341        %>
342        <base:section
343          id="sharedTo"
344          title="<%="Shared to (" + totalShare + ")"%>"
345          context="<%=cc%>"
346          >
347          <tbl:table 
348            id="itemsSharedTo"
349            clazz="itemlist"
350            columns="all"
351          >
352            <tbl:columndef 
353              id="itemType"
354              title="Item type"
355            />
356            <tbl:columndef 
357              id="name"
358              title="Name"
359            />
360            <tbl:columndef 
361              id="permissions"
362              title="Permissions"
363            />
364            <tbl:data>
365              <tbl:columns>
366              </tbl:columns>
367              <tbl:rows>
368              <%
369              for (Project project : projects)
370              {             
371                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
372                %>     
373                <tbl:row>
374                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
375                  <tbl:cell column="name"><base:icon 
376                    image="deleted.gif" 
377                    tooltip="This item has been scheduled for deletion" 
378                    visible="<%=project.isRemoved()%>"
379                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
380                  <tbl:cell column="permissions">
381                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
382                  </tbl:cell>
383                </tbl:row>
384                <%
385              }
386              for (Group group : groups)
387              {
388                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
389                %>
390                <tbl:row>             
391                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
392                  <tbl:cell column="name"><base:icon 
393                    image="deleted.gif" 
394                    tooltip="This item has been scheduled for deletion" 
395                    visible="<%=group.isRemoved()%>"
396                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
397                  <tbl:cell column="permissions">
398                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
399                  </tbl:cell>
400                </tbl:row>
401                <% 
402              }
403              for (User user : users)
404              {               
405                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
406                %>
407                <tbl:row>             
408                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
409                  <tbl:cell column="name"><base:icon 
410                    image="deleted.gif" 
411                    tooltip="This item has been scheduled for deletion" 
412                    visible="<%=user.isRemoved()%>"
413                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
414                  <tbl:cell column="permissions">
415                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
416                  </tbl:cell>
417                </tbl:row>
418                <%
419              }
420              %>
421              </tbl:rows>
422            </tbl:data>
423          </tbl:table>
424        </base:section>
425        <%
426      }
427      else
428      {
429        %>
430        <h4>Shared to</h4>
431        This configuration is not shared
432        (or, you don't have permission to view the ones it is shared to).
433        <%
434      }
435      %>
436    </div>
437
438      </t:tab>
439     
440      <t:tab id="parameters" title="Configuration parameters" >
441      <div class="boxed">
442      <table class="form" cellspacing="0">
443      <%
444      if (plugin != null)
445      {
446        List<String> names = new java.util.ArrayList<String>(configuration.getParameterNames());
447        if (names == null || names.size() == 0)
448        {
449          %>
450          No parameters has been specified.
451          <%
452        }
453        else
454        {
455          Collections.sort(names);
456          for (String name : names)
457          {
458            StringBuilder sb = new StringBuilder();
459            String displayValue = "";
460            String description = "";
461            try
462            {
463              ParameterInfo pi = configuration.getParameterInfo(name);
464              if (pi.getLabel() != null) name = HTML.encodeTags(pi.getLabel());
465              description = HTML.encodeTags(pi.getDescription());
466              List<?> values = pi.getValues();
467              int i = 0;
468              for (Object value : values)
469              {
470                if (value != null)
471                {
472                  if (i > 0) sb.append(", ");
473                  i++;
474                  if (value instanceof BasicItem)
475                  {
476                    BasicItem item = (BasicItem)value;
477                    String itemName = "";
478                    if (item instanceof File)
479                    {
480                      sb.append(Base.getLinkedFile(ID, (File)item, false, true, true, root));
481                    }
482                    else 
483                    {
484                      if (item instanceof Nameable)
485                      {
486                        itemName = ((Nameable)item).getName();
487                      }
488                      else
489                      {
490                        itemName = item.toString();
491                      }
492                      sb.append(Base.getLink(ID, HTML.encodeTags(itemName), 
493                        item.getType(), item.getId(), item.hasPermission(Permission.WRITE)));
494                    }
495                  }
496                  else if (value instanceof Date)
497                  {
498                    sb.append(dateFormatter.format((Date)value));
499                  }
500                  else
501                  {
502                    sb.append(HTML.encodeTags(value.toString()));
503                  }
504                }
505              }
506              displayValue = sb.toString();
507            }
508            catch (Throwable ex)
509            {
510              displayValue = "<i>ERROR: "+ex.getMessage()+"</i>";
511            }
512            %>
513            <tr>
514              <td class="prompt"><span title="<%=description%>"><%=name%></span></td>
515              <td>
516                <%=displayValue%>
517              </td>
518            </tr>
519            <%
520          }
521        }
522      }
523      %>
524      </table>
525      </div>
526      </t:tab>
527     
528      <t:tab id="annotations" title="Annotations" 
529        tooltip="View annotation values" 
530        visible="<%=plugin != null && plugin.supports("net.sf.basedb.core.plugin.AnnotationSetterPlugin") %>">
531        <div class="boxed">
532        <jsp:include page="../../common/annotations/list_annotations.jsp">
533          <jsp:param name="item_type" value="<%=itemType.name()%>" />
534          <jsp:param name="item_id" value="<%=itemId%>" />
535          <jsp:param name="ID" value="<%=ID%>" />
536        </jsp:include>
537        </div>
538      </t:tab>
539      <t:tab id="history" title="Change history" 
540        tooltip="Displays a log of all modifications made to this item"
541        visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
542        <%
543        if ("history".equals(tab))
544        {
545          %>
546          <jsp:include page="../../common/history/frameset.jsp">
547            <jsp:param name="source_type" value="<%=itemType.name()%>" />
548            <jsp:param name="source_id" value="<%=itemId%>" />
549            <jsp:param name="ID" value="<%=ID%>" />
550          </jsp:include>
551          <%
552        }
553        %>
554      </t:tab>
555      </t:tabcontrol>
556
557  </base:body>
558  </base:page>
559  <%
560}
561finally
562{
563  if (dc != null) dc.close();
564}
565
566%>
Note: See TracBrowser for help on using the repository browser.