Changeset 7030


Ignore:
Timestamp:
Nov 25, 2015, 11:28:13 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

Merged patch release 3.6.3 to the trunk.

Location:
trunk
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r7017 r7030  
    432432    throws IOException
    433433  {
    434     Document filterDef = XmlUtil2.getValidatedXml(HibernateUtil.class.getResource("/net/sf/basedb/core/filter-def-template.xml"), dtdFile);
     434    Document filterDef = XmlUtil2.getValidatedXml(HibernateUtil.class.getResource("/net/sf/basedb/core/filter-def.hbm.xml"), dtdFile);
    435435    Map<String, Element> filters = new HashMap<String, Element>();
    436436    for (Element filter : filterDef.getRootElement().getChildren())
     
    453453      Class<?> c = Class.forName(className);
    454454      Item itemType = Item.fromClass(c);
    455       if (itemType == null) return;
    456      
     455
    457456      log.info("Adding 'denyAll' filter to "+c.getName());
    458457      defineFilter(classTag, itemType, "denyAll", "`id` != `id`", filterTemplate);
     
    548547  private static void defineFilter(Element classTag, Item itemType, String name, String condition, Map<String, Element> filterTemplate)
    549548  {
    550     // Load the template
    551     Element filterSource = filterTemplate.get(name);
    552     if (filterSource == null) return;
    553 
    554     // Define the filter by cloning the template onto the root element
    555     classTag.getDocument().getRootElement().addContent(filterSource.clone());
    556     // We also need the same filter with name+itemtype so we have control
    557     // for each type of item
    558     Element filterDef = filterSource.clone();
    559     filterDef.setAttribute("name", name + itemType.name());
    560     classTag.getDocument().getRootElement().addContent(filterDef);
    561 
    562     // Second part of the filter definition goes inside the class tag
    563     Element filter = new Element("filter");
    564     filter.setAttribute("name", name);
    565     filter.setAttribute("condition", condition);
    566     classTag.addContent(filter);
    567    
    568     // And the name+itemtype variant
    569     filter = new Element("filter");
    570     filter.setAttribute("name", name + itemType.name());
    571     filter.setAttribute("condition", condition);
    572     classTag.addContent(filter);
     549    // Generic filter condition is only used for '<class>' elements (not '<subclass>')
     550    if (classTag.getName().equals("class"))
     551    {
     552      Element filter = new Element("filter");
     553      filter.setAttribute("name", name);
     554      filter.setAttribute("condition", condition);
     555      classTag.addContent(filter);
     556    }
     557   
     558    // Define item-specific filters with name+itemType so we have
     559    // control for each type of item
     560    if (itemType != null)
     561    {
     562      // Clone the definition from the template and change the name
     563      Element filterDef = filterTemplate.get(name).clone();
     564      filterDef.setAttribute("name", name + itemType.name());
     565      classTag.getDocument().getRootElement().addContent(filterDef);
     566     
     567      // Enable the filter for the current '<class>' or '<subclass>'
     568      Element filter = new Element("filter");
     569      filter.setAttribute("name", name + itemType.name());
     570      filter.setAttribute("condition", condition);
     571      classTag.addContent(filter);
     572    }
    573573  }
    574574 
  • trunk/src/core/net/sf/basedb/core/ItemContext.java

    r6965 r7030  
    14131413  public void copyObjectsAndTemporaryFilters(ItemContext other)
    14141414  {
    1415     if (objects != null || objects.size() > 0)
     1415    if (objects != null && objects.size() > 0)
    14161416    {
    14171417      if (other.objects == null) other.objects = new HashMap<String, Object>();
    14181418      other.objects.putAll(objects);
    14191419    }
    1420     for (PropertyFilterPair filter : propertyFilters.values())
    1421     {
    1422       if (filter.temporary != null)
    1423       {
    1424         other.setPropertyFilter(filter.temporary);
     1420    if (propertyFilters != null && propertyFilters.size() > 0)
     1421    {
     1422      for (PropertyFilterPair filter : propertyFilters.values())
     1423      {
     1424        if (filter.temporary != null)
     1425        {
     1426          other.setPropertyFilter(filter.temporary);
     1427        }
    14251428      }
    14261429    }
  • trunk/src/core/net/sf/basedb/core/Project.java

    r7016 r7030  
    2828import net.sf.basedb.core.data.ItemParameterValueData;
    2929import net.sf.basedb.core.data.ItemSubtypeData;
     30import net.sf.basedb.core.data.NameableData;
    3031import net.sf.basedb.core.data.ProjectData;
    3132import net.sf.basedb.core.data.ShareableData;
     
    3435import net.sf.basedb.core.query.Restrictions;
    3536import net.sf.basedb.core.query.Hql;
     37import net.sf.basedb.core.query.Orders;
    3638import net.sf.basedb.core.query.EntityQuery;
    3739import net.sf.basedb.core.query.ResultList;
     
    507509  {
    508510    if (include == null) include = EnumSet.of(Include.NOT_REMOVED, Include.MINE, Include.OTHERS);
     511    if (itemTypes == null || itemTypes.size() == 0) itemTypes = Metadata.getShareableItems();
    509512   
    510513    DbControl dc = getDbControl();
     
    583586    }
    584587   
    585     List<ShareableData> inProject = null;
    586     if (itemTypes != null && itemTypes.size() > 0)
    587     {
    588       inProject = new ArrayList<ShareableData>();
    589       for (Item item : itemTypes)
    590       {
    591         if (ShareableData.class.isAssignableFrom(item.getDataClass()))
    592         {
    593           // Query to load all shareable items of a specific subclass
    594           AbstractHqlQuery hql =
    595             new AbstractHqlQuery(item.getDataClass().getName(), "item", false){};
    596           hql.select(Selects.expression(Hql.alias("item"), null, true));
    597           if (restriction != null) hql.restrict(restriction);
    598           /*
    599             SELECT item
    600             FROM <class> item
    601             [WHERE restriction]
    602           */
     588    boolean useLimit = firstItem >= 0 && maxItems > 0;
     589    List<ShareableData> inProject = new ArrayList<ShareableData>();
     590    List<ItemProxy> proxies = new ArrayList<ItemProxy>();
     591   
     592    for (Item item : itemTypes)
     593    {
     594      if (sc.hasPermission(Permission.DENIED, item)) continue;
     595     
     596      if (ShareableData.class.isAssignableFrom(item.getDataClass()))
     597      {
     598        // Query to load all shareable items of a specific subclass
     599        AbstractHqlQuery hql =
     600          new AbstractHqlQuery(item.getDataClass().getName(), "item", false){};
     601        hql.select(Selects.expression(Hql.alias("item"), null, true));
     602        if (restriction != null) hql.restrict(restriction);
     603        if (NameableData.class.isAssignableFrom(item.getDataClass()))
     604        {
     605          hql.order(Orders.asc(Hql.property("name")));
     606        }
     607        hql.order(Orders.asc(Hql.property("id")));
     608        /*
     609          SELECT item[.id]
     610          FROM <class> item
     611          [WHERE restriction]
     612        */
     613        if (useLimit)
     614        {
     615          // Load proxies if we are just going to load a part of the items (it is a lot quicker!)
     616          for (Integer id : HibernateUtil.loadList(Integer.class, hql.getIdHqlQuery(dc), sc))
     617          {
     618            proxies.add(new ItemProxy(id, item));
     619          }
     620        }
     621        else
     622        {
     623          // Load all items
    603624          inProject.addAll(HibernateUtil.loadList(ShareableData.class, hql.getMainHqlQuery(dc), sc));
    604625        }
    605626      }
    606627    }
    607     else
    608     {
    609       // Query to load all shareable items
    610       AbstractHqlQuery hql =
    611         new AbstractHqlQuery("net.sf.basedb.core.data.ShareableData", "item", false){};
    612       hql.select(Selects.expression(Hql.alias("item"), null, true));
    613       if (restriction != null) hql.restrict(restriction);
    614       /*
    615         SELECT item
    616         FROM net.sf.basedb.core.data.ShareableData item
    617         [WHERE restriction]
    618       */
    619       inProject = HibernateUtil.loadList(ShareableData.class, hql.getMainHqlQuery(dc), sc);
    620     }
     628     
    621629    // Disable filters
    622630    HibernateUtil.disableFilter(session, "ownedByOrInProject");
     
    627635    HibernateUtil.disableFilter(session, "denyAll");
    628636   
    629     List<Shareable> items = new ArrayList<Shareable>(inProject.size());
    630     int index = 0;
     637    List<Shareable> items = new ArrayList<Shareable>(useLimit ? maxItems : inProject.size());
    631638    int totalItems = 0;
    632     boolean useLimit = firstItem >= 0 && maxItems > 0;
    633     int lastItem = firstItem + maxItems;
    634     for (ShareableData sd : inProject)
    635     {
    636     BasicData data = (BasicData)sd;
    637     try
    638     {
    639       BasicItem item = dc.getItem(BasicItem.class, data);
    640       if (!useLimit || (index >= firstItem && index < lastItem))
    641       {
    642         items.add((Shareable)item);
    643       }
    644       index++;
    645       totalItems++;
    646     }
    647     catch (PermissionDeniedException ex)
    648     {}
    649     }
     639    if (useLimit)
     640    {
     641      totalItems = proxies.size();
     642      int lastItem = Math.min(firstItem + maxItems, totalItems);
     643      for (int index = firstItem; index < lastItem; index++)
     644      {
     645        try
     646        {
     647          BasicItem item = proxies.get(index).getItem(dc);
     648          items.add((Shareable)item);
     649        }
     650        catch (PermissionDeniedException ex)
     651        {
     652          // We do not correct for permissions since that would make it impossible to
     653          // implement paging. We accept that some pages may contain fewer items.
     654        }
     655      }
     656    }
     657    else
     658    {
     659      totalItems = inProject.size();
     660      for (ShareableData sd : inProject)
     661      {
     662        try
     663        {
     664          BasicItem item = dc.getItem(BasicItem.class, (BasicData)sd);
     665          items.add((Shareable)item);
     666        }
     667        catch (PermissionDeniedException ex)
     668        {
     669          totalItems--;
     670        }
     671      }
     672    }
     673
    650674    return new UnmodifiableResultList<Shareable>(items, totalItems);
    651675  }
  • trunk/src/core/net/sf/basedb/core/filter-def.hbm.xml

    r7029 r7030  
    6565  <filter-def name="ownedBy">
    6666    <filter-param name="owner" type="int" />
     67  </filter-def>
     68
     69  <!--
     70    Filter Ownable+Removable items on the owner to only return
     71    items owned by or removed by the logged in user.
     72    Typical condition is ":user = owner OR :user = removedBy"
     73  -->
     74  <filter-def name="ownedOrRemovedBy">
     75    <filter-param name="user" type="int" />
    6776  </filter-def>
    6877
  • trunk/www/common/plugin/configure.jsp

    r6987 r7030  
    460460                    {
    461461                      %>
    462                       <select name="<%=fieldName%>" id="<%=fieldName%>">
     462                      <select name="<%=fieldName%>" id="<%=fieldName%>" style="min-width: 8em;">
    463463                      <%
    464464                      if (!pType.getNotNull())
  • trunk/www/common/share/share.js

    r6576 r7030  
    5252    Buttons.addClickHandler('btnAddPermissionTemplates', share.addPermissionTemplates);
    5353    Events.addEventHandler('btnAddPermissionTemplates', 'base-selected', share.addPermissionTemplateCallback);
     54    Events.addEventHandler('members', 'base-removed', share.itemRemoved);
    5455
    5556    // Permission checkboxes
     
    142143    event.detail.name += ' ['+permissionString+']';
    143144    event.detail.value = permissionCode;
     145    event.detail.originalValue = 0;
    144146   
    145147    Link.addItem('members', 'USER', event.detail);
     
    175177    event.detail.name += ' ['+permissionString+']';
    176178    event.detail.value = permissionCode;
     179    event.detail.originalValue = 0;
    177180   
    178181    Link.addItem('members', 'GROUP', event.detail);
     
    203206    event.detail.name += ' ['+permissionString+']';
    204207    event.detail.value = permissionCode;
     208    event.detail.originalValue = 0;
    205209   
    206210    Link.addItem('members', 'PROJECT', event.detail);
     
    233237  }
    234238
     239  /**
     240    Set the permission value to 0 when an item is removed
     241  */
     242  share.itemRemoved = function(event)
     243  {
     244    event.detail.item.value = 0;
     245  }
     246 
    235247  /**
    236248    Get a textual description of the permissions that are included in
  • trunk/www/include/scripts/linkitems-2.js

    r6880 r7030  
    104104        'action': link.ADD,
    105105        'value': item.value,
    106         'originalValue': item.value
     106        'originalValue': item.originalValue != undefined ? item.originalValue : item.value
    107107        };
    108108     
     
    167167        item.value = item.originalValue;
    168168        item.option = null;
     169        Events.sendCustomEvent(list, 'base-removed', list[i]);
    169170        list[i--] = null;
    170171      }
  • trunk/www/include/styles/main.css

    r6960 r7030  
    496496{
    497497  padding: 0;
     498}
     499
     500option
     501{
     502  padding-right: 8px;
    498503}
    499504
  • trunk/www/my_base/projects/projects.js

    r7001 r7030  
    5656      Events.addEventHandler('btnAddGroups', 'base-selected', projects.addGroupCallback);
    5757      Events.addEventHandler('members', 'change', projects.membersOnChange);
    58      
     58      Events.addEventHandler('members', 'base-removed', projects.memberRemoved);
     59   
    5960      // Permissions
    6061      Events.addEventHandler('read', 'click', projects.permissionsOnClick);
     
    275276    event.detail.name += ' ['+permissionString+']';
    276277    event.detail.value = permissionCode;
     278    event.detail.originalValue = 0;
    277279   
    278280    Link.addItem('members', 'USER', event.detail);
     
    302304    event.detail.name += ' ['+permissionString+']';
    303305    event.detail.value = permissionCode;
     306    event.detail.originalValue = 0;
    304307   
    305308    Link.addItem('members', 'GROUP', event.detail);
     309  }
     310
     311  /**
     312    Set the permission value to 0 when an item is removed
     313  */
     314  projects.memberRemoved = function(event)
     315  {
     316    event.detail.item.value = 0;
    306317  }
    307318
  • trunk/www/views/experiments/view_experiment.jsp

    r6963 r7030  
    526526            for (RootRawBioAssay item : rawBioAssays)
    527527            {
    528               RawBioAssay rba = item.getRawBioAssay();
     528              RawBioAssay rba = null;
     529              try
     530              {
     531                rba = item.getRawBioAssay();
     532              }
     533              catch (PermissionDeniedException ex)
     534              {}
    529535              AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
    530536              AnnotationSetSnapshot snapshot = as == null ? null : manager.getSnapshot(dc, as.getId());
     
    534540                    image="deleted.png"
    535541                    tooltip="This item has been scheduled for deletion"
    536                     visible="<%=rba.isRemoved()%>"
     542                    visible="<%=rba != null && rba.isRemoved()%>"
    537543                  /><%=Base.getLinkedName(ID, item, false, true)%></tbl:cell>
    538544                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
Note: See TracChangeset for help on using the changeset viewer.