source: trunk/www/common/annotations/index.jsp @ 6694

Last change on this file since 6694 was 6694, checked in by Nicklas Nordborg, 9 years ago

References #1908: Batch inheriting multiple annotations

Added InheritAnnotationsManager, InheritSpecification and a few other changes.

A test case has been implemented from the raw bioassays lists page which allows the user to select one or more annotation types to inherit to the selected raw bioassays. It is possible to select if existing inherited annotations should be removed or if new annotations should be inherited. For each annotation type is possible to select the parent type to inherit from (to avoid duplicate inheritance).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 5.8 KB
Line 
1<%-- $Id: index.jsp 6694 2015-01-26 14:41:25Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.BasicItem"
31  import="net.sf.basedb.core.AnnotatedItem"
32  import="net.sf.basedb.core.Annotation"
33  import="net.sf.basedb.core.AnnotationType"
34  import="net.sf.basedb.core.Annotatable"
35  import="net.sf.basedb.core.ItemSubtype"
36  import="net.sf.basedb.core.BaseException"
37  import="net.sf.basedb.core.SimpleProgressReporter"
38  import="net.sf.basedb.core.snapshot.SnapshotManager"
39  import="net.sf.basedb.util.annotations.RunnableInheritAnnotationsManager"
40  import="net.sf.basedb.util.annotations.InheritAnnotationsManager"
41  import="net.sf.basedb.util.annotations.InheritSpecification"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.WebException"
44  import="net.sf.basedb.util.Values"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="java.util.Set"
47  import="java.util.List"
48  import="java.util.ArrayList"
49 
50 
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
54
55<%
56final String root = request.getContextPath()+"/";
57final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
58final String ID = sc.getId();
59final String cmd = request.getParameter("cmd");
60final int itemId = Values.getInt(request.getParameter("item_id"));
61
62DbControl newDc = null;
63DbControl oldDc = null;
64String forward = null;
65String message = null;
66String redirect = null;
67try
68{
69  if ("EditItem".equals(cmd))
70  {
71    newDc = sc.newDbControl();
72    Annotation a = Annotation.getById(newDc, itemId);
73    AnnotationType at = a.getAnnotationType();
74    Annotatable item = a.getAnnotationSet().getItem();
75   
76    redirect = "annotate.jsp?ID=" + ID + "&item_id=" + item.getId() + 
77        "&item_type=" + item.getType().name() + 
78        "&annotationtype_id=" + at.getId() + "&standalone=1";
79    newDc.close();
80  }
81  else if ("SaveAnnotations".equals(cmd))
82  {
83    final Item itemType = Item.valueOf(request.getParameter("item_type"));
84    newDc = sc.newDbControl();
85    oldDc = sc.newDbControl();
86    ItemContext cc = sc.getCurrentContext(itemType);
87    Annotatable oldItem = (Annotatable)cc.getObject("item");
88    Annotatable newItem = (Annotatable)itemType.getById(newDc, itemId);
89    oldDc.reattachItem((BasicItem)oldItem, false);
90    Base.updateAnnotations(newDc, oldItem, newItem, request);
91    oldDc.close();
92    newDc.commit();
93    cc.removeObject("item");
94    message = "Annotations saved";
95  }
96  else if ("BatchInherit".equals(cmd))
97  {
98    final Item itemType = Item.valueOf(request.getParameter("item_type"));
99    final String subContext = Values.getString(request.getParameter("subcontext"), "");
100    final ItemContext cc = sc.getCurrentContext(itemType, subContext);
101   
102    newDc = sc.newDbControl();
103
104    Set<AnnotatedItem> items = (Set<AnnotatedItem>)cc.getObject("AnnotatedItems");
105    cc.removeObject("AnnotatedItems");
106   
107    RunnableInheritAnnotationsManager manager = new RunnableInheritAnnotationsManager(sc);
108    manager.addAllItems(items);
109   
110    for (Integer atId : Values.getInt(request.getParameter("annotationTypes").split(",")))
111    {
112      AnnotationType at = AnnotationType.getById(newDc, atId);
113      InheritSpecification spec = new InheritSpecification(at);
114      String action = request.getParameter("action_"+atId);
115     
116      if ("remove".equals(action))
117      {
118        spec.setRemove(true);
119      }
120      else
121      {
122        int subtypeId = Values.getInt(request.getParameter("from_"+atId));
123        boolean noDup = Values.getBoolean(request.getParameter("nodup_"+atId));
124        boolean replaceExisting = Values.getBoolean(request.getParameter("replace_"+atId));
125        if (subtypeId != 0)
126        {
127          spec.setItemSubtype(ItemSubtype.getById(newDc, subtypeId));
128        }
129        spec.setNoDuplicates(noDup);
130        spec.setReplaceExisting(replaceExisting);
131      }
132      manager.addSpecification(spec);
133     
134      //System.out.println("at:" + atId + "; " + action + "; from=" + from + "; noDup="+noDup + "; replace="+replaceExisting);
135    }
136    newDc.commit();
137   
138    SimpleProgressReporter progress = new SimpleProgressReporter(null);
139    sc.setSessionSetting("progress.inherit-annotations", progress);
140    manager.setProgressReporter(progress);
141    new Thread(manager).start();
142   
143    redirect = "../../common/progress_reporter.jsp?ID="+ID+
144      "&progress=inherit-annotations&title=Inheriting annotations to " + items.size() + " items";
145
146  }
147  else
148  {
149    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
150  }
151}
152finally
153{
154  if (oldDc != null) oldDc.close();
155  if (newDc != null) newDc.close();
156}
157
158if (forward != null)
159{
160  sc.setSessionSetting("alert-message", message);
161  pageContext.forward(forward);
162}
163else if (redirect != null)
164{
165  sc.setSessionSetting("alert-message", message);
166  response.sendRedirect(redirect);
167}
168else if (message == null)
169{
170  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
171}
172else
173{
174  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
175}
176%>
177
Note: See TracBrowser for help on using the repository browser.