source: trunk/www/admin/protocols/view_protocol.jsp @ 5249

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

Fixes #1309: externalId for protocols

Added to the web interface and batch importers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.7 KB
Line 
1<%-- $Id: view_protocol.jsp 5249 2010-02-17 12:38:58Z 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.Permission"
34  import="net.sf.basedb.core.Protocol"
35  import="net.sf.basedb.core.ProtocolType"
36  import="net.sf.basedb.core.AnnotationType"
37  import="net.sf.basedb.core.File"
38  import="net.sf.basedb.core.User"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.PluginDefinition"
41  import="net.sf.basedb.core.ItemQuery"
42  import="net.sf.basedb.core.ItemResultList"
43  import="net.sf.basedb.core.Include"
44  import="net.sf.basedb.core.MultiPermissions"
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.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
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.formatter.Formatter"
55  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
56  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
57  import="net.sf.basedb.clients.web.extensions.JspContext"
58  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
59  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
60  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
61  import="java.util.Date"
62  import="net.sf.basedb.util.Values"
63  import="java.util.Collections"
64  import="java.util.Map"
65  import="java.util.Set"
66%>
67<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
68<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
69<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
70<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
71<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
72<%!
73  private static final Item itemType = Item.PROTOCOL;
74  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.ITEM);
75%>
76<%
77final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
78final String ID = sc.getId();
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80final int itemId = cc.getId();
81final String tab = Values.getString(request.getParameter("tab"), "properties");
82final float scale = Base.getScale(sc);
83final DbControl dc = sc.newDbControl();
84try
85{
86  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
87  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
88
89  String title = null;
90  Protocol protocol = Protocol.getById(dc, itemId);
91 
92  final boolean writePermission = protocol.hasPermission(Permission.WRITE);
93  final boolean deletePermission = protocol.hasPermission(Permission.DELETE);
94  final boolean sharePermission = protocol.hasPermission(Permission.SET_PERMISSION);
95  final boolean setOwnerPermission = protocol.hasPermission(Permission.SET_OWNER);
96  final boolean isRemoved = protocol.isRemoved();
97  final boolean isUsed = isRemoved && protocol.isUsed();
98  final boolean deletePermanentlyPermission = deletePermission && !isUsed;
99  final boolean isOwner = protocol.isOwner();
100  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, protocol);
101  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
102  %>
103  <base:page title="<%=title%>">
104  <base:head scripts="tabcontrol.js,table.js" styles="toolbar.css,headertabcontrol.css,path.css,table.css">
105    <ext:scripts context="<%=jspContext%>" />
106    <ext:stylesheets context="<%=jspContext%>" />
107    <script language="JavaScript">
108    function editItem()
109    {
110      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, true);
111    }
112    function shareItem()
113    {
114      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id=<%=itemId%>', 'ShareProtocol', 600, 400);
115    }
116    function deleteItem()
117    {
118      location.replace('index.jsp?ID=<%=ID%>&cmd=DeleteItem&item_id=<%=itemId%>');
119    }
120    function restoreItem()
121    {
122      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
123    }
124    function deleteItemPermanently()
125    {
126      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', <%=itemId%>, '&callback=itemDeleted');
127    }
128    function itemDeleted()
129    {
130      Main.listItems('<%=ID%>', '<%=itemType.name()%>');
131    }
132    function showUsingItems()
133    {
134      Main.showUsingItems('<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
135    }
136    function setOwner()
137    {
138      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=SetOwnerOfItem&item_id=<%=itemId%>', 'SetOwnerOfItem', 450, 150);
139    }
140    function runPlugin(cmd)
141    {
142      Main.openPopup('index.jsp?ID=<%=ID%>&cmd='+cmd+'&item_id=<%=itemId%>', 'RunPlugin'+cmd, 740, 540);
143    }
144    function switchTab(tabControlId, tabId)
145    {
146      if (TabControl.isActive(tabControlId, tabId)) return;
147      if (tabId == 'history' && tabId != '<%=tab%>')
148      {
149        location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=itemId%>&tab='+tabId;
150      }
151      else
152      {
153        TabControl.setActiveTab(tabControlId, tabId);
154      }
155    }
156    </script>
157  </base:head>
158  <base:body>
159    <p>
160    <p:path>
161      <p:pathelement title="Protocols" href="<%="index.jsp?ID="+ID%>" />
162      <p:pathelement title="<%=HTML.encodeTags(protocol.getName())%>" />
163    </p:path>
164   
165    <t:tabcontrol id="main" active="<%=tab%>" switch="switchTab" remember="false">
166    <t:tab id="properties" title="Properties">
167   
168    <tbl:toolbar
169      >
170      <tbl:button 
171        disabled="<%=writePermission ? false : true%>" 
172        image="<%=writePermission ? "edit.gif" : "edit_disabled.gif"%>" 
173        onclick="editItem()" 
174        title="Edit&hellip;" 
175        tooltip="<%=writePermission ? "Edit this protocol" : "You do not have permission to edit this protocol"%>" 
176      />
177      <tbl:button 
178        disabled="<%=deletePermission ? false : true%>" 
179        image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
180        onclick="deleteItem()" 
181        title="Delete"
182        visible="<%=!protocol.isRemoved()%>"
183        tooltip="<%=deletePermission ? "Delete this protocol" : "You do not have permission to delete this protocol"%>" 
184      />
185      <tbl:button 
186        disabled="<%=writePermission ? false : true%>" 
187        image="<%=writePermission ? "restore.gif" : "restore_disabled.gif"%>" 
188        onclick="restoreItem()" 
189        title="Restore"
190        visible="<%=protocol.isRemoved()%>"
191        tooltip="<%=writePermission ? "Restore this protocol" : "You do not have permission to restore this protocol"%>" 
192      />
193      <tbl:button 
194        disabled="<%=sharePermission ? false : true%>"
195        image="<%=sharePermission ? "share.gif" : "share_disabled.gif"%>"
196        onclick="shareItem()" 
197        title="Share&hellip;" 
198        tooltip="<%=sharePermission ? "Share this protocol to other user, groups and projects" : "You do not have permission to share this protocol"%>"
199      />
200      <tbl:button 
201        disabled="<%=setOwnerPermission ? false : true%>"
202        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
203        onclick="setOwner()" 
204        title="Set owner&hellip;"
205        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
206      />
207      <tbl:button 
208        image="import.gif" 
209        onclick="runPlugin('ImportItem')" 
210        title="Import&hellip;" 
211        tooltip="Import data" 
212        visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
213      />
214      <tbl:button 
215        image="export.gif" 
216        onclick="runPlugin('ExportItem')" 
217        title="Export&hellip;" 
218        tooltip="Export data" 
219        visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
220      />
221      <tbl:button 
222        image="runplugin.gif" 
223        onclick="runPlugin('RunPlugin')" 
224        title="Run plugin&hellip;" 
225        tooltip="Run a plugin" 
226        visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
227      />
228      <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
229        wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
230      <tbl:button
231        image="help.gif"
232        onclick="<%="Main.openHelp('" + ID +"', 'protocol.view.properties')"%>"
233        title="Help&hellip;"
234        tooltip="Get help about this page"
235      />
236      </tbl:toolbar>
237    <div class="boxedbottom">
238      <div class="itemstatus">Permissions on this item: <i><%=PermissionUtil.getFullPermissionNames(protocol)%></i></div>
239      <%
240      if (protocol.isRemoved() || protocol.isShared())
241      {
242        %>
243        <div class="itemstatus">
244          <base:icon 
245            image="<%=deletePermanentlyPermission ? "deleted.gif" : "deleted_disabled.gif"%>"
246            onclick="<%=deletePermanentlyPermission ? "deleteItemPermanently()" : null%>"
247            tooltip="<%=deletePermanentlyPermission ? "Permanently delete this item" : null%>"
248            visible="<%=isRemoved%>"> This item has been flagged for deletion<br></base:icon>
249          <base:icon image="used.gif" 
250            onclick="showUsingItems()"
251            tooltip="Show the items that are using this one"
252            visible="<%=isUsed%>"> This item is used by other items and can't be permanently deleted<br></base:icon>
253          <base:icon image="shared.gif" 
254            visible="<%=protocol.isShared()%>"> This item is shared to other users, groups and/or projects</base:icon>
255        </div>
256        <%
257      }
258      %>
259      <table class="form" cellspacing="0">
260      <tr>
261        <td class="prompt">Name</td>
262        <td><%=HTML.encodeTags(protocol.getName())%></td>
263      </tr>
264      <tr>
265        <td class="prompt">Type</td>
266        <td><base:propertyvalue item="<%=protocol%>" property="protocolType" /></td>
267      </tr>
268      <tr>
269        <td class="prompt">External ID</td>
270        <td><%=HTML.encodeTags(protocol.getExternalId())%></td>
271      </tr>
272      <tr>
273        <td class="prompt">Registered</td>
274        <td><%=dateFormatter.format(protocol.getEntryDate())%></td>
275      </tr>
276      <tr>
277        <td class="prompt">File</td>
278        <td><base:propertyvalue item="<%=protocol%>" property="file" /></td>
279      </tr>
280      <tr>
281        <td class="prompt">Owner</td>
282        <td><base:propertyvalue item="<%=protocol%>" property="owner" /></td>
283      </tr>
284      <tr>
285        <td class="prompt">Description</td>
286        <td><%=HTML.niceFormat(protocol.getDescription())%></td>
287      </tr>
288      </table>
289
290      <%
291      ItemQuery<AnnotationType> parameterQuery = protocol.getParameters();
292      parameterQuery.include(Include.ALL);
293      parameterQuery.order(Orders.asc(Hql.property("name")));
294      ItemResultList<AnnotationType> parameters = parameterQuery.list(dc);
295      if (parameters.size() == 0)
296      {
297        %>
298        <h4>Parameters</h4>
299        No parameters has been added to this protocol
300        (or, you don't have permission to view them).
301        <%
302      }
303      else
304      {
305        %>
306        <base:section
307          id="parameters"
308          title="<%="Parameters (" + parameters.size() + ")"%>"
309          context="<%=cc%>"
310          >       
311          <tbl:table
312            id="parameters"
313            clazz="itemlist"
314            columns="all"
315            >
316          <tbl:columndef 
317            id="name"
318            title="Name"
319          />
320          <tbl:columndef
321            id="values"
322            title="Values"
323          />
324          <tbl:columndef 
325            id="description"
326            title="Description"
327          />
328          <tbl:data>
329            <tbl:columns>
330            </tbl:columns>
331            <tbl:rows>
332            <%
333            for (AnnotationType item : parameters)
334            {
335              %>
336              <tbl:row>
337                <tbl:cell column="name"><base:icon 
338                    image="deleted.gif" 
339                    tooltip="This item has been scheduled for deletion" 
340                    visible="<%=item.isRemoved()%>"
341                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
342                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
343                <tbl:cell column="values">
344                <%=item.isEnumeration() ? 
345                  "Enumeration: " + HTML.encodeTags(Values.getString(item.getValues(), ", ", true)) :
346                  item.getValueType()%>
347                </tbl:cell>
348              </tbl:row>
349              <%
350            }
351            %>
352            </tbl:rows>
353          </tbl:data>
354          </tbl:table>
355        </base:section>
356        <%
357      }     
358     
359      // Tables with users/groups/projects that this item is shared to
360      MultiPermissions mp = new MultiPermissions(Collections.singleton(protocol));
361      ItemResultList<User> users = mp.getUsers().list(dc);
362      ItemResultList<Group> groups = mp.getGroups().list(dc);
363      ItemResultList<Project> projects = mp.getProjects().list(dc);
364      int totalShare = (users.size() + groups.size() + projects.size());
365      if (totalShare > 0)
366      {
367        %>
368        <base:section 
369          id="sharedTo" 
370          title="<%="Shared to (" + totalShare + ")"%>"
371          context="<%=cc%>"
372          >       
373          <tbl:table 
374            id="itemsSharedTo"
375            clazz="itemlist"
376            columns="all"
377          >
378            <tbl:columndef 
379              id="itemType"
380              title="Item type"
381            />
382            <tbl:columndef 
383              id="name"
384              title="Name"
385            />
386            <tbl:columndef 
387              id="permissions"
388              title="Permissions"
389            />
390            <tbl:data>
391              <tbl:columns>
392              </tbl:columns>
393              <tbl:rows>
394              <%
395              for (Project project : projects)
396              {
397                Set<Permission> permissions = mp.getPermissions(project).values().iterator().next();
398                %>     
399                <tbl:row>
400                  <tbl:cell column="itemType"><%=project.getType()%></tbl:cell>
401                  <tbl:cell column="name"><base:icon 
402                    image="deleted.gif" 
403                    tooltip="This item has been scheduled for deletion" 
404                    visible="<%=project.isRemoved()%>"
405                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
406                  <tbl:cell column="permissions">
407                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
408                  </tbl:cell>
409                </tbl:row>
410                <%
411              }
412              for (Group group : groups)
413              {
414                Set<Permission> permissions = mp.getPermissions(group).values().iterator().next();
415                %>
416                <tbl:row>             
417                  <tbl:cell column="itemType"><%=group.getType()%></tbl:cell>
418                  <tbl:cell column="name"><base:icon 
419                    image="deleted.gif" 
420                    tooltip="This item has been scheduled for deletion" 
421                    visible="<%=group.isRemoved()%>"
422                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
423                  <tbl:cell column="permissions">
424                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
425                  </tbl:cell>
426                </tbl:row>
427                <% 
428              }
429              for (User user : users)
430              {
431                Set<Permission> permissions = mp.getPermissions(user).values().iterator().next();
432                %>
433                <tbl:row>             
434                  <tbl:cell column="itemType"><%=user.getType()%></tbl:cell>
435                  <tbl:cell column="name"><base:icon 
436                    image="deleted.gif" 
437                    tooltip="This item has been scheduled for deletion" 
438                    visible="<%=user.isRemoved()%>"
439                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
440                  <tbl:cell column="permissions">
441                    <%=PermissionUtil.translatePermissionsToString(permissions)%>
442                  </tbl:cell>
443                </tbl:row>
444                <%
445              }
446              %>
447              </tbl:rows>
448            </tbl:data>
449          </tbl:table>
450        </base:section>
451        <%
452      }
453      else
454      {
455        %>
456        <h4>Shared to</h4>
457        This protocol is not shared
458        (or, you don't have permission to view the ones it is shared to).
459        <%
460      }
461      %> 
462    </div>
463    </t:tab>
464     
465    <t:tab id="annotations" title="Annotations" 
466      tooltip="View annotation values">
467      <div class="boxed">
468      <jsp:include page="../../common/annotations/list_annotations.jsp">
469        <jsp:param name="item_type" value="<%=itemType.name()%>" />
470        <jsp:param name="item_id" value="<%=itemId%>" />
471        <jsp:param name="ID" value="<%=ID%>" />
472      </jsp:include>
473      </div>
474    </t:tab>
475    <t:tab id="history" title="Change history" 
476      tooltip="Displays a log of all modifications made to this item"
477      visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>">
478      <%
479      if ("history".equals(tab))
480      {
481        %>
482        <jsp:include page="../../common/history/frameset.jsp">
483          <jsp:param name="source_type" value="<%=itemType.name()%>" />
484          <jsp:param name="source_id" value="<%=itemId%>" />
485          <jsp:param name="ID" value="<%=ID%>" />
486        </jsp:include>
487        <%
488      }
489      %>
490    </t:tab>
491    </t:tabcontrol>
492
493  </base:body>
494  </base:page>
495  <%
496}
497finally
498{
499  if (dc != null) dc.close();
500}
501
502%>
Note: See TracBrowser for help on using the repository browser.