Class EntityUtil


  • public class EntityUtil
    extends java.lang.Object
    Author:
    Nils Bühner, terrestris GmbH & Co. KG
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String RESTRICT_FIELDS_PARAM
      The 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 java.util.List<java.lang.String> determineRestrictFields​(org.springframework.util.MultiValueMap<java.lang.String,​java.lang.String> requestedFilter, java.lang.Class<?> entityClass)
      Returns a list of fieldnames to restrict the output to.
      static java.util.List<java.lang.String> getFilterableOrRestrictableFieldNames​(java.lang.Class<?> entityClass)
      Returns a list of fieldNames of the passed class that can be used to either
      static boolean isCollectionField​(java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Class<?> collectionElementType, boolean forceAccess)
      Checks whether the given fieldName in clazz is a collection field with elements of type collectionElementType.
      static boolean isField​(java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Class<?> fieldEntityType, boolean forceAccess)  
      static java.util.List<java.lang.String> listFromCommaSeparatedStringList​(java.util.List<java.lang.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<java.lang.String,​java.lang.Object> validFieldNamesWithCastedValues​(org.springframework.util.MultiValueMap<java.lang.String,​java.lang.String> requestedFilter, java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • RESTRICT_FIELDS_PARAM

        public static final java.lang.String RESTRICT_FIELDS_PARAM
        The parameter that might contain a list of fieldNames to restrict the entity to.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EntityUtil

        public EntityUtil()
    • Method Detail

      • isField

        public static boolean isField​(java.lang.Class<?> clazz,
                                      java.lang.String fieldName,
                                      java.lang.Class<?> fieldEntityType,
                                      boolean forceAccess)
        Parameters:
        clazz -
        fieldName -
        fieldEntityType -
        forceAccess -
      • isCollectionField

        public static boolean isCollectionField​(java.lang.Class<?> clazz,
                                                java.lang.String fieldName,
                                                java.lang.Class<?> collectionElementType,
                                                boolean forceAccess)
        Checks whether the given fieldName in clazz is a collection field with elements of type collectionElementType.
        Parameters:
        clazz - The class to check for the given collection field
        fieldName - The name of the collection field
        collectionElementType - The type of the concrete element in the collection
        forceAccess - whether to break scope restrictions using the AccessibleObject.setAccessible(boolean) method. false will only match public fields.
        Returns:
        Whether or not the given fieldName in clazz is a collection field with elements of type collectionElementType.
      • listFromCommaSeparatedStringList

        public static java.util.List<java.lang.String> listFromCommaSeparatedStringList​(java.util.List<java.lang.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:
        inoutin.size()out.size()
        nullnull n.a.n.a.
        [null]null 1n.a.
        ["foo"]["foo"] 11
        ["foo,bar"] ["foo", "bar"] 12
        ["foo", "bar"] ["foo", "bar"] 22
        ["foo,humpty", "bar,dumpty"] ["foo", "humpty", "bar", "dumpty"] 24
        Parameters:
        listOfCommaSeparatedValues -
      • determineRestrictFields

        public static java.util.List<java.lang.String> determineRestrictFields​(org.springframework.util.MultiValueMap<java.lang.String,​java.lang.String> requestedFilter,
                                                                               java.lang.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 the 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.

        Parameters:
        requestedFilter -
        entityClass -
      • validFieldNamesWithCastedValues

        public static org.springframework.util.MultiValueMap<java.lang.String,​java.lang.Object> validFieldNamesWithCastedValues​(org.springframework.util.MultiValueMap<java.lang.String,​java.lang.String> requestedFilter,
                                                                                                                                      java.lang.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: