Class EntityUtil


  • public class EntityUtil
    extends Object
    Author:
    Nils Bühner, terrestris GmbH & Co. KG
    • 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
    • Constructor Detail

      • EntityUtil

        public EntityUtil()
    • 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 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 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:
        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 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 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<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: