Package org.openremote.model.util
Class ValueUtil
java.lang.Object
org.openremote.model.util.ValueUtil
Utilities for working with values/JSON and asset model
Custom descriptors can be added by simply adding new Asset
/Agent
sub types and following the discovery
rules described in StandardModelProvider
; alternatively a custom AssetModelProvider
implementation
can be created and discovered with the ServiceLoader
or manually added to this class via
getModelProviders()
collection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
static interface
AFunctionalInterface
for populating theConstraintViolation.getPropertyPath()
for the value being validated (e.g. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static Map
<String, AssetTypeInfo> protected static List
<AssetModelProvider> protected static com.kjetland.jackson.jsonSchema.JsonSchemaGenerator
static com.fasterxml.jackson.databind.ObjectMapper
static Logger
protected static Map
<String, MetaItemDescriptor<?>> static final String
protected static jakarta.validation.Validator
protected static Map
<String, ValueDescriptor<?>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
applyValueFilters
(Object value, ValueFilter... filters) Apply the specified set ofValueFilter
s to the specified valuestatic String
asJSONOrThrow
(Object object) protected static AssetTypeInfo
buildAssetInfoFromClass
(Class<? extends Asset<?>> assetClass, Map<String, List<NameHolder>> classDescriptorMap) protected static AssetTypeInfo
buildAssetInfoFromName
(String name, Map<String, List<NameHolder>> classDescriptorMap) static byte[]
bytesFromBinaryString
(String binary) static byte[]
bytesFromHexString
(String hex) static String
bytesToBinaryString
(byte[] bytes) static String
bytesToHexString
(byte[] bytes) static <T> T
clone
(T object) static com.fasterxml.jackson.databind.ObjectMapper
configureObjectMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) static <T> T
static <T> Predicate
<T> distinctByKey
(Function<? super T, ?> keyExtractor) static String
doDynamicTimeReplace
(String str, Instant instant) static String
doDynamicValueReplace
(String str, Object value) protected static void
static Object
findFirstNonNullElement
(Collection<?> collection) static Map.Entry
<?, ?> findFirstNonNullEntry
(Map<?, ?> map) static <T extends Agent<T,
?, ?>>
Optional<AgentDescriptor<T, ?, ?>> getAgentDescriptor
(Class<T> agentType) static Optional
<AgentDescriptor<?, ?, ?>> getAgentDescriptor
(String agentType) protected static Class<?>[]
static Class
<?> getArrayClass
(Class<?> componentType) getAssetClass
(String assetType) getAssetClasses
(String parentType) getAssetClasses
(AssetModelProvider assetModelProvider) static <T extends Asset<?>>
Optional<AssetDescriptor<T>> getAssetDescriptor
(Class<T> assetType) static Optional
<AssetDescriptor<?>> getAssetDescriptor
(String assetType) static AssetDescriptor<?>[]
getAssetDescriptors
(String parentType) static <T extends Asset<?>>
Optional<AssetTypeInfo> getAssetInfo
(Class<T> assetType) static Optional
<AssetTypeInfo> getAssetInfo
(String assetType) static AssetTypeInfo[]
getAssetInfos
(String parentType) getBoolean
(Object value) getBooleanCoerced
(Object value) protected static List
<NameHolder> getDescriptorFields
(Class<?> type) Extract public static field values that are of typeAssetDescriptor
,AttributeDescriptor
,MetaItemDescriptor
orValueDescriptor
.getDoubleCoerced
(Object value) getInteger
(Object value) getIntegerCoerced
(Object value) getLongCoerced
(Object value) static Optional
<MetaItemDescriptor<?>> getMetaItemDescriptor
(String name) static Map
<String, MetaItemDescriptor<?>> static <T extends Asset<?>>
Optional<MetaItemDescriptor<?>[]> getMetaItemDescriptors
(Class<T> assetType) static Optional
<MetaItemDescriptor<?>[]> getMetaItemDescriptors
(String assetType) static List
<AssetModelProvider> static Object
getObjectFieldValue
(Object object, Field field) static Object
getObjectFieldValue
(Object object, String fieldName) static Object[]
getObjectFieldValues
(Object object, Field[] fields) static Object[]
getObjectFieldValues
(Object object, String[] fieldNames) static <T> com.fasterxml.jackson.core.type.TypeReference
<Attribute<T>> static com.fasterxml.jackson.databind.JsonNode
Returns the schema for the specified typegetStringCoerced
(Object value) static jakarta.validation.Validator
static <T> Optional
<T> static <T> Optional
<T> static <T> Optional
<T> getValueCoerced
(Object value, Class<T> type) Basic type coercion/casting of values; utilises Jackson's underlying type coercion/casting mechanismstatic Optional
<ValueDescriptor<?>> getValueDescriptor
(String name) static ValueDescriptor
<?> getValueDescriptorForValue
(Object value) static Map
<String, ValueDescriptor<?>> static <T extends Asset<?>>
Optional<ValueDescriptor<?>[]> getValueDescriptors
(Class<T> assetType) static Optional
<ValueDescriptor<?>[]> getValueDescriptors
(String assetType) static void
initialise
(Container container) static void
initialiseAssetAttributes
(Asset<?> asset) static boolean
static boolean
static boolean
isCollection
(Class<?> clazz) protected static boolean
static boolean
static boolean
static boolean
static boolean
static boolean
objectsEquals
(Object a, Object b) static boolean
static boolean
static <T> Optional
<T> static <T> Optional
<T> static <T> Optional
<T> static <T> Set
<jakarta.validation.ConstraintViolation<T>> Validates the supplied object using standard JSR-380 bean validation; therefore any type passed in here must follow the JSR-380 annotation requirements.static boolean
validateValue
(AttributeDescriptor<?> attributeDescriptor, ValueDescriptor<?> valueDescriptor, MetaHolder metaHolder, Instant now, jakarta.validation.ConstraintValidatorContext context, ValueUtil.ConstraintViolationPathProvider constraintBuilderProvider, Object value) Evaluate the validity of a value dynamically by extractingValueConstraint
s from the supplied parameters; each found constraint is then evaluated against the value supplied to the function.static boolean
validateValueConstraint
(jakarta.validation.ConstraintValidatorContext context, ValueUtil.ConstraintViolationPathProvider constraintViolationPathProvider, Instant now, ValueConstraint valueConstraint, Object value)
-
Field Details
-
LOG
-
JSON
public static com.fasterxml.jackson.databind.ObjectMapper JSON -
assetModelProviders
-
assetInfoMap
-
assetTypeMap
-
agentTypeMap
-
metaItemDescriptors
-
valueDescriptors
-
validator
protected static jakarta.validation.Validator validator -
generator
protected static com.kjetland.jackson.jsonSchema.JsonSchemaGenerator generator -
NULL_LITERAL
- See Also:
-
-
Constructor Details
-
ValueUtil
public ValueUtil()
-
-
Method Details
-
configureObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper configureObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
parse
-
parse
-
parse
-
parse
-
asJSON
-
asJSONOrThrow
public static String asJSONOrThrow(Object object) throws com.fasterxml.jackson.core.JsonProcessingException - Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getValue
-
getValue
-
getValueCoerced
Basic type coercion/casting of values; utilises Jackson's underlying type coercion/casting mechanism -
getString
-
getStringCoerced
-
getBoolean
-
getBooleanCoerced
-
getInteger
-
getIntegerCoerced
-
getDouble
-
getDoubleCoerced
-
getLong
-
getLongCoerced
-
distinctByKey
-
convert
-
isArray
-
isBoolean
-
isNumber
-
isString
-
isMap
-
isCollection
-
isObject
-
getArrayClass
- Throws:
ClassNotFoundException
-
applyValueFilters
Apply the specified set ofValueFilter
s to the specified value -
clone
public static <T> T clone(T object) -
getRef
-
findFirstNonNullElement
-
findFirstNonNullEntry
-
getAssetInfos
-
getAssetClasses
-
getAssetClass
-
getAssetInfo
-
getAssetInfo
-
getAssetDescriptors
-
getAssetDescriptor
public static <T extends Asset<?>> Optional<AssetDescriptor<T>> getAssetDescriptor(Class<T> assetType) -
getAssetDescriptor
-
getAgentDescriptor
public static <T extends Agent<T,?, Optional<AgentDescriptor<T,?>> ?, getAgentDescriptor?>> (Class<T> agentType) -
getAgentDescriptor
-
getMetaItemDescriptors
-
getMetaItemDescriptors
public static <T extends Asset<?>> Optional<MetaItemDescriptor<?>[]> getMetaItemDescriptors(Class<T> assetType) -
getMetaItemDescriptors
-
getMetaItemDescriptor
-
getValueDescriptors
-
getValueDescriptors
public static <T extends Asset<?>> Optional<ValueDescriptor<?>[]> getValueDescriptors(Class<T> assetType) -
getValueDescriptors
-
getValueDescriptor
-
getValueDescriptorForValue
-
getModelProviders
-
initialise
- Throws:
IllegalStateException
-
doSchemaInit
protected static void doSchemaInit() -
getAgentLinkClasses
-
validate
public static <T> Set<jakarta.validation.ConstraintViolation<T>> validate(@NotNull T obj, Class<?>... groups) Validates the supplied object using standard JSR-380 bean validation; therefore any type passed in here must follow the JSR-380 annotation requirements. -
getValidator
public static jakarta.validation.Validator getValidator() -
validateValue
public static boolean validateValue(AttributeDescriptor<?> attributeDescriptor, ValueDescriptor<?> valueDescriptor, MetaHolder metaHolder, Instant now, jakarta.validation.ConstraintValidatorContext context, ValueUtil.ConstraintViolationPathProvider constraintBuilderProvider, Object value) Evaluate the validity of a value dynamically by extractingValueConstraint
s from the supplied parameters; each found constraint is then evaluated against the value supplied to the function.Unfortunately JSR-380 can't be used (even Hibernate validator's programmatic API) because validators are type centric but here the type (e.g.
Attribute
orAttributeInfo
) is fixed but the constraints to be applied are dynamic, would be nice if there was a solution to this problem but this works for now. -
validateValueConstraint
public static boolean validateValueConstraint(jakarta.validation.ConstraintValidatorContext context, ValueUtil.ConstraintViolationPathProvider constraintViolationPathProvider, Instant now, ValueConstraint valueConstraint, Object value) -
getSchema
Returns the schema for the specified type -
initialiseAssetAttributes
- Throws:
IllegalStateException
-
getObjectFieldValues
-
getObjectFieldValues
-
getObjectFieldValue
-
getObjectFieldValue
-
objectsEquals
-
objectsEqualsWithJSONFallback
-
objectsEqualsUsingJSON
-
isGetter
-
getAssetClasses
protected static Set<Class<? extends Asset<?>>> getAssetClasses(AssetModelProvider assetModelProvider) -
getDescriptorFields
Extract public static field values that are of typeAssetDescriptor
,AttributeDescriptor
,MetaItemDescriptor
orValueDescriptor
. -
buildAssetInfoFromName
protected static AssetTypeInfo buildAssetInfoFromName(String name, Map<String, List<NameHolder>> classDescriptorMap) throws IllegalStateException- Throws:
IllegalStateException
-
buildAssetInfoFromClass
protected static AssetTypeInfo buildAssetInfoFromClass(Class<? extends Asset<?>> assetClass, Map<String, List<NameHolder>> classDescriptorMap) throws IllegalStateException- Throws:
IllegalStateException
-
bytesToHexString
-
bytesFromHexString
-
bytesToBinaryString
-
bytesFromBinaryString
-
doDynamicTimeReplace
-
doDynamicValueReplace
-