public class EntityUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
RESTRICT_FIELDS_PARAM
The parameter that might contain a list of fieldNames to restrict the entity to.
|
| Constructor and Description |
|---|
EntityUtil() |
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
determineRestrictFields(org.springframework.util.MultiValueMap<String,String> requestedFilter,
Class<?> entityClass)
Returns a list of fieldnames to restrict the output to.
|
static List<String> |
getFilterableOrRestrictableFieldNames(Class<?> entityClass)
Returns a list of fieldNames of the passed class that can be used to either
|
static boolean |
isCollectionField(Class<?> clazz,
String fieldName,
Class<?> collectionElementType,
boolean forceAccess)
Checks whether the given
fieldName in clazz is
a collection field with elements of type
collectionElementType. |
static boolean |
isField(Class<?> clazz,
String fieldName,
Class<?> fieldEntityType,
boolean forceAccess) |
static List<String> |
listFromCommaSeparatedStringList(List<String> listOfCommaSeparatedValues)
A small utility method that will turn a passed list with comma separated strings into
a list which has single elements:
|
static org.springframework.util.MultiValueMap<String,Object> |
validFieldNamesWithCastedValues(org.springframework.util.MultiValueMap<String,String> requestedFilter,
Class<?> entityClass)
This method returns a multi value map, where the keys are the
intersection of (non-static private) field names of the given entity
class and the given set of requested/input field names (which are the
keys of the passed multi value map), i.e.
|
public static final String RESTRICT_FIELDS_PARAM
public static boolean isField(Class<?> clazz, String fieldName, Class<?> fieldEntityType, boolean forceAccess)
clazz - fieldName - fieldEntityType - forceAccess - public static boolean isCollectionField(Class<?> clazz, String fieldName, Class<?> collectionElementType, boolean forceAccess)
fieldName in clazz is
a collection field with elements of type
collectionElementType.clazz - The class to check for the given collection fieldfieldName - The name of the collection fieldcollectionElementType - The type of the concrete element in the collectionforceAccess - whether to break scope restrictions using the
AccessibleObject.setAccessible(boolean)
method. false will only match public fields.fieldName in
clazz is a collection field with elements of type
collectionElementType.public static List<String> getFilterableOrRestrictableFieldNames(Class<?> entityClass)
validFieldNamesWithCastedValues(org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>, java.lang.Class<?>), ordetermineRestrictFields(org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>, java.lang.Class<?>) entityClass - public static List<String> listFromCommaSeparatedStringList(List<String> listOfCommaSeparatedValues)
Examples:
| in | out | in.size() | out.size() |
|---|---|---|---|
null | null |
n.a. | n.a. |
[null] | null |
1 | n.a. |
["foo"] | ["foo"] |
1 | 1 |
["foo,bar"] |
["foo", "bar"] |
1 | 2 |
["foo", "bar"] |
["foo", "bar"] |
2 | 2 |
["foo,humpty", "bar,dumpty"] |
["foo", "humpty", "bar", "dumpty"] |
2 | 4 |
listOfCommaSeparatedValues - public static List<String> determineRestrictFields(org.springframework.util.MultiValueMap<String,String> requestedFilter, Class<?> entityClass)
requestedFilter.
Only the key "output:only" is taken as list of requested fieldName to restrict by, the value is treated in a case-insensitive matter.
The returned list will have casing as they appear in the class, regardless
of the case of the values that appear in RESTRICT_FIELDS_PARAM.
requestedFilter - entityClass - public static org.springframework.util.MultiValueMap<String,Object> validFieldNamesWithCastedValues(org.springframework.util.MultiValueMap<String,String> requestedFilter, Class<?> entityClass)
Regarding case sensitivity, the field names that are building the keys of the result map are used in their original representation/definition from the entity model, but the keys/fieldnames in the input may be case-insensitive.
The value for each key is a list of casted (!) values of the string values of the given input map. The type of the field in the entity is used to determine the correct casting.
requestedFilter - entityClass - Copyright © 2020 terrestris GmbH & Co. KG. All rights reserved.