Changeset 6931


Ignore:
Timestamp:
Jun 18, 2015, 1:51:52 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1950: Add support for any-to-any link filters in table lists views

Basic level of support for any-to-any filters. The column definition should set the filter property to |link|target|property where:

  • link = the name of the link (required)
  • target = the type of items (eg. FILE, SAMPLE) (optional)
  • property = the property to filter on on the target item (optional)


At the moment filtering is only possible for 'exists/missing' and the value type for the column must be set to 'boolean'.

Exporting has full support for all properties. If no property is set the default is to export the name if the target item is nameable, otherwise the id.

Location:
trunk/src
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/plugins/ExportedProperty.java

    r6875 r6931  
    2727import net.sf.basedb.core.DbControl;
    2828import net.sf.basedb.core.FileSetMember;
     29import net.sf.basedb.core.Item;
    2930import net.sf.basedb.core.Metadata;
     31import net.sf.basedb.core.Nameable;
    3032import net.sf.basedb.core.Type;
    3133import net.sf.basedb.core.Unit;
     
    111113      dataloader = new FileSetMemberLoader(fileType, propertyPath);
    112114    }
     115    else if (name.startsWith("|"))
     116    {
     117      // Any-to-any=|link|type|property
     118      String[] any = name.split("\\|");
     119      String linkName = any[1];
     120      Item linkType = any.length > 2 ? Item.valueOf(any[2]) : null;
     121      String linkProperty = any.length > 3 ? any[3] : null;
     122     
     123      if (linkProperty == null)
     124      {
     125        // Use 'name' if possible when no link property has been specified
     126        if (linkType != null && Nameable.class.isAssignableFrom(linkType.getItemClass()))
     127        {
     128          linkProperty = "name";
     129          formatter = FormatterFactory.getTypeFormatter(dc.getSessionControl(), Type.STRING);
     130        }
     131        else
     132        {
     133          formatter = FormatterFactory.getTypeFormatter(dc.getSessionControl(), Type.INT);
     134        }
     135      }
     136     
     137      if (linkProperty != null)
     138      {
     139        propertyPath = Metadata.getInstance(linkType.getItemClass()).getPropertyPath(linkProperty, false);
     140      }
     141      if (dataloader == null)
     142      {
     143        dataloader = new AnyToAnyDataLoader(linkName, linkType, propertyPath);
     144      }
     145    }
    113146    else if (dataloader == null && metadata != null)
    114147    {
  • trunk/src/core/net/sf/basedb/core/PropertyFilter.java

    r6881 r6931  
    3535import net.sf.basedb.core.data.UnitData;
    3636import net.sf.basedb.core.query.Annotations;
     37import net.sf.basedb.core.query.AnyToAnyRestriction;
    3738import net.sf.basedb.core.query.EntityQuery;
    3839import net.sf.basedb.core.query.Query;
     
    701702    }
    702703   
     704    else if (property != null && property.startsWith("|"))
     705    {
     706      // Property is Any-to-any filter: |link-name|link-type|property
     707      // link-name is required
     708      // link-type is optional, if not specified filter is always of the type exists/not-exists
     709      // property is optional, if not specified filter is always of the type exists/not-exists
     710      String[] parts = property.split("\\|", 4);
     711      String linkName = parts[1];
     712      Item linkType = parts.length > 2 ? Item.valueOf(parts[2]) : null;
     713      String linkProperty = parts.length > 3 ? parts[3] : null;
     714     
     715      if (linkType == null || linkProperty == null)
     716      {
     717        if (Boolean.TRUE.equals(getValueAsObject()))
     718        {
     719          restriction = AnyToAnyRestriction.exists(null, linkName, linkType);
     720        }
     721        else
     722        {
     723          restriction = AnyToAnyRestriction.missing(null, linkName, linkType);
     724        }
     725      }
     726    }
     727   
    703728    else
    704729    {
Note: See TracChangeset for help on using the changeset viewer.