Changeset 4305


Ignore:
Timestamp:
May 21, 2008, 1:11:20 PM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #1015: Add reporter list from tables that list reporters/reporter info

It is now possible to create reporter lists from features, wells and raw data, eg. all DataQuery?-based item types. Creating the lists using queries from the dynamic database needs a different solution.

Location:
trunk
Files:
15 edited

Legend:

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

    r4302 r4305  
    7272
    7373  /**
    74     The item type returned by the query.
    75   */
    76   private final Item itemType;
     74    The item type returned by the query, eg.
     75    SELECT [returnType] FROM ...
     76  */
     77  private final Item returnType;
     78 
     79  /**
     80    The root item type we start with in the query. eq.
     81    SELECT ... FROM [rootTypeTable]
     82    @since 2.8
     83  */
     84  private final Item rootType;
    7785 
    7886  /**
     
    134142    Create a new query returning items of the specified item type
    135143    using the default optional runtime filter.
    136     @param itemType The type of items that are returned
     144    @param returnType The type of items that are returned
     145    @param entityName The name of the type of items as known to
     146      Hibernate, or null to use the class of the return type
    137147    @param stateless TRUE if the stateless Hibernate session should be used, FALSE
    138148      if the regular Hibernate session should be used
    139149  */
    140   AbstractEntityQuery(Item itemType, String entityName, boolean stateless)
    141   {
    142     this(itemType, entityName, stateless, QueryRuntimeFilterFactory.getOptionalFilter(itemType));
     150  AbstractEntityQuery(Item returnType, String entityName, boolean stateless)
     151  {
     152    this(returnType, returnType, entityName, null, stateless,
     153        QueryRuntimeFilterFactory.getOptionalFilter(returnType));
    143154  }
    144155 
     
    146157    Create a new query returning items of the specified type with a non-default
    147158    optional runtime filter.
    148     @param itemType The type of items that are returned
     159    @param returnType The type of items that are returned
     160    @param entityName The name of the type of items as known to
     161      Hibernate, or null to use the class of the return type
    149162    @param stateless TRUE if the stateless Hibernate session should be used, FALSE
    150163      if the regular Hibernate session should be used
     
    152165      or null to not use any optional filter
    153166  */
    154   AbstractEntityQuery(Item itemType, String entityName, boolean stateless, QueryRuntimeFilter optionalFilter)
    155   {
    156     super(entityName == null ? itemType.getDataClass().getName() : entityName);
    157     this.itemType = itemType;
     167  AbstractEntityQuery(Item returnType, String entityName, boolean stateless, QueryRuntimeFilter optionalFilter)
     168  {
     169    this(returnType, returnType, entityName, null, stateless, optionalFilter);
     170  }
     171
     172  /**
     173    Create a new query that may have different return type and root item type.
     174
     175    @see DataQuery#DataQuery(Class, Item, String, String)
     176    @since 2.8
     177  */
     178  AbstractEntityQuery(Item returnType, Item rootType, String rootName, String select,
     179      boolean stateless, QueryRuntimeFilter optionalFilter)
     180  {
     181    super(rootName == null ? rootType.getDataClass().getName() : rootName);
     182    super.selectPermanent(Selects.expression(Hql.property(rootType.getAlias(), select), null, true));
     183    this.returnType = returnType;
     184    this.rootType = rootType;
    158185    this.stateless = stateless;
    159     this.requiredFilter = QueryRuntimeFilterFactory.getRequiredFilter(itemType);
     186    this.requiredFilter = QueryRuntimeFilterFactory.getRequiredFilter(rootType);
    160187    this.optionalFilter = optionalFilter;
    161     super.selectPermanent(Selects.expression(Hql.alias(itemType.getAlias()), null, true));
    162188    this.includes = EnumSet.of(Include.NOT_REMOVED, Include.MINE, Include.IN_PROJECT,
    163       Include.ANNOTATED, Include.NOT_ANNOTATED);
     189        Include.ANNOTATED, Include.NOT_ANNOTATED);
    164190    this.permission = Permission.READ;
    165191    setAutoJoinType(JoinType.LEFT);
    166192  }
    167 
    168193 
    169194  /*
     
    231256 
    232257  /**
    233     The alias of the item that is returned by this query.
     258    The alias of the item that is the root of this query.
    234259    @see Item#getAlias()
    235260  */
    236261  public String getRootAlias()
    237262  {
    238     return itemType.getAlias();
     263    return rootType.getAlias();
    239264  }
    240265 
     
    299324  public Item getItemType()
    300325  {
    301     return itemType;
     326    return returnType;
     327  }
     328  /**
     329    @since 2.8
     330  */
     331  public Item getRootType()
     332  {
     333    return rootType;
    302334  }
    303335  public void include(Include... includes)
  • trunk/src/core/net/sf/basedb/core/ArrayDesign.java

    r4257 r4305  
    2929import net.sf.basedb.core.data.ArrayDesignPlateData;
    3030import net.sf.basedb.core.data.FeatureData;
     31import net.sf.basedb.core.data.ReporterData;
    3132import net.sf.basedb.core.query.Hql;
    3233import net.sf.basedb.core.query.Restrictions;
     
    777778
    778779  /**
     780    Get a query that returns the reporters on this array design. The query
     781    is rooted at the features, which means that:
     782    <ul>
     783    <li>All filters, sorting, etc. that works for {@link #getFeatures()} can be
     784      used without modifications on this query.
     785    <li>The same reporter may be returned multiple times if it is present on several
     786      features.
     787    <li>'Null' values may be returned if there are features without a reporter
     788    </ul>
     789   
     790    @return A {@link DataQuery} object
     791    @since 2.8
     792  */
     793  public DataQuery<ReporterData> getReporters()
     794  {
     795    DataQuery<ReporterData> query =
     796      new DataQuery<ReporterData>(ReporterData.class, Item.FEATURE, null, "reporter");
     797    query.restrictPermanent(
     798        Restrictions.eq(
     799          Hql.property("arrayDesignBlock.arrayDesign"),
     800          Hql.entity(this)
     801        )
     802      );
     803    return query;
     804  }
     805 
     806  /**
    779807    Get a feature when you know the id.
    780808    @param id The id of the feature
  • trunk/src/core/net/sf/basedb/core/DataQuery.java

    r4243 r4305  
    6262 
    6363  /**
     64    Create a query that may have different return type and root entity.
     65    For example, to return reporters from a query rooted at features:
     66    <code>new DataQuery(ReporterData.class, Item.FEATURE, null, "reporter")</code>.
     67    This will be translated to something like (in HQL):
     68    <code>SELECT ftr.reporter FROM FeatureData ftr ...</code>
     69
     70    @param dataClass The class of the data objects that are returned
     71    @param rootType The root item type of the query
     72    @param rootName The root enitity name, or null to use
     73      the class name of the root type
     74    @param select The HQL property that we should select on the root
     75      type to get to the return type
     76    @since 2.8
     77  */
     78  DataQuery(Class<I> dataClass, Item rootType, String rootName, String select)
     79  {
     80    super(Item.fromDataClass(dataClass), rootType, rootName, select, true,
     81      QueryRuntimeFilterFactory.getOptionalFilter(rootType));
     82    this.dataClass = dataClass;
     83  }
     84 
     85  /**
    6486    Create a new query for the specified item, using a non-default optional
    6587    runtime filter.
  • trunk/src/core/net/sf/basedb/core/Plate.java

    r4040 r4305  
    2828import net.sf.basedb.core.data.PlateEventData;
    2929import net.sf.basedb.core.data.PlateCoordinate;
     30import net.sf.basedb.core.data.ReporterData;
    3031import net.sf.basedb.core.data.WellData;
    3132import net.sf.basedb.core.query.Restrictions;
     
    483484  }
    484485 
     486  /**
     487    Get a query that returns the reporters on this plate. The query
     488    is rooted at the wells, which means that:
     489    <ul>
     490    <li>All filters, sorting, etc. that works for {@link #getWells()} can be
     491      used without modifications on this query.
     492    <li>The same reporter may be returned multiple times if it is present on several
     493      wells.
     494    <li>'Null' values may be returned if there are wells without a reporter
     495    </ul>
     496   
     497    @return A {@link DataQuery} object
     498    @since 2.8
     499  */
     500  public DataQuery<ReporterData> getReporters()
     501  {
     502    DataQuery<ReporterData> query =
     503      new DataQuery<ReporterData>(ReporterData.class, Item.WELL, null, "reporter");
     504    query.restrictPermanent(
     505        Restrictions.eq(
     506          Hql.property("plate"),
     507          Hql.entity(this)
     508        )
     509      );
     510    return query;
     511  }
     512 
    485513}
  • trunk/src/core/net/sf/basedb/core/RawBioAssay.java

    r4284 r4305  
    11371137    }
    11381138    DataQuery<RawData> query = new DataQuery<RawData>(RawData.class, rdt.getEntityName());
     1139    query.restrictPermanent(
     1140      Restrictions.eq(
     1141        Hql.property("rawBioAssay"),
     1142        Hql.entity(this)
     1143      )
     1144    );
     1145    return query;
     1146  }
     1147 
     1148  /**
     1149    Get a query that returns the reporters on this raw bioassay.
     1150    The query is rooted at the raw data, which means that:
     1151    <ul>
     1152    <li>All filters, sorting, etc. that works for {@link #getRawData()} can be
     1153      used without modifications on this query.
     1154    <li>The same reporter may be returned multiple times if it is present on multiple
     1155      spots.
     1156    <li>'Null' values may be returned if there are spots without a reporter
     1157    </ul>
     1158   
     1159    @return A {@link DataQuery} object
     1160    @since 2.8 
     1161  */
     1162  public DataQuery<ReporterData> getReporters()
     1163  {
     1164    RawDataType rdt = getRawDataType();
     1165    if (!rdt.isStoredInDb())
     1166    {
     1167      throw new BaseException("Raw data for raw data type '" + rdt + "' is not stored in the database.");
     1168    }
     1169    DataQuery<ReporterData> query =
     1170      new DataQuery<ReporterData>(ReporterData.class, Item.RAWDATA, rdt.getEntityName(), "reporter");
    11391171    query.restrictPermanent(
    11401172      Restrictions.eq(
  • trunk/src/core/net/sf/basedb/core/query/EntityQuery.java

    r3679 r4305  
    4949  */
    5050  public Item getItemType();
     51 
     52  /**
     53    The type of items that is the root of the query. In most cases,
     54    this is the same as the {@link #getItemType()}, but not
     55    always.
     56    @since 2.8
     57  */
     58  public Item getRootType();
    5159 
    5260  /**
  • trunk/www/lims/arraydesigns/features/index.jsp

    r4093 r4305  
    3737  import="net.sf.basedb.core.ArrayDesign"
    3838  import="net.sf.basedb.core.data.FeatureData"
     39  import="net.sf.basedb.core.data.ReporterData"
    3940  import="net.sf.basedb.clients.web.Base"
    4041  import="net.sf.basedb.clients.web.WebException"
     
    103104    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+features+of+array+design";
    104105  }
     106  else if ("CreateReporterList".equals(cmd))
     107  {
     108    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     109    dc = sc.newDbControl();   
     110    final ArrayDesign arrayDesign = ArrayDesign.getById(dc, arrayDesignId);
     111    final DataQuery<ReporterData> query = arrayDesign.getReporters();
     112    cc.configureQuery(query, true);
     113    cc.setQuery(query);
     114    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
     115      "&cmd=NewItem&addReporters=1&formId=features&fromContext=FEATURE" +
     116      "&name=" + HTML.urlEncode(arrayDesign.getName());
     117  }
    105118  else
    106119  {
  • trunk/www/lims/arraydesigns/features/list_features.jsp

    r4302 r4305  
    156156      }
    157157    }
     158    function newReporterList()
     159    {
     160      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
     161    }
    158162    </script>
    159163  </base:head>
     
    465469          title="Columns&hellip;"
    466470          tooltip="Show, hide and re-order columns"
     471        />
     472        <tbl:button
     473          image="add.png"
     474          onclick="newReporterList()"
     475          title="New reporter list&hellip;"
     476          tooltip="Create a new reporter list from matching features"
     477          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
    467478        />
    468479        <tbl:button
  • trunk/www/lims/plates/wells/index.jsp

    r3679 r4305  
    3333  import="net.sf.basedb.core.Well"
    3434  import="net.sf.basedb.core.ItemQuery"
     35  import="net.sf.basedb.core.DataQuery"
    3536  import="net.sf.basedb.core.Permission"
    3637  import="net.sf.basedb.core.PermissionDeniedException"
     38  import="net.sf.basedb.core.data.ReporterData"
    3739  import="net.sf.basedb.util.RemovableUtil"
    3840  import="net.sf.basedb.clients.web.Base"
     
    174176    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
    175177  }
     178  else if ("CreateReporterList".equals(cmd))
     179  {
     180    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     181    dc = sc.newDbControl();   
     182    final Plate plate = Plate.getById(dc, plateId);
     183    final DataQuery<ReporterData> query = plate.getReporters();
     184    cc.configureQuery(query, true);
     185    cc.setQuery(query);
     186    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
     187      "&cmd=NewItem&addReporters=1&formId=wells&fromContext=WELL"+
     188      "&name=" + HTML.urlEncode(plate.getName());
     189  }
    176190  else
    177191  {
  • trunk/www/lims/plates/wells/list_wells.jsp

    r4302 r4305  
    162162      }
    163163    }
     164    function newReporterList()
     165    {
     166      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
     167    }
    164168    </script>
    165169  </base:head>
     
    376380          title="Columns&hellip;"
    377381          tooltip="Show, hide and re-order columns"
     382        />
     383        <tbl:button
     384          image="add.png"
     385          onclick="newReporterList()"
     386          title="New reporter list&hellip;"
     387          tooltip="Create a new reporter list from matching wells"
     388          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
    378389        />
    379390        <tbl:button
  • trunk/www/views/rawbioassays/rawdata/index.jsp

    r3679 r4305  
    3232  import="net.sf.basedb.core.ItemContext"
    3333  import="net.sf.basedb.core.data.RawData"
     34  import="net.sf.basedb.core.data.ReporterData"
    3435  import="net.sf.basedb.core.RawBioAssay"
    3536  import="net.sf.basedb.core.RawDataType"
     
    126127    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&subcontext="+rawDataType.getId()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
    127128  }
     129  else if ("CreateReporterList".equals(cmd))
     130  {
     131    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, rawDataType.getId(), pageContext, defaultContext);
     132    final DataQuery<ReporterData> query = rba.getReporters();
     133    cc.configureQuery(query, true);
     134    cc.setQuery(query);
     135    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
     136      "&cmd=NewItem&addReporters=1&formId=rawdata&fromContext=RAWDATA&subContext="+rawDataType.getId()+
     137      "&name=" + HTML.urlEncode(rba.getName());
     138  }
    128139  else
    129140  {
  • trunk/www/views/rawbioassays/rawdata/list_rawdata.jsp

    r4302 r4305  
    162162      }
    163163    }
     164    function newReporterList()
     165    {
     166      Table.submitToPopup(formId, 'CreateReporterList', 540, 400);
     167    }
    164168    </script>
    165169  </base:head>
     
    557561          title="Columns&hellip;"
    558562          tooltip="Show, hide and re-order columns"
     563        />
     564        <tbl:button
     565          image="add.png"
     566          onclick="newReporterList()"
     567          title="New reporter list&hellip;"
     568          tooltip="Create a new reporter list from matching spots"
     569          visible="<%=sc.hasPermission(Permission.CREATE, Item.REPORTERLIST)%>"
    559570        />
    560571        <tbl:button
  • trunk/www/views/reporterlists/edit_reporterlist.jsp

    r4301 r4305  
    5151{
    5252  String title = null;
     53  String name = null;
    5354  ReporterList reporterList = null;
    5455  boolean addReporters = false;
    5556  boolean mergeReporterLists = false;
    5657  int numSelectedLists = cc.getSelected().size();
     58  String formId = Values.getString(request.getParameter("formId"), "reporters");
     59  String fromContext = Values.getString(request.getParameter("fromContext"), "REPORTER");
     60  String subContext = request.getParameter("subContext");
    5761
    5862  if (itemId == 0)
     
    6266    addReporters = Values.getBoolean(request.getParameter("addReporters"));
    6367    mergeReporterLists = !addReporters && numSelectedLists > 0;
     68    name = request.getParameter("name");
     69    if (name == null) name = Values.getString(cc.getPropertyValue("name"), "New reporter list");
    6470  }
    6571  else
    6672  {
    6773    reporterList = ReporterList.getById(dc, itemId);
     74    name = reporterList.getName();
    6875    cc.setObject("item", reporterList);
    6976    title = "Edit reporter list -- " + HTML.encodeTags(reporterList.getName());
     
    152159      if (!selectedItems)
    153160      {
    154         selectedItems = window.opener.Table.getSelected('reporters');
     161        selectedItems = window.opener.Table.getSelected('<%=formId%>');
    155162      }
    156163      return selectedItems;
     
    166173    <form action="index.jsp?ID=<%=ID%>" method="post" name="reporterList" onsubmit="return false;">
    167174    <input type="hidden" name="cmd" value="UpdateItem">
    168 
     175    <input type="hidden" name="fromContext" value="<%=fromContext%>">
     176    <%
     177    if (subContext != null)
     178    {
     179      %>
     180      <input type="hidden" name="subContext" value="<%=subContext%>">
     181      <%
     182    }
     183    %>
    169184    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
    170185    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>"
     
    176191        <td class="prompt">Name</td>
    177192        <td><input <%=requiredClazz%> type="text" name="name"
    178           value="<%=HTML.encodeTags(reporterList == null ? Values.getString(cc.getPropertyValue("name"), "New reporter list") : reporterList.getName())%>"
     193          value="<%=HTML.encodeTags(name)%>"
    179194          size="40" maxlength="<%=ReporterList.MAX_NAME_LENGTH%>"></td>
    180195      </tr>
  • trunk/www/views/reporterlists/index.jsp

    r4301 r4305  
    139139    {
    140140      rl = ReporterList.getNew(dc);
    141       message = "Reporter list created";
    142141      dc.saveItem(rl);
    143142     
     
    146145      if (which != null)
    147146      {
    148         DataQuery<ReporterData> query = (DataQuery<ReporterData>)sc.getCurrentContext(Item.REPORTER).getQuery();
     147        Item fromContext = Item.valueOf(request.getParameter("fromContext"));
     148        String subContext = Values.getString(request.getParameter("subContext"), "");
     149        DataQuery<ReporterData> query =
     150          (DataQuery<ReporterData>)sc.getCurrentContext(fromContext, subContext).getQuery();
    149151        if ("all".equals(which))
    150152        {
     
    165167          query.setParameter("_selected_", Arrays.asList(itemIds), Type.INT);     
    166168        }
     169        // else -- no modifications to the query mean that we only get the current page
    167170       
    168171        DataResultIterator<ReporterData> result = query.iterate(dc);
    169172        while (result.hasNext())
    170173        {
    171           rl.addReporter(result.next(), null);
     174          ReporterData reporter = result.next();
     175          if (reporter != null) rl.addReporter(reporter, null);
    172176        }
    173177      }
     
    196200        }
    197201      }
     202      message = "Reporter list created with " + rl.getSize() + " reporter(s)";
    198203    }
    199204    else
  • trunk/www/views/reporters/index.jsp

    r4093 r4305  
    272272    cc.configureQuery(query, true);
    273273    cc.setQuery(query);
    274     redirect = "../reporterlists/index.jsp?ID="+ID+"&cmd=NewItem&addReporters=1";
     274    redirect = "../reporterlists/index.jsp?ID="+ID+"&cmd=NewItem&addReporters=1&formId=reporters&fromContext=REPORTER";
    275275  }
    276276  else
Note: See TracChangeset for help on using the changeset viewer.