Class PropertyFilter
public class PropertyFilter extends Object
property operator value
,
ie. name = 'Nicklas'
or spots > 10000
.- Version:
- 2.0
- Author:
- Nicklas
- See Also:
SessionControl.getCurrentContext(Item)
,ItemContext
- Last modified
- $Date: 2022-12-20 14:18:19 +0100 (Tue, 20 Dec 2022) $
-
Field Summary
Fields Modifier and Type Field 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 TransformContext
transformContext
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 Summary
Constructors Constructor 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. -
Method Summary
Modifier and Type Method 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, 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.Restriction
getRestriction(DbControl dc, EntityQuery query, ClientContext context)
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.<T> T
getValueAsObject()
Get the value as an object of the correct type.private <T> T
getValueAsObject(String value, Unit unit, boolean asDouble)
<T> T
getValueAsObject(Unit unit, boolean asDouble)
Get the value as an object of the proper type converted to the specified unit.<T> List<T>
getValuesAsObjects()
Splits the value string at each "|" and creates a list with objects from the substrings that were found.private <T> List<T>
getValuesAsObjects(String value, Unit unit, boolean asDouble)
<T> List<T>
getValuesAsObjects(Unit unit, boolean asDouble)
Same asgetValueAsObject(Unit, boolean)
but the filter string is first split at each "|".String
getValueSeparator()
Type
getValueType()
Get the type of the property.boolean
isExtensionFilter(String prefix)
Checks if this filter is an extension filter.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 rowsvoid
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()
-
Field Details
-
MAX_VALUE_LENGTH
public static final int MAX_VALUE_LENGTHThe maximum allowed length of a filter value.- Since:
- 2.6.2
- See Also:
- Constant Field Values
-
TEMPORARY
public static final boolean TEMPORARYFlag to use for temporary filters.- Since:
- 2.16
- See Also:
- Constant Field Values
-
value_separator
The string/characters used as a separator in a string with more then one filter values.- See Also:
- Constant Field Values
-
ENTITY_COLLECTION
-
DATA_FILES
-
property
-
rowIndex
private int rowIndex -
valueType
-
operator
-
value
-
unit
-
temporary
private boolean temporary -
transformContext
-
-
Constructor Details
-
PropertyFilter
Create a new filter for a property on filter row 0.- Parameters:
property
- The name of the property
-
PropertyFilter
Create a new filter for a property.- Parameters:
property
- The name of the propertyrowIndex
- The filter row to create the filter on
-
PropertyFilter
Create a new filter for a property.- Parameters:
property
- The name of the propertyoperator
- The operator to usevalue
- The value to check againstvalueType
- The type of the value
-
PropertyFilter
public PropertyFilter(String property, Operator operator, String value, Type valueType, boolean temporary)Create a new filter for a property.- Parameters:
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 not- Since:
- 2.16
-
PropertyFilter
PropertyFilter(String property, int rowIndex, PropertyFilterData filter)Create a new filter from a loaded database object.
-
-
Method Details
-
create
Create a property filter instance from what has been saved in the database. Basically, we need to strip the [filterrow] if it is set.- Since:
- 3.5
-
getData
PropertyFilterData getData()Create a new database filter object from this filter. -
toString
-
setTemporary
public void setTemporary(boolean temporary)Set or clear a flag indicating that this filter is temporary filter. Temporary filters are not saved between sessions.- Since:
- 2.16
-
isTemporary
public boolean isTemporary()Is this filter a temporary filter or not.- Since:
- 2.16
-
getProperty
Get the name of the property this filter is used on. -
isExtensionFilter
Checks if this filter is an extension filter. An extension filter has agetProperty()
that starts with "!x.prefix".- Parameters:
prefix
- The extension prefix to check, or null to check any extension- Since:
- 3.18
-
getRowIndex
public int getRowIndex()Get the filter row index this filter is part of.- Since:
- 3.5
-
setRowIndex
void setRowIndex(int rowIndex)Only used internally when removing filter rows- Since:
- 3.5
- See Also:
ItemContext.removeFilterRow(int)
-
getValueType
Get the type of the property. -
setValueType
Set the type of the property.- Parameters:
valueType
- The type
-
getOperator
Get the operator to use in the filter. -
setOperator
Set the operator to use in the filter. -
setUnit
Sets the unit the values for the property are stored in the database. When a unit is set, it is possible to have filter values with units. The filter values are automatically converted to this unit before the filter is applied. For example, if we set the unit to 'g', someone may filter on '0.5kg', which is converted to 500 in the query.- Parameters:
unit
- The unit, or null to remove the unit from the filter- Since:
- 2.9
-
getValue
Get the value to use in the filter.- Returns:
- The value as a string
-
setValue
Set the value to use in the filter.- Parameters:
value
- The value as a string
-
getValueAsObject
public <T> T getValueAsObject()Get the value as an object of the correct type. If the filter property is numeric and has a unit, the value is converted to the correct unit automatically. For example, if the value is '5kg' and the unit is 'g' this method returns 5000.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 usegetValueAsObject(Unit, boolean)
with asDouble=true instead.- Returns:
- The value as an object
- Throws:
InvalidDataException
- If the string value can't be parsed
-
getValueAsObject
Get the value as an object of the proper type converted to the specified unit. For example, if the unit is 'g' and the value is '5kg' this method returns 5000.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)
.- Parameters:
unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE to let thegetValueType()
decide- Returns:
- The value as an object
- Since:
- 2.9
-
getValueAsObject
-
getValuesAsObjects
Splits the value string at each "|" and creates a list with objects from the substrings that were found.- Returns:
- A list with objects, or null if splitting string of values returns null.
- Throws:
InvalidDataException
- If any of the string values can't be parsed.- Since:
- 2.5
-
getValuesAsObjects
Same asgetValueAsObject(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'.'- Parameters:
unit
- A unit, or null to use the default unitasDouble
- TRUE to return the value as a double, FALSE to let thegetValueType()
decide- Returns:
- A list with the values
- Since:
- 2.9
-
getValuesAsObjects
-
convertValueToUnit
private Double convertValueToUnit(Session session, String value, String unitSymbol, Unit convertTo)Converts a string to a numeric value with the correct unit.- Parameters:
session
- Hibernate session used to lookup unitsvalue
- The string value which should be parsable withDouble.parseDouble(String)
unitSymbol
- The unit of the string valueconvertTo
- The unit to convert the value to- Returns:
- The converted value
-
getRestriction
Create a restriction from the filter. There are a few special cases: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:
- 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).
- Since BASE 3.18: !x., which is intended to be handled by extensions. It is ignored by the BASE core code. The rest of the property should be a unique identifier for the extension that is handling the filter.
The property may also start with $@.
- Returns:
- The restriction
- Since:
- 2.8
-
getRestriction
Create a restriction from the filter. There are a few special cases: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:
- 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).
- Since BASE 3.18: !x., which is intended to be handled by extensions. It is ignored by the BASE core code. The rest of the property should be a unique identifier for the extension that is handling the filter.
The property may also start with $@.
- Returns:
- The restriction
- Since:
- 3.19.4
-
getDynamicRestriction
- Since:
- 3.9.2
-
getValueSeparator
-