Changeset 5164


Ignore:
Timestamp:
Oct 27, 2009, 2:37:00 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1377: Filter item lists on the 'Shared to' column

The filter functionality has been added to the core api. It is tested with the sample listing. The other list pages that has the "Shared to" column can be fixed
by using the following column definition:

<tbl:columndef
   id="sharedTo"
   title="Shared to"
   filterable="true"
   filterproperty="!sharedTo.name"
   datatype="string"
/>
Location:
trunk
Files:
1 added
4 edited

Legend:

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

    r5136 r5164  
    10841084            {
    10851085              String filterProperty = filter.getProperty();
    1086               if (filterProperty != null && !filterProperty.startsWith("£") && !filterProperty.startsWith("&"))
     1086              if (filterProperty != null && !filterProperty.startsWith("£") && !filterProperty.startsWith("&") && !filterProperty.startsWith("!"))
    10871087              {
    10881088                int lastDotIndex = filterProperty.lastIndexOf('.');
  • trunk/src/core/net/sf/basedb/core/PropertyFilter.java

    r5014 r5164  
    429429    must end with a property name from the entity in the collection within paranthesis.
    430430    Eg. &experiments(name). The filter is applied as a subquery.
     431    <p>
     432    If the property starts with ! it is another special filter. There is currently
     433    one such filter (since BASE 2.15): !sharedTo.name, which is used to filter
     434    shareable items by the name of users/groups/projects it has been shared to.
     435    The 'name' part can be replaced with any other property that is common for
     436    users, groups and projects (eg. description or id).
    431437    <p>
    432438    The property may also start with $@.
     
    642648            Expressions.any(subquery));
    643649      }
     650      else if (property != null && property.startsWith("!sharedTo."))
     651      {
     652        // A special filter on on shareable items
     653        String filterProperty = property.substring("!sharedTo.".length());
     654        String filterValue = getValue();
     655        Operator filterOp = null;
     656        if (operator == Operator.EQ || operator == Operator.NEQ)
     657        {
     658          filterOp = Operator.EQ;
     659        }
     660        else if (operator == Operator.LIKE || operator == Operator.NOTLIKE)
     661        {
     662          filterOp = Operator.LIKE;
     663        }
     664        else if (operator == Operator.IN ||  operator == Operator.NOTIN)
     665        {
     666          filterOp = Operator.IN;
     667        }
     668        else if (operator == Operator.LIKE_IN ||  operator == Operator.NOTLIKE_IN)
     669        {
     670          filterOp = Operator.LIKE_IN;
     671        }
     672        else
     673        {
     674          filterOp = operator;
     675        }
     676        boolean sharedTo = operator == filterOp;
     677       
     678        Restriction users = null;
     679        Restriction groups = null;
     680        Restriction projects = null;
     681        if (filterValue != null)
     682        {
     683          users = new PropertyFilter("$usr." + filterProperty,
     684              filterOp, filterValue, valueType).getRestriction(dc, query);
     685          groups = new PropertyFilter("$grp." + filterProperty,
     686              filterOp, filterValue, valueType).getRestriction(dc, query);
     687          projects = new PropertyFilter("$prj." + filterProperty,
     688              filterOp, filterValue, valueType).getRestriction(dc, query);
     689        }
     690        restriction = Hql.sharedTo(sharedTo, users, groups, projects);
     691      }
    644692      else
    645693      {   
  • trunk/src/core/net/sf/basedb/core/query/Hql.java

    r4889 r5164  
    2828import net.sf.basedb.core.InvalidUseOfNullException;
    2929import net.sf.basedb.core.ReporterList;
     30import net.sf.basedb.core.Shareable;
    3031import net.sf.basedb.core.UnsavedItemException;
    3132import net.sf.basedb.core.data.BasicData;
     
    546547  }
    547548 
     549  /**
     550    A special restriction that works on {@link Shareable} items.
     551    The restriction is used to find items that have or have not
     552    been shared to users/groups and/or projects that meet some
     553    specific criteria.
     554   
     555    @param sharedTo TRUE to finds items that have been shared to at
     556      least one of the matching users/groups/projects, FALSE to find
     557      items that are not shared to any of the matching users/groups/projects.
     558      If all three restrictions are null, a value of TRUE will find items
     559      that are not shared and FALSE will find items that are shared to
     560      anyone.
     561    @param users A restriction to apply on the subquery that is matching users,
     562      or null to not match against users
     563    @param groups A restriction to apply on the subquery that is matching groups,
     564      or null to not match against groups
     565    @param projects A restriction to apply on the subquery that is matching projects,
     566      or null to not match against projects
     567    @return A restriction
     568    @since 2.15
     569  */
     570  public static Restriction sharedTo(boolean sharedTo, Restriction users, Restriction groups, Restriction projects)
     571  {
     572    return new SharedToRestriction(sharedTo, users, groups, projects);
     573  }
    548574}
  • trunk/www/biomaterials/samples/list_samples.jsp

    r4901 r5164  
    477477        id="sharedTo"
    478478        title="Shared to"
     479        filterable="true"
     480        filterproperty="!sharedTo.name"
     481        datatype="string"
    479482      />
    480483      <tbl:toolbar
Note: See TracChangeset for help on using the changeset viewer.