Changeset 7032


Ignore:
Timestamp:
Dec 3, 2015, 3:41:04 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #1975: Improve filtering in project items list

The list now uses the conditional query element. The filter implementation that enable/disable the restriction has been moved from the trashcan JSP file to a separate java class, ReturnClassFilter.

Location:
trunk
Files:
1 added
3 edited

Legend:

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

    r7030 r7032  
    596596      if (ShareableData.class.isAssignableFrom(item.getDataClass()))
    597597      {
    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));
     598        // Query to load all "shareable" items of a specific item type
     599        AbstractEntityQuery hql = new AbstractEntityQuery(item, null, false){};
    602600        if (restriction != null) hql.restrict(restriction);
    603601        if (NameableData.class.isAssignableFrom(item.getDataClass()))
  • trunk/www/my_base/projects/items/list_items.jsp

    r6834 r7032  
    4444  import="net.sf.basedb.core.query.Restriction"
    4545  import="net.sf.basedb.core.query.Restrictions"
     46  import="net.sf.basedb.core.query.ReturnClassFilter"
    4647  import="net.sf.basedb.util.Enumeration"
    4748  import="net.sf.basedb.util.ShareableUtil"
     
    103104      }
    104105    }
     106    Restriction id = cc.getFilterRestriction("id", dc, null);
    105107    Restriction sharedTo = cc.getFilterRestriction("!sharedTo.name", dc, null);
    106108    Restriction owner = cc.getFilterRestriction("owner.name", dc, null);
    107     Restriction name = cc.getFilterRestriction("name", dc, null);
    108     Restriction description = cc.getFilterRestriction("description", dc, null);
    109     Restriction id = cc.getFilterRestriction("id", dc, null);
     109    Restriction name = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
     110        cc.getFilterRestriction("name", dc, null), null);
     111    Restriction description = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
     112        cc.getFilterRestriction("description", dc, null), null);
    110113    Restriction restriction = Restrictions.nullSafeAnd(sharedTo, owner, name, description, id);
    111114    items = project.getItems(itemTypes,
  • trunk/www/views/trashcan/list_trash.jsp

    r7018 r7032  
    4848  import="net.sf.basedb.core.query.Restriction"
    4949  import="net.sf.basedb.core.query.Restrictions"
     50  import="net.sf.basedb.core.query.ReturnClassFilter"
    5051  import="net.sf.basedb.util.Enumeration"
    5152  import="net.sf.basedb.util.ShareableUtil"
     
    7778    {
    7879      items.add(item.name(), item.toString());
    79     }
    80   }
    81  
    82   static class ReturnClassFilter
    83     implements Filter<EntityQuery>
    84   {
    85     private final Class<?> returnClass;
    86     ReturnClassFilter(Class<?> returnClass)
    87     {
    88       this.returnClass = returnClass;
    89     }
    90    
    91     public boolean evaluate(EntityQuery query)
    92     {
    93       return returnClass.isAssignableFrom(query.getItemType().getItemClass());
    9480    }
    9581  }
Note: See TracChangeset for help on using the changeset viewer.