source: trunk/www/common/annotations/inherit.jsp @ 6947

Last change on this file since 6947 was 6947, checked in by Nicklas Nordborg, 6 years ago

References #1941: Store experimental factor values as part experiments

Implemented support for inheriting new annotations via the "Inherit" button. The 'Inherited annotations' tab has been removed from all dialogs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.4 KB
Line 
1<%-- $Id: inherit.jsp 6947 2015-09-08 12:30:31Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5  Copyright (C) 2007 Nicklas Nordborg
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 is used to display and modify the attributes of
25  the of a news item
26
27  @author Nicklas
28  @version 2.0
29--%>
30<%@ page pageEncoding="UTF-8" session="false"
31  import="net.sf.basedb.core.SessionControl"
32  import="net.sf.basedb.core.DbControl"
33  import="net.sf.basedb.core.Item"
34  import="net.sf.basedb.core.Type"
35  import="net.sf.basedb.core.BasicItem"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.Annotatable"
38  import="net.sf.basedb.core.AnnotationSet"
39  import="net.sf.basedb.core.Annotation"
40  import="net.sf.basedb.core.RawBioAssay"
41  import="net.sf.basedb.core.PhysicalBioAssay"
42  import="net.sf.basedb.core.DerivedBioAssay"
43  import="net.sf.basedb.core.Extract"
44  import="net.sf.basedb.core.ItemSubtype"
45  import="net.sf.basedb.core.ItemQuery"
46  import="net.sf.basedb.core.Include"
47  import="net.sf.basedb.core.Nameable"
48  import="net.sf.basedb.core.ItemResultList"
49  import="net.sf.basedb.core.AnnotationType"
50  import="net.sf.basedb.core.PermissionDeniedException"
51  import="net.sf.basedb.util.AnnotationUtil"
52  import="net.sf.basedb.core.Subtypable"
53  import="net.sf.basedb.core.query.Orders"
54  import="net.sf.basedb.core.query.Hql"
55  import="net.sf.basedb.core.query.Expressions"
56  import="net.sf.basedb.core.query.Restrictions"
57  import="net.sf.basedb.util.Tree"
58  import="net.sf.basedb.clients.web.Base"
59  import="net.sf.basedb.clients.web.WebException"
60  import="net.sf.basedb.clients.web.util.HTML"
61  import="net.sf.basedb.util.Values"
62  import="net.sf.basedb.util.formatter.Formatter"
63  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
64  import="java.util.List"
65  import="java.util.Set"
66  import="java.util.HashSet"
67  import="java.util.Map"
68  import="java.util.HashMap"
69  import="org.json.simple.JSONArray"
70  import="org.json.simple.JSONObject"
71%>
72<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
73<%!
74private void loadParents(DbControl dc, Set<AnnotationSet> parentAnnotations, Set<Annotatable> parentItems, Annotatable current)
75{
76  Set<Annotatable> parents = AnnotationUtil.getAllAnnotatableParentItems(dc, current, null);
77  for (Annotatable parent : parents)
78  {
79    if (parent != null && parentItems.add(parent))
80    {
81      if (parent.hasPermission(Permission.USE) && parent.isAnnotated())
82      {
83        parentAnnotations.add(parent.getAnnotationSet());
84      }
85    }
86  }
87}
88
89JSONArray generateJoustTree(Set<AnnotationSet> parentAnnotations, Set<AnnotationSet> nonParents, Set<Annotation> inheritedAnnotations)
90{
91  String itemIcon = "Annotatable";
92  String annotationIcon = "Annotation";
93  String parameterIcon = "Parameter";
94  String nonParentIcon = "NonParent";
95  JSONArray json = new JSONArray();
96 
97  for (AnnotationSet as : parentAnnotations)
98  {
99    Annotatable item = null;
100    String itemType = as.getItemType().toString();
101    try
102    {
103      item = as.getItem();
104    }
105    catch (PermissionDeniedException ex)
106    {}
107    if (item instanceof Subtypable)
108    {
109      try
110      {
111        ItemSubtype subtype = ((Subtypable)item).getItemSubtype();
112        if (subtype != null) itemType = subtype.getName();
113      }
114      catch (PermissionDeniedException ex)
115      {}
116    }
117   
118    String icon = nonParents.contains(as) ? nonParentIcon : itemIcon;
119   
120    String joustId = "as-"+as.getId();
121    String input = "<input type=\"checkbox\""+
122      " name=\""+joustId+"\">";
123    String name = item == null ? "<i>- denied -</i>" : 
124      HTML.encodeTags(((Nameable)item).getName()) + " <span class=\"itemsubtype\">(" + itemType + ")</span>";
125   
126    ItemQuery<Annotation> query = as.getAnnotations(Annotation.Source.PRIMARY);
127    query.restrict(Restrictions.eq(Hql.property("annotationType.disableInheritance"), Expressions.bool(false)));
128    List<Annotation> annotations = query.list(as.getDbControl());
129    if (annotations.size() == 0) continue; // With the next AnnotationSet/item
130     
131    JSONObject jsonJoust = null;
132
133    SessionControl sc = as.getSessionControl();
134    for (Annotation a : annotations)
135    {
136      Formatter formatter = FormatterFactory.getAnnotationFormatter(sc, a, null);
137      boolean inherited = inheritedAnnotations != null && inheritedAnnotations.contains(a);
138      if (inherited) continue;
139     
140      if (jsonJoust == null)
141      {
142        jsonJoust = newJoustEntry(null, icon, input+name, joustId);
143        jsonJoust.put("isOpen", 1);
144        jsonJoust.put("type", "annotation-set");
145        jsonJoust.put("externalId", as.getId());
146        json.add(jsonJoust);
147      }
148     
149      AnnotationType at = a.getAnnotationType();
150      String annotationName = at.getName();
151      boolean isParameter = at.isProtocolParameter();
152
153      joustId = "a-"+a.getId();
154      String values = Values.getString(a.getValues(null), ", ", true, formatter);
155      name = HTML.encodeTags(annotationName +
156        " [" + Values.trimString(values, 20)+"]");
157      input = "<input type=\"checkbox\""+
158        " name=\""+joustId+"\""+
159        (inherited ? " checked" : "")+
160        ">";
161     
162      JSONObject jsonAnnotation = newJoustEntry(jsonJoust, isParameter ? parameterIcon : annotationIcon, input+name, joustId);
163      jsonAnnotation.put("type", "annotation");
164      jsonAnnotation.put("externalId", a.getId());
165      jsonAnnotation.put("annotationType", HTML.encodeTags(annotationName));
166      jsonAnnotation.put("values", HTML.encodeTags(values));
167      jsonAnnotation.put("inherited", inherited ? 1 : 0);
168      jsonAnnotation.put("modified", 0);
169    }
170  }
171  return json;
172}
173
174JSONObject newJoustEntry(JSONObject jsonParent, String icon, String text, String id)
175{
176  JSONObject jsonJoust = new JSONObject();
177  jsonJoust.put("icon", icon);
178  jsonJoust.put("text", text);
179  jsonJoust.put("id", id);
180  if (jsonParent != null)
181  {
182    JSONArray jsonChildren = (JSONArray)jsonParent.get("children");
183    if (jsonChildren == null)
184    {
185      jsonChildren = new JSONArray();
186      jsonParent.put("children", jsonChildren);
187    }
188    jsonChildren.add(jsonJoust);
189  }
190  return jsonJoust;
191}
192%>
193<%
194final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
195final String ID = sc.getId();
196final float scale = Base.getScale(sc);
197final Item itemType = Item.valueOf(request.getParameter("item_type"));
198final int itemId = Values.getInt(request.getParameter("item_id"));
199
200//final boolean standalone = Values.getBoolean(request.getParameter("standalone"));
201
202final DbControl dc = sc.newDbControl();
203ItemResultList<AnnotationType> annotationTypes = null;
204try
205{
206  final Annotatable item = itemId == 0 ? null : (Annotatable)itemType.getById(dc, itemId);
207  Set<AnnotationSet> parentAnnotations = new java.util.LinkedHashSet<AnnotationSet>();
208  Set<Annotatable> parentItems = new HashSet<Annotatable>();
209  Set<AnnotationSet> nonParents = new HashSet<AnnotationSet>();
210
211  if (item != null)
212  {
213    // Get all annotated parents and their annotation sets
214    loadParents(dc, parentAnnotations, parentItems, item);
215  }
216
217  String title = "Inherit annotations to " + 
218    HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() : 
219    (item == null ? " new item" : item.toString())));
220
221  // Parent items may have been submitted by caller
222  String[] parents = request.getParameterValues("parents");
223  // Each parameter is ITEMTYPE:ID:ID:...
224  if (parents != null)
225  {
226    for (String parent : parents)
227    {
228      String[] temp = parent.split(":");
229      Item parentType = Item.valueOf(temp[0]);
230      for (int i = 1; i < temp.length; ++i)
231      {
232        int parentId = Values.getInt(temp[i], -1);
233        if (parentId != -1) 
234        {
235          Annotatable parentItem = (Annotatable)parentType.getById(dc, parentId);
236          if (parentItems.add(parentItem))
237          {
238            // This is a new parent
239            if (parentItem.hasPermission(Permission.USE) && parentItem.isAnnotated()) 
240            {
241              parentAnnotations.add(parentItem.getAnnotationSet());
242            }
243            loadParents(dc, parentAnnotations, parentItems, parentItem);
244          }
245        }
246      }
247    }
248  }
249 
250  // Get the currently inherited annotations
251  final AnnotationSet as = item != null && item.isAnnotated() ? item.getAnnotationSet() : null;
252  Set<Annotation> inheritedAnnotations = null;
253 
254  if (as != null)
255  {
256    ItemQuery<Annotation> inheritedQuery = as.getAnnotations(null);
257    inheritedQuery.restrict(
258        Restrictions.neq(
259          Hql.property("source"), 
260          Expressions.integer(Annotation.Source.PRIMARY.ordinal())
261      ));
262   
263    // Ignore annotations marked for DELETE (so it is possible to re-select them)
264    String d = request.getParameter("deleted");
265    if (d != null)
266    {
267      Integer[] deleted = Values.getInt(d.split(","));
268      if (deleted.length > 0)
269      {
270        inheritedQuery.restrict(Restrictions.not(Restrictions.in(Hql.property("id"), Expressions.parameter("deleted"))));
271        inheritedQuery.setParameter("deleted", java.util.Arrays.asList(deleted), Type.INT);
272      }
273    }
274       
275    inheritedQuery.order(Orders.asc(Hql.property("annotationSet")));
276    inheritedQuery.order(Orders.asc(Hql.property("annotationType.name")));
277    inheritedAnnotations = new HashSet<Annotation>();
278    for (Annotation a : inheritedQuery.list(dc))
279    {
280      a = a.getInheritedFrom();
281      if (a != null)
282      {
283        inheritedAnnotations.add(a);
284        AnnotationSet from = a.getAnnotationSet();
285        if (!parentAnnotations.contains(from) && from.hasPermission(Permission.USE))
286        {
287          parentAnnotations.add(from);
288          nonParents.add(from);
289        }
290      }
291    }
292  }
293  JSONArray json = generateJoustTree(parentAnnotations, nonParents, inheritedAnnotations);
294  %>
295  <base:page type="popup" title="Inherit annotations">
296  <base:head  scripts="joust-2.js,~inherit.js" styles="joust-2.css">
297  <style>
298  .selected .itemsubtype
299  {
300    color: #E8E8E8;
301  }
302  </style>
303  </base:head>
304  <base:body>
305   
306  <h1><%=title%> <base:help helpid="annotations.inherit" /></h1>
307  <div class="content bottomborder">
308 
309  <div id="page-data" class="datacontainer"
310    data-callback="<%=HTML.encodeTags(request.getParameter("callback"))%>"
311  ></div>
312 
313  <form name="annotations"> 
314  <div class="absolutefull">
315 
316    <div class="absolutefull bg-filled-100 rightborder" style="width: 28em;">
317   
318      <div class="absolutefull bottomborder" style="height: 2em;">
319      <%
320      if (parentAnnotations.size() > 0) 
321      {
322        %>
323        <table style="width: 100%;">
324        <tr>
325          <td style="padding-left: 4px; padding-right: 4px;"><base:icon image="filter.png"/></td>
326          <td style="width: 100%; padding-top: 1px;">
327            <input type="text" name="quickFilter" id="quickFilter" 
328              class="auto-init" data-auto-init="focus"
329              style="width: calc(100% - 10px);"
330              title="Type to filter annotation types">
331          </td>
332        </table>
333        <%
334      }
335      %>
336      </div>
337      <div class="absolutefull parameterlist" style="top: 2em; bottom: 3em;">
338        <div id="joust" class="joust absolutefull"
339          data-joust-tree="<%=HTML.encodeTags(json.toJSONString()) %>"
340          >
341          <%
342          if (parentAnnotations.size() == 0) 
343          {
344            %>
345            <div class="messagecontainer error" style="margin: 2em;">There are no parent items with annotations.</div>
346            <%
347          }
348          %>
349          <div id="noMatchingFilter" class="messagecontainer error" style="margin: 2em; display: none;">No annotations matches the filter.</div>
350        </div>
351      </div>
352     
353      <div class="absolutefull topborder" style="top: auto; bottom: 0px; height: 3em;">
354        <table style="height: 100%; margin:auto;"><tr><td>
355        <base:icon image="annotation.png" style="vertical-align: text-bottom;"/> = annotation
356        <base:icon image="parameter.png" style="vertical-align: text-bottom;"/> = protocol parameter<br>
357        <base:icon image="item-error.png" style="vertical-align: text-bottom;" /> = not a parent item
358        </td></tr></table>
359      </div>
360   
361    </div>
362   
363    <div class="absolutefull" style="left: 28em; padding: 1em;">
364      <div id="annotationType" style="font-weight: bold;"></div>
365      <div id="annotationValues"></div>
366    </div>
367 
368  </div>
369  </form>
370  </div>
371
372  <base:buttongroup subclass="dialogbuttons">
373    <base:button id="btnOk" title="Ok" />
374    <base:button id="close" title="Cancel" />
375  </base:buttongroup>
376 
377  </base:body>
378  </base:page>
379  <%
380}
381finally
382{
383  if (dc != null) dc.close();
384}
385%>
386
Note: See TracBrowser for help on using the repository browser.