public class PropertyFilter extends Object
property operator value
,
ie. name = 'Nicklas'
or spots > 10000
.SessionControl.getCurrentContext(Item)
,
ItemContext
Modifier and Type | Field and Description |
---|---|
private Pattern |
DATA_FILES |
private Pattern |
ENTITY_COLLECTION |
static int |
MAX_VALUE_LENGTH
The maximum allowed length of a filter value.
|
private Operator |
operator |
private String |
property |
private int |
rowIndex |
private boolean |
temporary |
static boolean |
TEMPORARY
Flag to use for temporary filters.
|
private Unit |
unit |
private String |
value |
private static String |
value_separator
The string/characters used as a separator in a string with more then one filter values.
|
private Type |
valueType |
Constructor and Description |
---|
PropertyFilter(String property)
Create a new filter for a property on filter row 0.
|
PropertyFilter(String property,
int rowIndex)
Create a new filter for a property.
|
PropertyFilter(String property,
int rowIndex,
PropertyFilterData filter)
Create a new filter from a loaded database object.
|
PropertyFilter(String property,
Operator operator,
String value,
Type valueType)
Create a new filter for a property.
|
PropertyFilter(String property,
Operator operator,
String value,
Type valueType,
boolean temporary)
Create a new filter for a property.
|
Modifier and Type | Method and Description |
---|---|
private Double |
convertValueToUnit(Session session,
String value,
String unitSymbol,
Unit convertTo)
Converts a string to a numeric value with the correct unit.
|
(package private) static PropertyFilter |
create(String propertyFromDb,
PropertyFilterData data)
Create a property filter instance from what has been saved in the database.
|
(package private) PropertyFilterData |
getData()
Create a new database filter object from this filter.
|
Restriction |
getDynamicRestriction(DbControl dc)
Deprecated.
In 3.9.2, use
getDynamicRestriction(DbControl, SqlQuery) instead |
Restriction |
getDynamicRestriction(DbControl dc,
SqlQuery query) |
Operator |
getOperator()
Get the operator to use in the filter.
|
String |
getProperty()
Get the name of the property this filter is used on.
|
Restriction |
getRestriction(DbControl dc,
EntityQuery query)
Create a restriction from the filter.
|
int |
getRowIndex()
Get the filter row index this filter is part of.
|
String |
getValue()
Get the value to use in the filter.
|
Object |
getValueAsObject()
Get the value as an object of the correct type.
|
private Object |
getValueAsObject(String value,
Unit unit,
boolean asDouble) |
Object |
getValueAsObject(Unit unit,
boolean asDouble)
Get the value as an object of the proper type converted to the
specified unit.
|
List<Object> |
getValuesAsObjects()
Splits the value string at each "|" and creates
a list with objects from the substrings that were found.
|
private List<Object> |
getValuesAsObjects(String value,
Unit unit,
boolean asDouble) |
List<Object> |
getValuesAsObjects(Unit unit,
boolean asDouble)
Same as
getValueAsObject(Unit, boolean) but the filter string
is first split at each "|". |
String |
getValueSeparator() |
Type |
getValueType()
Get the type of the property.
|
boolean |
isTemporary()
Is this filter a temporary filter or not.
|
void |
setOperator(Operator operator)
Set the operator to use in the filter.
|
(package private) void |
setRowIndex(int rowIndex)
Only used internally when removing filter rows
|
void |
setTemporary(boolean temporary)
Set or clear a flag indicating that this filter is temporary filter.
|
void |
setUnit(Unit unit)
Sets the unit the values for the property are stored in the
database.
|
void |
setValue(String value)
Set the value to use in the filter.
|
void |
setValueType(Type valueType)
Set the type of the property.
|
String |
toString() |
public static final int MAX_VALUE_LENGTH
public static final boolean TEMPORARY
private static final String value_separator
private final Pattern ENTITY_COLLECTION
private final Pattern DATA_FILES
private final String property
private int rowIndex
private Type valueType
private Operator operator
private String value
private Unit unit
private boolean temporary
public PropertyFilter(String property)
property
- The name of the propertypublic PropertyFilter(String property, int rowIndex)
property
- The name of the propertyrowIndex
- The filter row to create the filter onpublic PropertyFilter(String property, Operator operator, String value, Type valueType)
property
- The name of the propertyoperator
- The operator to usevalue
- The value to check againstvalueType
- The type of the valuepublic PropertyFilter(String property, Operator operator, String value, Type valueType, boolean temporary)
property
- The name of the propertyoperator
- The operator to usevalue
- The value to check againstvalueType
- The type of the valuetemporary
- A flag indicating if the filter should be temporary or notPropertyFilter(String property, int rowIndex, PropertyFilterData filter)
static PropertyFilter create(String propertyFromDb, PropertyFilterData data)
PropertyFilterData getData()
public void setTemporary(boolean temporary)
public boolean isTemporary()
public String getProperty()
public int getRowIndex()
void setRowIndex(int rowIndex)
ItemContext.removeFilterRow(int)
public Type getValueType()
public void setValueType(Type valueType)
valueType
- The typepublic Operator getOperator()
public void setOperator(Operator operator)
public void setUnit(Unit unit)
unit
- The unit, or null to remove the unit from the filterpublic String getValue()
public void setValue(String value)
value
- The value as a stringpublic Object getValueAsObject()
Note! The returned value is cast to the class supported by
the getValueType()
. Beware of this when the
filter has an integer type and a unit with low precision.
For example, if the value is '125min' and the unit is
'hour' this method returns the integer 2. To avoid this
use getValueAsObject(Unit, boolean)
with
asDouble=true instead.
InvalidDataException
- If the string value can't be parsedpublic Object getValueAsObject(Unit unit, boolean asDouble)
If the asDouble parameter is true, the value is returned as a
double, otherwise it is cast to the
proper class as specified by the getValueType()
.
Note! The above only applies for numerical properties that
has a unit. If not, the value is simply parsed with
Type.parseString(String)
.
unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE
to let the getValueType()
decidepublic List<Object> getValuesAsObjects()
InvalidDataException
- If any of the string values can't be parsed.public List<Object> getValuesAsObjects(Unit unit, boolean asDouble)
getValueAsObject(Unit, boolean)
but the filter string
is first split at each "|". Each individual string may or may not specify
a unit. If a unit is specified for some parts but not for all, the nearest
following unit is used. For example, the string '300g|5|10kg' is the same as
'300g|5kg|10kg'.'unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE
to let the getValueType()
decideprivate List<Object> getValuesAsObjects(String value, Unit unit, boolean asDouble)
private Double convertValueToUnit(Session session, String value, String unitSymbol, Unit convertTo)
session
- Hibernate session used to lookup unitsvalue
- The string value which should be parsable with
Double.parseDouble(String)
unitSymbol
- The unit of the string valueconvertTo
- The unit to convert the value topublic Restriction getRestriction(DbControl dc, EntityQuery query)
If the property starts with a $ it is interpreted as a alias.property
value, ignoring the root alias of the query. The alias is removed from the
property before proceeding.
If the property starts with a # or ## it is a filter on annotations. The rest of
the property is the ID of the annotation type, and we use a
AnnotationSimpleRestriction
object for the restriction. If there
is only one # in the prefix only direct annotations are searched, if there
are two ##, inherited annotations are also searched.
If the property starts with a £, the rest of the property is the path that
joins the ReporterData.getReporterListScores()
collection. The filter
value is the ID of the reporter list.
If the property starts with a @ the property is a collection of values and we always use an IN restriction, ignoring the specified operator.
If the property starts with & it is a collection of entities. The property must end with a property name from the entity in the collection within paranthesis. Eg. &experiments(name). The filter is applied as a subquery.
If the property starts with ! it is another special filter. There is currently one such filter (since BASE 2.15): !sharedTo.name, which is used to filter shareable items by the name of users/groups/projects it has been shared to. The 'name' part can be replaced with any other property that is common for users, groups and projects (eg. description or id).
The property may also start with $@.
@Deprecated public Restriction getDynamicRestriction(DbControl dc)
getDynamicRestriction(DbControl, SqlQuery)
insteadpublic Restriction getDynamicRestriction(DbControl dc, SqlQuery query)
public String getValueSeparator()