Changeset 7037


Ignore:
Timestamp:
Dec 4, 2015, 12:55:19 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #1976: Improve filtering in "All items" list

The list now uses conditional query elements.

Location:
trunk
Files:
2 edited

Legend:

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

    r7036 r7037  
    4141import net.sf.basedb.core.query.Orders;
    4242import net.sf.basedb.core.query.EntityQuery;
     43import net.sf.basedb.core.query.Expressions;
    4344import net.sf.basedb.core.query.ResultList;
    4445import net.sf.basedb.core.query.Selects;
     
    12211222      {
    12221223        // Query to load all ownable items of a specific subclass
    1223         AbstractHqlQuery hql =
    1224           new AbstractHqlQuery(item.getDataClass().getName(), "item", false){};
    1225         hql.select(Selects.expression(Hql.alias("item"), null, true));
    1226         hql.restrict(Hql.restriction("item.owner = :user", null));
     1224        AbstractEntityQuery hql = new AbstractEntityQuery(item, null, false){};
     1225        hql.restrict(Restrictions.eq(Hql.property("owner"), Expressions.parameter("user")));
    12271226        hql.setParameter("user", getId(), Type.INT);
    12281227        if (restriction != null) hql.restrict(restriction);
  • trunk/www/views/items/list_items.jsp

    r6834 r7037  
    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"
     
    9899      }
    99100    }
    100     Restriction sharedTo = cc.getFilterRestriction("!sharedTo.name", dc, null);
    101     Restriction name = cc.getFilterRestriction("name", dc, null);
    102     Restriction description = cc.getFilterRestriction("description", dc, null);
    103101    Restriction id = cc.getFilterRestriction("id", dc, null);
     102    Restriction sharedTo = Restrictions.conditionalRestriction(new ReturnClassFilter(Shareable.class),
     103      cc.getFilterRestriction("!sharedTo.name", dc, null), null, true);
     104    Restriction name = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
     105      cc.getFilterRestriction("name", dc, null), null, true);
     106    Restriction description = Restrictions.conditionalRestriction(new ReturnClassFilter(Nameable.class),
     107      cc.getFilterRestriction("description", dc, null), null, true);
    104108    Restriction restriction = Restrictions.nullSafeAnd(sharedTo, name, description, id);
    105     if (sharedTo != null)
    106     {
    107       // If we filter on "Shared to" we must make sure to only
    108       // include Shareable items in the query
    109       if (itemTypes != null)
    110       {
    111         itemTypes.retainAll(Metadata.getShareableItems());
    112       }
    113       else
    114       {
    115         itemTypes = Metadata.getShareableItems();
    116       }
    117     }
     109
    118110    User loggedInUser = User.getById(dc, sc.getLoggedInUserId());
    119111    if (itemTypes == null || itemTypes.size() > 0)
Note: See TracChangeset for help on using the changeset viewer.