source: trunk/www/views/experiments/bioassaysets/list_bioassaysets.jsp @ 5069

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

References #108: Logging the change history of an item

  • Enabled logging for experiments
  • Added "Change history" tab to experiments, plugin configuration and protocol
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.6 KB
Line 
1<%-- $Id: list_bioassaysets.jsp 5069 2009-08-20 08:53:16Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Nicklas Nordborg
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.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.BasicItem"
32  import="net.sf.basedb.core.Experiment"
33  import="net.sf.basedb.core.BioAssaySet"
34  import="net.sf.basedb.core.Transformation"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Nameable"
37  import="net.sf.basedb.core.ItemResultIterator"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.Permission"
40  import="net.sf.basedb.core.PluginDefinition"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Expressions"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.core.query.Restrictions"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.core.plugin.Plugin"
49  import="net.sf.basedb.util.Tree"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.ChangeHistoryUtil"
52  import="net.sf.basedb.clients.web.ModeInfo"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="java.util.List"
56  import="java.util.ArrayList"
57  import="java.util.LinkedList"
58  import="java.util.Map"
59  import="java.util.HashMap"
60  import="java.util.Iterator"
61  import="java.util.Collection"
62%>
63<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
64<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
65<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
66<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
67<%!
68  private static final Item itemType = Item.BIOASSAYSET;
69  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
70%>
71<%!
72
73private static void addToTree(Tree<BasicItem> tree, BioAssaySet bas)
74{
75  if (!tree.contains(bas))
76  {
77    Transformation transformation = bas.getTransformation();
78    Tree.Entry<BasicItem> parent = tree.getEntry(transformation);
79    if (parent == null) 
80    {
81      addToTree(tree, transformation);
82      parent = tree.getEntry(transformation);
83    }
84    parent.addChild(bas);
85  }
86}
87
88private static void addToTree(Tree<BasicItem> tree, Transformation transformation)
89{
90  if (!tree.contains(transformation))
91  {
92    BioAssaySet source = transformation.getSource();
93    Tree.Entry<BasicItem> parent = tree.getEntry(source);
94    if (parent == null) 
95    {
96      addToTree(tree, source);
97      parent = tree.getEntry(source);
98    }
99    parent.addChild(transformation);
100  }
101}
102
103private static Tree<BasicItem> getAnalysisTree(DbControl dc, ItemQuery<BioAssaySet> bioAssaySetQuery, ItemQuery<Transformation> transformationQuery)
104{
105  Tree<BasicItem> tree = new Tree<BasicItem>(null);
106  ItemResultList<BioAssaySet> allBioAssaySets = bioAssaySetQuery.list(dc);
107  List<Integer> ids = new ArrayList<Integer>(allBioAssaySets.size());
108 
109  for (BioAssaySet bas : allBioAssaySets)
110  {
111    addToTree(tree, bas);
112    ids.add(bas.getId());
113  }
114 
115  transformationQuery.restrict(
116    Restrictions.in(
117      Hql.property("source.id"), 
118      Expressions.parameter("bioAssaySets", ids)
119    )
120  );
121  ItemResultList<Transformation> allTransformations = transformationQuery.list(dc);
122  for (Transformation t: allTransformations)
123  {
124    addToTree(tree, t);
125  }
126  return tree;
127}
128String generateTree(Tree<BasicItem> tree, BasicItem root, Collection<String> closed)
129{
130  StringBuilder sb = new StringBuilder();
131  Tree.Entry<BasicItem> rootEntry = tree.getEntry(root);
132  if (rootEntry == null) return "";
133 
134  List<Tree.Entry<BasicItem>> children = rootEntry.getChildren();
135  if (children != null)
136  {
137    for (Tree.Entry<BasicItem> child : children)
138    {
139      BasicItem node = child.getNode();
140      int id = node.getId();
141      String var = node.getType().name() + "_" + id;
142      String name = ((Nameable)node).getName();
143     
144      String folderIcon = node.getType() == Item.BIOASSAYSET ?
145        "BioAssaySet" : "Transformation";
146      sb.append("var ").append(var);
147      if (root == null)
148      {
149        sb.append(" = JoustMenu.addMenuItem(-1");
150      }
151      else
152      {
153        String rootVar = root.getType().name() + "_" + root.getId();
154        sb.append(" = JoustMenu.addChildItem(").append(rootVar); 
155      }
156      sb.append(",'").append(folderIcon).append("'");
157      sb.append(",'").append(HTML.javaScriptEncode(name)).append("'");
158      sb.append(", null, '', '").append(var).append("');\n");
159      if ((closed == null || !closed.contains(var)) && child.getNumChildren() > 0)
160      {
161        sb.append("JoustMenu.menuItems[").append(var).append("].isOpen = true;\n");
162      }
163      sb.append(generateTree(tree, node, closed));
164    }
165  }
166  return sb.toString();
167}
168%>
169<%
170final int experimentId = Values.getInt(request.getParameter("experiment_id"));
171final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
172final String ID = sc.getId();
173final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
174final ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
175
176final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
177final String callback = request.getParameter("callback");
178final String title = mode.generateTitle("bioassay set", "bioassay sets");
179final DbControl dc = sc.newDbControl();
180Tree<BasicItem> analysisTree = null;
181try
182{
183  final Experiment experiment = Experiment.getById(dc, experimentId);
184  final boolean createPermission = experiment.hasPermission(Permission.WRITE);
185  final boolean deletePermission = createPermission;
186  final boolean writePermission = createPermission;
187
188  final ItemQuery<BioAssaySet> query = Base.getConfiguredQuery(cc, true, experiment.getBioAssaySets(), mode);
189  final ItemQuery<Transformation> transformationQuery = experiment.getTransformations();
190  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
191  try
192  {
193    analysisTree = getAnalysisTree(dc, query, transformationQuery);
194  }
195  catch (Throwable t)
196  {
197    cc.setMessage(t.getMessage());
198  }
199  // Contains the ID:s of the bioassaysets that are closed in the tree
200  Collection<String> closed = (Collection<String>)cc.getObject("closed");
201  int numListed = 0;
202  %>
203  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
204  <base:head scripts="table.js,tabcontrol.js,newjoust.js" styles="table.css,headertabcontrol.css,path.css,newjoust.css">
205    <script language="JavaScript">
206    function switchTab(tabControlId, tabId)
207    {
208      if (tabId == 'properties' || tabId == 'overview' || tabId == 'history')
209      {
210        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=experimentId%>&tab='+tabId;
211      }
212      else
213      {
214        TabControl.setActiveTab(tabControlId, tabId);
215      }
216    }
217    </script>
218  </base:head>
219 
220  <base:body >
221    <p>
222    <p:path>
223      <p:pathelement title="Experiments" href="<%="../index.jsp?ID="+ID%>" />
224      <p:pathelement title="<%=HTML.encodeTags(experiment.getName())%>" />
225    </p:path>
226
227    <t:tabcontrol id="main" active="bioassaysets" switch="switchTab">
228    <t:tab id="properties" title="Properties" />
229   
230    <t:tab id="bioassaysets" title="Bioassay sets">
231   
232      <jsp:include page="analysis_tree.jsp">
233        <jsp:param name="ID" value="<%=ID%>" />
234        <jsp:param name="experiment_id" value="<%=experimentId%>" />
235      </jsp:include>
236   
237    <base:buttongroup align="center">
238      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
239      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
240      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
241    </base:buttongroup>
242    </t:tab>
243    <t:tab id="overview" title="Overview" 
244      tooltip="Display a tree overview of related items" />
245    <t:tab id="history" title="Change history" 
246      tooltip="Displays a log of all modifications made to this item"
247      visible="<%=ChangeHistoryUtil.showChangeHistoryTab(sc)%>" />
248    </t:tabcontrol>
249
250  </base:body>
251  </base:page>
252  <%
253}
254finally
255{
256  if (dc != null) dc.close();
257}
258%>
Note: See TracBrowser for help on using the repository browser.