Class EntityUtil
- java.lang.Object
-
- de.terrestris.shoguncore.util.entity.EntityUtil
-
public class EntityUtil extends Object
- Author:
- Nils Bühner, terrestris GmbH & Co. KG
-
-
Field Summary
Fields Modifier and Type Field Description static StringRESTRICT_FIELDS_PARAMThe parameter that might contain a list of fieldNames to restrict the entity to.
-
Constructor Summary
Constructors Constructor Description EntityUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 eitherstatic booleanisCollectionField(Class<?> clazz, String fieldName, Class<?> collectionElementType, boolean forceAccess)Checks whether the givenfieldNameinclazzis a collection field with elements of typecollectionElementType.static booleanisField(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.
-
-
-
Field Detail
-
RESTRICT_FIELDS_PARAM
public static final String RESTRICT_FIELDS_PARAM
The parameter that might contain a list of fieldNames to restrict the entity to.- See Also:
- Constant Field Values
-
-
Method Detail
-
isField
public static boolean isField(Class<?> clazz, String fieldName, Class<?> fieldEntityType, boolean forceAccess)
- Parameters:
clazz-fieldName-fieldEntityType-forceAccess-
-
isCollectionField
public static boolean isCollectionField(Class<?> clazz, String fieldName, Class<?> collectionElementType, boolean forceAccess)
Checks whether the givenfieldNameinclazzis a collection field with elements of typecollectionElementType.- Parameters:
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 theAccessibleObject.setAccessible(boolean)method.falsewill only matchpublicfields.- Returns:
- Whether or not the given
fieldNameinclazzis a collection field with elements of typecollectionElementType.
-
getFilterableOrRestrictableFieldNames
public static List<String> getFilterableOrRestrictableFieldNames(Class<?> entityClass)
Returns a list of fieldNames of the passed class that can be used to either- filter results with, see
validFieldNamesWithCastedValues(org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>, java.lang.Class<?>), or - restrict output of queries, see
determineRestrictFields(org.springframework.util.MultiValueMap<java.lang.String, java.lang.String>, java.lang.Class<?>)
- Parameters:
entityClass-- Returns:
- filter results with, see
-
listFromCommaSeparatedStringList
public 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:Examples:
Examples: in out in.size() out.size() nullnulln.a. n.a. [null]null1 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 - Parameters:
listOfCommaSeparatedValues-
-
determineRestrictFields
public static List<String> determineRestrictFields(org.springframework.util.MultiValueMap<String,String> requestedFilter, Class<?> entityClass)
Returns a list of fieldnames to restrict the output to. This list is the intersection of fields that are possible to be restricted and the names that are actually requested in therequestedFilter.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.- Parameters:
requestedFilter-entityClass-
-
validFieldNamesWithCastedValues
public 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. fields in the input that are not present in the entity model definition will be removed/ignored in this method.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.
- Parameters:
requestedFilter-entityClass-- Returns:
-
-