Changeset 5878


Ignore:
Timestamp:
Nov 17, 2011, 12:41:31 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1616: Clone reporter information to per-experiment tables in the dynamic database

Added a reporter cloning plug-in and buttons in the gui for starting it and for removing the cloned table. The gui probaby need some improvements and it should be possible to get more information about the cloned reporters...

Added permission checks in the ReporterCloneBatcher.

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r5877 r5878  
    776776
    777777  /**
     778    Load an item from the database. If the item is already attached to this
     779    DbControl the same instance is returned, otherwise a new instance is
     780    created an attached to this DbControl.
     781    @param item The item to load
     782    @return An item that is attached to this DbControl (or null if item is null)
     783    @since 3.1
     784  */
     785  @SuppressWarnings("unchecked")
     786  public <I extends BasicItem> I loadItem(I item)
     787  {
     788    if (item == null) return null;
     789    return (I)loadItem(item.getClass(), item.getId());
     790  }
     791 
     792  /**
    778793    Load an item from the database when you now the id. If the item
    779794    has already been loaded the item in the cache will be used.
  • trunk/src/core/net/sf/basedb/core/Experiment.java

    r5877 r5878  
    367367  }
    368368
    369   VirtualDb getVirtualDb()
     369  /**
     370    Get the virtual database ite that is used to manage experiment-specific
     371    tables in the dynamic database for this experiment.
     372    @return A virtual db instance
     373    @since 3.1
     374  */
     375  public VirtualDb getVirtualDb()
    370376  {
    371377    return getDbControl().getItem(VirtualDb.class, getData().getVirtualDb());
  • trunk/src/core/net/sf/basedb/core/ReporterCloneBatcher.java

    r5877 r5878  
    148148    Drop the cloned reporter information from the dynamic database. If the
    149149    current experiment doesn't have any cloned reporters, nothing is done.
     150    @throws PermissionDeniedException If the logged in user does't have
     151      write permission in this experiment
    150152  */
    151153  public void dropClonedReporters()
    152154  {
     155    experiment.checkPermission(Permission.WRITE);
    153156    DbControl dc = getDbControl();
    154157   
     
    177180    If there already is a cloned reporter information it will be removed.
    178181   
     182    @param template The reporter clone template to use
    179183    @param progress An optional progress reporter
    180184    @return The number of cloned reporters
     185    @throws InvalidUseOfNullException If the template is null
     186    @throws PermissionDeniedException If the logged in user does't have
     187      write permission in this experiment or use permission for the template
     188      or read permission for reporters
    181189  */
    182190  public int cloneReporters(ReporterCloneTemplate template, ProgressReporter progress)
    183191  {
     192    if (template == null) throw new InvalidUseOfNullException("template");
     193    // Permission checks
     194    experiment.checkPermission(Permission.WRITE);
     195    template.checkPermission(Permission.USE);
     196    if (!getSessionControl().hasPermission(Permission.READ, Item.REPORTER))
     197    {
     198      throw new PermissionDeniedException(Permission.READ, "Reporter");
     199    }
     200   
    184201    DbControl dc = getDbControl();
    185202   
  • trunk/src/core/net/sf/basedb/core/ReporterCloneTemplate.java

    r5877 r5878  
    209209
    210210  /**
     211    Allow the description to be changed with RESTRICTED_WRITE
     212    permission.
     213  */
     214  @Override
     215  public void setDescription(String description)
     216    throws PermissionDeniedException, InvalidDataException
     217  {
     218    checkPermission(Permission.RESTRICTED_WRITE);
     219    NameableUtil.setDescription(getData(), description);
     220  }
     221 
     222  /**
    211223    If the template is locked it means that it is used by an experiment
    212224    and can't be modified or deleted. Locked templates are managed
  • trunk/src/plugins/core/core-plugins.xml

    r5787 r5878  
    797797  </plugin-definition>
    798798
     799  <plugin-definition id="CloneReportersPlugin">
     800    <about>
     801      <name>Clone reporters</name>
     802      <description>
     803        Clone reporter annotations to a per-experiment storage in the
     804        dynamic database. The cloned table contains only those reporters that
     805        have been used in the experiment and it is also possible to select
     806        a subset of all available reporter annotations (eg. by a template).
     807        After the cloning operation all tools/plug-ins working on the experiment
     808        will use the cloned annotations which protects the analysis from accidental
     809        updates to the main reporter annotations. The cloned reporter annotations
     810        can be removed and/or updated at any time.
     811      </description>
     812    </about>
     813    <plugin-class>net.sf.basedb.plugins.CloneReportersPlugin</plugin-class>
     814    <settings>
     815      <property name="everyone-use">1</property>
     816    </settings>
     817  </plugin-definition>
     818
    799819  <!--
    800820  <plugin-definition id="">
  • trunk/www/admin/reporterclonetemplates/index.jsp

    r5877 r5878  
    5757<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    5858<%!
    59   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,description");
     59  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,properties,description");
    6060  private static final Item itemType = Item.REPORTERCLONETEMPLATE;
    6161%>
  • trunk/www/admin/reporterclonetemplates/list_templates.jsp

    r5877 r5878  
    2121
    2222--%>
     23<%@page import="net.sf.basedb.core.ClonedProperty"%>
    2324<%@ page pageEncoding="UTF-8" session="false"
    2425  import="net.sf.basedb.core.SessionControl"
     
    8384  {
    8485    final ItemQuery<ReporterCloneTemplate> query = Base.getConfiguredQuery(dc, cc, true, ReporterCloneTemplate.getQuery(), mode);
     86    query.join(Hql.leftJoin("properties", "prp"));
     87    query.setDistinct(true);
    8588    templates = query.iterate(dc);
    8689  }
     
    225228        filterable="true"
    226229        exportable="true"
     230      />
     231      <%
     232      Enumeration<String, String> allProperties = new Enumeration<String, String>();
     233      for (ClonedProperty cp : ClonedProperty.getAll())
     234      {
     235        allProperties.add(cp.getTitle(), cp.getTitle());
     236      }
     237      %>
     238      <tbl:columndef
     239        id="properties"
     240        property="$prp.title"
     241        datatype="string"
     242        title="Properties"
     243        filterable="true"
     244        enumeration="<%=allProperties %>"
    227245      />
    228246      <tbl:columndef
     
    438456                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
    439457                  /></tbl:cell>
     458                <tbl:cell column="properties">
     459                  <%
     460                  String separator = "";
     461                  for (ClonedProperty cp : item.getClonedProperties())
     462                  {
     463                    out.write(separator);
     464                    separator = ", ";
     465                    out.write(HTML.encodeTags(cp.getTitle()));
     466                  }
     467                  %>
     468                </tbl:cell>
    440469                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    441470                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
  • trunk/www/views/experiments/index.jsp

    r5590 r5878  
    3636  import="net.sf.basedb.core.User"
    3737  import="net.sf.basedb.core.Directory"
     38  import="net.sf.basedb.core.ReporterCloneTemplate"
     39  import="net.sf.basedb.core.ReporterCloneBatcher"
     40  import="net.sf.basedb.core.PluginDefinition"
     41  import="net.sf.basedb.core.Job"
     42  import="net.sf.basedb.core.ItemParameterType"
    3843  import="net.sf.basedb.core.ItemQuery"
    3944  import="net.sf.basedb.core.ItemResultIterator"
     
    4651  import="net.sf.basedb.core.SimpleProgressReporter"
    4752  import="net.sf.basedb.core.snapshot.SnapshotManager"
     53  import="net.sf.basedb.plugins.CloneReportersPlugin"
    4854  import="net.sf.basedb.util.RemovableUtil"
    4955  import="net.sf.basedb.util.ShareableUtil"
     
    407413    redirect = viewPage;
    408414  }
     415  else if ("CloneReporters".equals(cmd))
     416  {
     417    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
     418    final int maxRecent = Base.getMaxRecent(sc);
     419   
     420    dc = sc.newDbControl();
     421    ReporterCloneTemplate template = ReporterCloneTemplate.getById(dc, Values.getInt(request.getParameter("reporterclonetemplate_id")));
     422    cc.setRecent(template, maxRecent);
     423   
     424    Experiment exp = Experiment.getById(dc, Values.getInt(itemId));
     425   
     426    PluginDefinition clonePlugin = PluginDefinition.getByClassName(dc, CloneReportersPlugin.class.getName());
     427    Job cloneJob = Job.getNew(dc, clonePlugin, null, exp);
     428    cloneJob.setName("Cloning reporters using template '" + template.getName() + "'");
     429    cloneJob.setDescription(Values.getStringOrNull(request.getParameter("description")));
     430    cloneJob.setParameterValue("template", "Reporter clone template", null,
     431      new ItemParameterType<ReporterCloneTemplate>(ReporterCloneTemplate.class, null), template);
     432    dc.saveItem(cloneJob);
     433    dc.commit();
     434   
     435    redirect = "../jobs/index.jsp?ID=" + ID + "&cmd=ViewItem&item_id="+cloneJob.getId();
     436  }
     437  else if ("RemoveClonedReporters".equals(cmd))
     438  {
     439   
     440    dc = sc.newDbControl();
     441    Experiment exp = Experiment.getById(dc, Values.getInt(itemId));
     442    ReporterCloneBatcher batcher = exp.getReporterCloneBatcher(dc);
     443    batcher.dropClonedReporters();
     444    dc.commit();
     445   
     446    message = "The cloned reporter annotations has been removed";
     447   
     448  }
    409449  else
    410450  {
  • trunk/www/views/experiments/view_experiment.jsp

    r5877 r5878  
    2424  @version 2.0
    2525--%>
     26<%@page import="net.sf.basedb.core.VirtualTable"%>
    2627<%@ page pageEncoding="UTF-8" session="false"
    2728  import="net.sf.basedb.core.SessionControl"
     
    3132  import="net.sf.basedb.core.Permission"
    3233  import="net.sf.basedb.core.Experiment"
     34  import="net.sf.basedb.core.VirtualDb"
    3335  import="net.sf.basedb.core.RawBioAssay"
    3436  import="net.sf.basedb.core.AnnotationType"
     
    103105  String title = null;
    104106  Experiment experiment = Experiment.getById(dc, itemId);
     107  VirtualDb virtualDb = experiment.getVirtualDb();
    105108 
    106109  final boolean writePermission = experiment.hasPermission(Permission.WRITE);
     
    273276      frm.submit();
    274277    }
     278    function cloneReporters()
     279    {
     280      Main.openPopup('clone_reporters.jsp?ID=<%=ID%>&item_id=<%=itemId%>', 'CloneReporters', 600, 500);
     281    }
     282    function removeClonedReporters()
     283    {
     284      if (confirm('Are you sure that you want to remove all cloned reporter annotations?\nThis action can\'t be undone.'))
     285      {
     286        Main.openPopup('index.jsp?ID=<%=ID%>&cmd=RemoveClonedReporters&item_id=<%=itemId%>', 'RemoveClonedReporters', 400, 300);
     287      }
     288    }
    275289    </script>
    276290  </base:head>
     
    323337        title="Set owner&hellip;"
    324338        tooltip="<%=setOwnerPermission ? "Change owner of this item" : "You do not have permission to change ownership of this item"%>"
     339      />
     340      <tbl:button
     341        visible="<%=writePermission && virtualDb.hasTable(VirtualTable.POSITION) %>"
     342        image="copy.gif"
     343        onclick="cloneReporters()"
     344        title="Clone reporters&hellip;"
     345        tooltip="Clone reporter annotations for all reporters that are used in this experiment"
     346      />
     347      <tbl:button
     348        visible="<%=writePermission && virtualDb.hasClonedReporters() %>"
     349        image="delete_permanently.png"
     350        onclick="removeClonedReporters()"
     351        title="Remove cloned reporters&hellip;"
     352        tooltip="Remove all cloned reporter annotations"
    325353      />
    326354      <tbl:button
Note: See TracChangeset for help on using the changeset viewer.