Class EntityUtils
java.lang.Object
com.foreach.across.modules.entity.util.EntityUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <Y> List<Y>
static <Y> org.springframework.data.domain.Page<Y>
Create aPage
from anyIterable
.static String
combineDisplayNames
(String first, String... propertyNames) static org.springframework.data.domain.Sort
combineSortSpecifiers
(org.springframework.data.domain.Sort... sorts) Merge any number ofSort
instances into a single instance.static String
generateDisplayName
(String propertyName) static String
generateEntityName
(Class<?> entityType) Generate a default entity name for an entity type.static EntityTypeDescriptor
resolveEntityTypeDescriptor
(org.springframework.core.convert.TypeDescriptor typeDescriptor, EntityRegistry entityRegistry) Inspects aTypeDescriptor
to retrieve the targetTypeDescriptor
if possible.static org.springframework.data.domain.Pageable
translateSort
(org.springframework.data.domain.Pageable pageable, EntityPropertyRegistry propertyRegistry) Translates theSort
property attached to this pageable.static org.springframework.data.domain.Sort
translateSort
(org.springframework.data.domain.Sort sort, EntityPropertyRegistry propertyRegistry) Translates theSort
instance based on the specifiedEntityPropertyRegistry
.
-
Constructor Details
-
EntityUtils
public EntityUtils()
-
-
Method Details
-
generateEntityName
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 aTypeDescriptor
to retrieve the targetTypeDescriptor
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 genericMap
, no target type can be resolved. If the type extends a collection type but theEntityRegistry
contains an entry for that specific type, that target type will be returned. Else the member will still be resolved. If the type isOptional
, the member will be returned. Ifnull
is passed as the argument for a type descriptor, a generic descriptor for aObject
will be returned.- Parameters:
typeDescriptor
- to inspect for the target type- Returns:
- resolved descriptor
-
generateDisplayName
-
combineDisplayNames
-
translateSort
public static org.springframework.data.domain.Pageable translateSort(org.springframework.data.domain.Pageable pageable, EntityPropertyRegistry propertyRegistry) Translates theSort
property attached to this pageable. Will create a newPageable
if sorting is modified. SeetranslateSort(Sort, EntityPropertyRegistry)
for more details.- Parameters:
pageable
- instance to be translatedpropertyRegistry
- 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 specifiedEntityPropertyRegistry
. For everySort.Order
entry a property will be looked up in the registry. If a property is found, theSort.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 theSort.Order.getNullHandling()
andSort.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 translatedpropertyRegistry
- 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 ofSort
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
Create aPage
from anyIterable
.- Parameters:
collection
- contains the items in the page- Returns:
- Page instance
-
asList
Create aList
from anyIterable
. 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
-