Package de.hybris.platform.cockpit.util
Class TypeTools
java.lang.Object
de.hybris.platform.cockpit.util.TypeTools
Usefull utility methods for dealing with the cockpit type system.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckInstanceOfCatalogVersion(TypeService typeService, TypedObject object) Check instance of catalog version.static booleancheckInstanceOfCategory(TypeService typeService, TypedObject object) Check instance of category.static booleancheckInstanceOfMedia(TypeService typeService, TypedObject object) Check instance of media.static booleancheckInstanceOfProduct(TypeService typeService, TypedObject object) Check instance of product.static Objectcontainer2Item(TypeService typeService, Object containerValue) Converts typed object or collection of typed objects to item (or collection of them.static <E> Collection<E>createCollection(Class<? extends Collection> clazz, Collection<E> items) Creates a new collection with the same or similar* type toclazz.static ObjectValueContainercreateValueContainer(TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos) Creates the value container.static ObjectValueContainercreateValueContainer(TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos, boolean lazyLoad) egacy API relying on ZK dependency injectionstatic ObjectValueContainercreateValueContainer(ObjectValueHandlerRegistry valueHandlerRegistry, TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos, boolean lazyLoad) Creates the value container.static voidfilterOutRemovedItems(List<? extends TypedObject> items) Filters out removed items.getAllAttributes(TypedObject typedObject) Gets all attributes and their possible values from TypedObject.static Map<PropertyDescriptor,Object> getAllDefaultValues(TypeService typeService, ObjectTemplate template, Set<String> languageIsos) Gets the all default values.static Set<ObjectType>getAllSubtypes(ObjectType type) Gets the all subtypes.static List<ObjectType>getAllSupertypes(ObjectType type) Gets the all supertypes.static TypeServiceDeprecated.since 6.3, will be removed without replacement.static StringgetEnumName(HybrisEnumValue hybrisEnum) Get the localized name of an hybris enum.getInitialValues(ObjectType type, TypedObject baseItem, TypeService typeService, UIConfigurationService configurationService) Gets the initial values.static Set<PropertyDescriptor>getMandatoryAttributes(ObjectType type, boolean creationMode) Gets the mandatory attributes.static Set<PropertyDescriptor>getMandatoryAttributes(ObjectType type, boolean creationMode, PropertyService propertyService) Same asgetMandatoryAttributes(ObjectType, boolean)but usesPropertyServiceto check if mandatory.static ModelServiceDeprecated.since 6.3, will be removed without replacement.static StringgetMultiplicityString(PropertyDescriptor propertyDescriptor) Deprecated.since 6.3, usePropertyService.getMultiplicityString(PropertyDescriptor)instead.static ObjectgetObjectAttributeValue(TypedObject object, String attributeQualifier, TypeService typeService) Deprecated.since 6.3, useValueService.getValue(TypedObject, PropertyDescriptor)instead.static Set<PropertyDescriptor>getOmittedProperties(ObjectValueContainer valueContainer, ObjectTemplate template, boolean creationMode) Gets the omitted properties.static Set<PropertyDescriptor>getOmittedProperties(ObjectValueContainer valueContainer, Set<PropertyDescriptor> descriptors, boolean creationMode) Gets the omitted properties basing on given set of property descriptors.static ObjectgetPropertyValue(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor) Reads the value of the given pd.static StringgetPropertyValueAsString(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor) Reads the value of the given pd and retuns is as a String.static List<ObjectTemplate>getTemplatesForCreation(TypeService typeService, BaseType type) Gets the templates for creation.static List<Map<ObjectTemplate,Integer>> getTemplatesForCreationWithDepth(TypeService typeService, BaseType type, int initialDepth, boolean showAbstract) Gets the templates for creation with depth.static StringgetTypeDescription(BaseType type, TypeService typeService) Deprecated.since 6.3, useObjectType.getDescription()instead.static StringgetTypeName(BaseType type, TypeService typeService) Deprecated.since 6.3, useObjectType.getName()instead.static StringgetValueAsString(LabelService labelService, Object value) Returns a string representation of a value, where value can be a TypedObject, a collection of TypedObject (the LabelService is used to get the labels) or any other Object (toString() is used).static StringgetValueAsString(LabelService labelService, Object value, int size) static ObjectTemplategetValueTypeAsObjectTemplate(PropertyDescriptor propertyDescriptor, TypeService typeService) Gets the value type as object template.static booleanhasSupertype(ObjectType type, ObjectType supertype) Checks for supertype.static booleanisEditable(SystemService systemService, ObjectType type, PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, useUIAccessRightServiceisWritable methods instead.protected static booleanisEmptyLocalizedValue(Map<String, Object> value) Checks if is empty localized value.protected static booleanisEmptyValue(Object value) Checks if is empty value.static booleanisInitial(PropertyDescriptor propertyDescriptor) Deprecated.since 6.3, usePropertyService.isInitial(PropertyDescriptor)instead.static booleanisMandatory(PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, usePropertyService.isMandatory(PropertyDescriptor, boolean)instead.static booleanisPartof(PropertyDescriptor propertyDescriptor) Deprecated.since 6.3, usePropertyService.isPartof(PropertyDescriptor)instead.static booleanisReadable(SystemService systemService, ObjectType type, PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, useUIAccessRightServiceisReadable methods instead.static Objectitem2Container(TypeService typeService, Object value) Converts item or collection of items to typed objects (or collection of them).itemToPkList(Collection<? extends Item> items) Deprecated.since 6.3, will be removed without replacement.multiEdit(PropertyDescriptor propertyDesc, String languageIso, List<TypedObject> items, Object value) Multi edit.static booleanprimitiveValue(Boolean value) Deprecated.since 6.3, useBooleanUtils.toBoolean(Boolean)instead.static intprimitiveValue(Integer value) Returns the primitive value for the given integer or 0 if null.static booleanpropertyBelongsTo(TypeService typeService, Set<ObjectType> types, PropertyDescriptor propertyDescriptor) Property belongs to.
-
Constructor Details
-
TypeTools
public TypeTools()
-
-
Method Details
-
getValueAsString
Returns a string representation of a value, where value can be a TypedObject, a collection of TypedObject (the LabelService is used to get the labels) or any other Object (toString() is used).- Parameters:
labelService- the label servicevalue- the value- Returns:
- the string representation
-
getValueAsString
-
getTypeName
Deprecated.since 6.3, useObjectType.getName()instead.Get the type name in the current session language.- Parameters:
type- the typetypeService- the typeservice- Returns:
- the type name
-
getTypeDescription
Deprecated.since 6.3, useObjectType.getDescription()instead.Get the type description in the current session language.- Parameters:
type- the typetypeService- the typeservice- Returns:
- the type description
-
getInitialValues
public static Map<String,Object> getInitialValues(ObjectType type, TypedObject baseItem, TypeService typeService, UIConfigurationService configurationService) Gets the initial values.- Parameters:
type- the typebaseItem- the base itemtypeService- the type serviceconfigurationService- the configuration service- Returns:
- the initial values
-
getMultiplicityString
Deprecated.since 6.3, usePropertyService.getMultiplicityString(PropertyDescriptor)instead.Gets the multiplicity string.- Parameters:
propertyDescriptor- the property descriptor- Returns:
- the multiplicity string
-
getValueTypeAsObjectTemplate
public static ObjectTemplate getValueTypeAsObjectTemplate(PropertyDescriptor propertyDescriptor, TypeService typeService) Gets the value type as object template.- Parameters:
propertyDescriptor- the property descriptortypeService- the type service- Returns:
- the value type as object template
-
getObjectAttributeValue
@Deprecated public static Object getObjectAttributeValue(TypedObject object, String attributeQualifier, TypeService typeService) Deprecated.since 6.3, useValueService.getValue(TypedObject, PropertyDescriptor)instead.Gets the object attribute value.- Parameters:
object- the objectattributeQualifier- the attribute qualifiertypeService- the type service- Returns:
- the object attribute value
-
createValueContainer
public static ObjectValueContainer createValueContainer(TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos) Creates the value container.- Parameters:
typedObject- the typed objectpropertyDescriptors- the property descriptorslangIsos- the lang isos- Returns:
- the object value container
-
createValueContainer
public static ObjectValueContainer createValueContainer(ObjectValueHandlerRegistry valueHandlerRegistry, TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos, boolean lazyLoad) Creates the value container.- Parameters:
typedObject- the typed objectpropertyDescriptors- the property descriptorslangIsos- the lang isoslazyLoad- the lazy load- Returns:
- the object value container
-
createValueContainer
public static ObjectValueContainer createValueContainer(TypedObject typedObject, Set<PropertyDescriptor> propertyDescriptors, Set<String> langIsos, boolean lazyLoad) egacy API relying on ZK dependency injection- Parameters:
typedObject-propertyDescriptors-langIsos-lazyLoad-- Returns:
-
getAllSupertypes
Gets the all supertypes.- Parameters:
type- the type- Returns:
- the all supertypes
-
getAllSubtypes
Gets the all subtypes.- Parameters:
type- the type- Returns:
- the all subtypes
-
hasSupertype
Checks for supertype.- Parameters:
type- the typesupertype- the supertype- Returns:
- true, if successful
-
itemToPkList
Deprecated.since 6.3, will be removed without replacement.Item to pk list.- Parameters:
items- the items- Returns:
- the list < p k>
-
getTemplatesForCreation
Gets the templates for creation.- Parameters:
typeService- the type servicetype- the type- Returns:
- the templates for creation
-
getTemplatesForCreationWithDepth
public static List<Map<ObjectTemplate,Integer>> getTemplatesForCreationWithDepth(TypeService typeService, BaseType type, int initialDepth, boolean showAbstract) Gets the templates for creation with depth.- Parameters:
typeService- the type servicetype- the typeinitialDepth- the initial depthshowAbstract- the show abstract- Returns:
- the templates for creation with depth
-
isEditable
@Deprecated public static boolean isEditable(SystemService systemService, ObjectType type, PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, useUIAccessRightServiceisWritable methods instead.Checks if is editable.- Parameters:
systemService- the system servicetype- object typepropertyDescriptor- property descriptorcreationMode- the creation mode- Returns:
- true, if is editable
-
isReadable
@Deprecated public static boolean isReadable(SystemService systemService, ObjectType type, PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, useUIAccessRightServiceisReadable methods instead.Checks if is readable.- Parameters:
systemService- the system servicetype- object typepropertyDescriptor- property descriptorcreationMode- the creation mode- Returns:
- true, if is readable
-
isInitial
Deprecated.since 6.3, usePropertyService.isInitial(PropertyDescriptor)instead.Checks if is initial.- Parameters:
propertyDescriptor- the pd- Returns:
- true, if is initial
-
isPartof
Deprecated.since 6.3, usePropertyService.isPartof(PropertyDescriptor)instead. -
item2Container
Converts item or collection of items to typed objects (or collection of them). If the value is no item/collection of items the unprocessed value is returned.- Parameters:
typeService- the TypeServicevalue- the value- Returns:
- converted value
-
container2Item
Converts typed object or collection of typed objects to item (or collection of them. If the value is no typed object/collection of typed objects the unprocessed value is returned.- Parameters:
typeService- the TypeServicecontainerValue- the value- Returns:
- converted value
-
checkInstanceOfCategory
Check instance of category.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfCatalogVersion
Check instance of catalog version.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfProduct
Check instance of product.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfMedia
Check instance of media.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
multiEdit
public static List<String> multiEdit(PropertyDescriptor propertyDesc, String languageIso, List<TypedObject> items, Object value) Multi edit.- Parameters:
propertyDesc- the property desclanguageIso- the language isoitems- the itemsvalue- the value- Returns:
- the list< string>
-
primitiveValue
Deprecated.since 6.3, useBooleanUtils.toBoolean(Boolean)instead.Primitive value.- Parameters:
value- the value- Returns:
- true, if successful
-
primitiveValue
Returns the primitive value for the given integer or 0 if null. -
getCoreTypeService
Deprecated.since 6.3, will be removed without replacement. Use proper dependency injection to get the typeService.Gets the core type service.- Returns:
- the core type service
-
getModelService
Deprecated.since 6.3, will be removed without replacement. Use proper dependency injection to get the modelService.Gets the model service.- Returns:
- the model service
-
getOmittedProperties
public static Set<PropertyDescriptor> getOmittedProperties(ObjectValueContainer valueContainer, ObjectTemplate template, boolean creationMode) Gets the omitted properties.- Parameters:
valueContainer- the value containertemplate- the templatecreationMode- the creation mode- Returns:
- the omitted properties
-
getOmittedProperties
public static Set<PropertyDescriptor> getOmittedProperties(ObjectValueContainer valueContainer, Set<PropertyDescriptor> descriptors, boolean creationMode) Gets the omitted properties basing on given set of property descriptors. The descriptors are checked if mandatory and if true - added to an appropriate collection. After that a check is done if the required values are not empty. It allows to collect a list of omited properties this way.- Parameters:
valueContainer- the value containerdescriptors- the descriptorscreationMode- the creation mode- Returns:
- the omitted properties
-
getMandatoryAttributes
Gets the mandatory attributes. Can only be used in a zk environment. UsegetMandatoryAttributes(ObjectType, boolean, PropertyService)from outside zk.- Parameters:
type- the typecreationMode- the creation mode- Returns:
- the mandatory attributes
-
getMandatoryAttributes
public static Set<PropertyDescriptor> getMandatoryAttributes(ObjectType type, boolean creationMode, PropertyService propertyService) Same asgetMandatoryAttributes(ObjectType, boolean)but usesPropertyServiceto check if mandatory. -
isMandatory
@Deprecated public static boolean isMandatory(PropertyDescriptor propertyDescriptor, boolean creationMode) Deprecated.since 6.3, usePropertyService.isMandatory(PropertyDescriptor, boolean)instead.Checks if is mandatory.- Parameters:
propertyDescriptor- the pdcreationMode- the creation mode- Returns:
- true, if is mandatory
-
propertyBelongsTo
public static boolean propertyBelongsTo(TypeService typeService, Set<ObjectType> types, PropertyDescriptor propertyDescriptor) Property belongs to.- Parameters:
typeService- the type servicetypes- the typespropertyDescriptor- the pd- Returns:
- true, if successful
-
getAllDefaultValues
public static Map<PropertyDescriptor,Object> getAllDefaultValues(TypeService typeService, ObjectTemplate template, Set<String> languageIsos) Gets the all default values.- Parameters:
typeService- the type servicetemplate- the templatelanguageIsos- the language isos- Returns:
- the all default values
-
isEmptyValue
Checks if is empty value.- Parameters:
value- the value- Returns:
- true, if is empty value
-
isEmptyLocalizedValue
Checks if is empty localized value.- Parameters:
value- the value- Returns:
- true, if is empty localized value
-
getAllAttributes
Gets all attributes and their possible values from TypedObject.- Parameters:
typedObject- the typed object- Returns:
- the all attributes map
-
getEnumName
Get the localized name of an hybris enum. If there is no name set, the code will be returned.- Parameters:
hybrisEnum- the hybris enum- Returns:
- the localized name of the enum or the code if the enum is no EnumerationValue
-
filterOutRemovedItems
Filters out removed items.- Parameters:
items- the items
-
getPropertyValueAsString
public static String getPropertyValueAsString(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor) Reads the value of the given pd and retuns is as a String. If no readable, ValueHandler.NOT_READABLE_VALUE.toString() will be returned. If some problem occurs, an empty string will be returned. -
getPropertyValue
public static Object getPropertyValue(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor) Reads the value of the given pd. If no readable, ValueHandler.NOT_READABLE_VALUE will be returned. If some problem occurs, null will be returned. -
createCollection
public static <E> Collection<E> createCollection(Class<? extends Collection> clazz, Collection<E> items) Creates a new collection with the same or similar* type to
clazz. The created collection will contains elements stored byitemscollection.*If cannot create a new instance with the same type, then it will creates:
- Parameters:
clazz- the requested type for new collection.items- the collection whose elements are to be placed into this collection.- Returns:
- the new collection which contains
-