Class EntityUtils

java.lang.Object
com.foreach.across.modules.entity.util.EntityUtils

public class EntityUtils extends Object
  • Constructor Details

    • EntityUtils

      public EntityUtils()
  • Method Details

    • generateEntityName

      public static String generateEntityName(Class<?> entityType)
      Generate a default entity name for an entity type.
      Parameters:
      entityType - for which to generate the name
      Returns:
      default name
    • resolveEntityTypeDescriptor

      public static EntityTypeDescriptor resolveEntityTypeDescriptor(org.springframework.core.convert.TypeDescriptor typeDescriptor, EntityRegistry entityRegistry)
      Inspects a TypeDescriptor to retrieve the target TypeDescriptor if possible. This method is meant to determine the target entity type of for example a collection or array descriptor. In the latter case the target type would usually be the member type of the descriptor.

      If the type descriptor is neither array nor collection, the original type descriptor is considered to be the target. If the type descriptor is representing a class that extends any of the collection types, its member will be used.

      In case of a generic Map, no target type can be resolved.

      If the type extends a collection type but the EntityRegistry contains an entry for that specific type, that target type will be returned. Else the member will still be resolved. If the type is Optional, the member will be returned.

      If null is passed as the argument for a type descriptor, a generic descriptor for a Object will be returned.

      Parameters:
      typeDescriptor - to inspect for the target type
      Returns:
      resolved descriptor
    • generateDisplayName

      public static String generateDisplayName(String propertyName)
    • combineDisplayNames

      public static String combineDisplayNames(String first, String... propertyNames)
    • translateSort

      public static org.springframework.data.domain.Pageable translateSort(org.springframework.data.domain.Pageable pageable, EntityPropertyRegistry propertyRegistry)
      Translates the Sort property attached to this pageable. Will create a new Pageable if sorting is modified. See translateSort(Sort, EntityPropertyRegistry) for more details.
      Parameters:
      pageable - instance to be translated
      propertyRegistry - to be used for looking up matching properties
      Returns:
      modified instance or same if unmodified
    • translateSort

      @NonNull public static org.springframework.data.domain.Sort translateSort(org.springframework.data.domain.Sort sort, EntityPropertyRegistry propertyRegistry)

      Translates the Sort instance based on the specified EntityPropertyRegistry. For every Sort.Order entry a property will be looked up in the registry. If a property is found, the Sort.Order attribute of the property will be fetched and if one is specified, it will be used as the basis for the new entry. Especially the Sort.Order.getNullHandling() and Sort.Order.isIgnoreCase() settings will be copied. In case null handling is native, a fixed null handling will be applied depending on the direction.

      Order entries for which no property or property attribute can be found, will be left unchanged.

      Parameters:
      sort - instance to be translated
      propertyRegistry - to be used for looking up matching properties
      Returns:
      modified or possibly same instance if unmodified
    • combineSortSpecifiers

      public static org.springframework.data.domain.Sort combineSortSpecifiers(org.springframework.data.domain.Sort... sorts)
      Merge any number of Sort instances into a single instance. Properties will only be applied once, the first time they are encountered.
      Parameters:
      sorts - to combine
      Returns:
      combined sort or null if no sort orders were specified
    • asPage

      public static <Y> org.springframework.data.domain.Page<Y> asPage(Iterable<Y> collection)
      Create a Page from any Iterable.
      Parameters:
      collection - contains the items in the page
      Returns:
      Page instance
    • asList

      public static <Y> List<Y> asList(Iterable<Y> iterable)
      Create a List from any Iterable. If the iterable is a list the same instance will be returned. In all other cases a new instance will be created from the elements of the iterable.
      Type Parameters:
      Y - element type
      Parameters:
      iterable - containing the elements
      Returns:
      List instance