Package de.hybris.platform.cockpit.util
Class TypeTools
- java.lang.Object
-
- de.hybris.platform.cockpit.util.TypeTools
-
public class TypeTools extends java.lang.ObjectUsefull utility methods for dealing with the cockpit type system.
-
-
Constructor Summary
Constructors Constructor Description TypeTools()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static 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 java.lang.Objectcontainer2Item(TypeService typeService, java.lang.Object containerValue)Converts typed object or collection of typed objects to item (or collection of them.static <E> java.util.Collection<E>createCollection(java.lang.Class<? extends java.util.Collection> clazz, java.util.Collection<E> items)Creates a new collection with the same or similar* type toclazz.static ObjectValueContainercreateValueContainer(TypedObject typedObject, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.String> langIsos)Creates the value container.static ObjectValueContainercreateValueContainer(TypedObject typedObject, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.String> langIsos, boolean lazyLoad)egacy API relying on ZK dependency injectionstatic ObjectValueContainercreateValueContainer(ObjectValueHandlerRegistry valueHandlerRegistry, TypedObject typedObject, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.String> langIsos, boolean lazyLoad)Creates the value container.static voidfilterOutRemovedItems(java.util.List<? extends TypedObject> items)Filters out removed items.static java.util.Map<java.lang.String,java.lang.Object>getAllAttributes(TypedObject typedObject)Gets all attributes and their possible values from TypedObject.static java.util.Map<PropertyDescriptor,java.lang.Object>getAllDefaultValues(TypeService typeService, ObjectTemplate template, java.util.Set<java.lang.String> languageIsos)Gets the all default values.static java.util.Set<ObjectType>getAllSubtypes(ObjectType type)Gets the all subtypes.static java.util.List<ObjectType>getAllSupertypes(ObjectType type)Gets the all supertypes.static TypeServicegetCoreTypeService()Deprecated.since 6.3, will be removed without replacement.static java.lang.StringgetEnumName(HybrisEnumValue hybrisEnum)Get the localized name of an hybris enum.static java.util.Map<java.lang.String,java.lang.Object>getInitialValues(ObjectType type, TypedObject baseItem, TypeService typeService, UIConfigurationService configurationService)Gets the initial values.static java.util.Set<PropertyDescriptor>getMandatoryAttributes(ObjectType type, boolean creationMode)Gets the mandatory attributes.static java.util.Set<PropertyDescriptor>getMandatoryAttributes(ObjectType type, boolean creationMode, PropertyService propertyService)Same asgetMandatoryAttributes(ObjectType, boolean)but usesPropertyServiceto check if mandatory.static ModelServicegetModelService()Deprecated.since 6.3, will be removed without replacement.static java.lang.StringgetMultiplicityString(PropertyDescriptor propertyDescriptor)Deprecated.since 6.3, usePropertyService.getMultiplicityString(PropertyDescriptor)instead.static java.lang.ObjectgetObjectAttributeValue(TypedObject object, java.lang.String attributeQualifier, TypeService typeService)Deprecated.since 6.3, useValueService.getValue(TypedObject, PropertyDescriptor)instead.static java.util.Set<PropertyDescriptor>getOmittedProperties(ObjectValueContainer valueContainer, ObjectTemplate template, boolean creationMode)Gets the omitted properties.static java.util.Set<PropertyDescriptor>getOmittedProperties(ObjectValueContainer valueContainer, java.util.Set<PropertyDescriptor> descriptors, boolean creationMode)Gets the omitted properties basing on given set of property descriptors.static java.lang.ObjectgetPropertyValue(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor)Reads the value of the given pd.static java.lang.StringgetPropertyValueAsString(ValueService valueService, TypedObject object, PropertyDescriptor propertyDescriptor)Reads the value of the given pd and retuns is as a String.static java.util.List<ObjectTemplate>getTemplatesForCreation(TypeService typeService, BaseType type)Gets the templates for creation.static java.util.List<java.util.Map<ObjectTemplate,java.lang.Integer>>getTemplatesForCreationWithDepth(TypeService typeService, BaseType type, int initialDepth, boolean showAbstract)Gets the templates for creation with depth.static java.lang.StringgetTypeDescription(BaseType type, TypeService typeService)Deprecated.since 6.3, useObjectType.getDescription()instead.static java.lang.StringgetTypeName(BaseType type, TypeService typeService)Deprecated.since 6.3, useObjectType.getName()instead.static java.lang.StringgetValueAsString(LabelService labelService, java.lang.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 java.lang.StringgetValueAsString(LabelService labelService, java.lang.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(java.util.Map<java.lang.String,java.lang.Object> value)Checks if is empty localized value.protected static booleanisEmptyValue(java.lang.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 java.lang.Objectitem2Container(TypeService typeService, java.lang.Object value)Converts item or collection of items to typed objects (or collection of them).static java.util.List<PK>itemToPkList(java.util.Collection<? extends Item> items)Deprecated.since 6.3, will be removed without replacement.static java.util.List<java.lang.String>multiEdit(PropertyDescriptor propertyDesc, java.lang.String languageIso, java.util.List<TypedObject> items, java.lang.Object value)Multi edit.static booleanprimitiveValue(java.lang.Boolean value)Deprecated.since 6.3, useBooleanUtils.toBoolean(Boolean)instead.static intprimitiveValue(java.lang.Integer value)Returns the primitive value for the given integer or 0 if null.static booleanpropertyBelongsTo(TypeService typeService, java.util.Set<ObjectType> types, PropertyDescriptor propertyDescriptor)Property belongs to.
-
-
-
Method Detail
-
getValueAsString
public static java.lang.String getValueAsString(LabelService labelService, java.lang.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).- Parameters:
labelService- the label servicevalue- the value- Returns:
- the string representation
-
getValueAsString
public static java.lang.String getValueAsString(LabelService labelService, java.lang.Object value, int size)
-
getTypeName
@Deprecated public static java.lang.String getTypeName(BaseType type, TypeService typeService)
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 public static java.lang.String getTypeDescription(BaseType type, TypeService typeService)
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 java.util.Map<java.lang.String,java.lang.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 public static java.lang.String getMultiplicityString(PropertyDescriptor propertyDescriptor)
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 java.lang.Object getObjectAttributeValue(TypedObject object, java.lang.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, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.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, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.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, java.util.Set<PropertyDescriptor> propertyDescriptors, java.util.Set<java.lang.String> langIsos, boolean lazyLoad)
egacy API relying on ZK dependency injection- Parameters:
typedObject-propertyDescriptors-langIsos-lazyLoad-- Returns:
-
getAllSupertypes
public static java.util.List<ObjectType> getAllSupertypes(ObjectType type)
Gets the all supertypes.- Parameters:
type- the type- Returns:
- the all supertypes
-
getAllSubtypes
public static java.util.Set<ObjectType> getAllSubtypes(ObjectType type)
Gets the all subtypes.- Parameters:
type- the type- Returns:
- the all subtypes
-
hasSupertype
public static boolean hasSupertype(ObjectType type, ObjectType supertype)
Checks for supertype.- Parameters:
type- the typesupertype- the supertype- Returns:
- true, if successful
-
itemToPkList
@Deprecated public static java.util.List<PK> itemToPkList(java.util.Collection<? extends Item> items)
Deprecated.since 6.3, will be removed without replacement.Item to pk list.- Parameters:
items- the items- Returns:
- the list < p k>
-
getTemplatesForCreation
public static java.util.List<ObjectTemplate> getTemplatesForCreation(TypeService typeService, BaseType type)
Gets the templates for creation.- Parameters:
typeService- the type servicetype- the type- Returns:
- the templates for creation
-
getTemplatesForCreationWithDepth
public static java.util.List<java.util.Map<ObjectTemplate,java.lang.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 public static boolean isInitial(PropertyDescriptor propertyDescriptor)
Deprecated.since 6.3, usePropertyService.isInitial(PropertyDescriptor)instead.Checks if is initial.- Parameters:
propertyDescriptor- the pd- Returns:
- true, if is initial
-
isPartof
@Deprecated public static boolean isPartof(PropertyDescriptor propertyDescriptor)
Deprecated.since 6.3, usePropertyService.isPartof(PropertyDescriptor)instead.
-
item2Container
public static java.lang.Object item2Container(TypeService typeService, java.lang.Object value)
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
public static java.lang.Object container2Item(TypeService typeService, java.lang.Object containerValue)
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
public static boolean checkInstanceOfCategory(TypeService typeService, TypedObject object)
Check instance of category.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfCatalogVersion
public static boolean checkInstanceOfCatalogVersion(TypeService typeService, TypedObject object)
Check instance of catalog version.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfProduct
public static boolean checkInstanceOfProduct(TypeService typeService, TypedObject object)
Check instance of product.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
checkInstanceOfMedia
public static boolean checkInstanceOfMedia(TypeService typeService, TypedObject object)
Check instance of media.- Parameters:
typeService- the type serviceobject- the object- Returns:
- true, if successful
-
multiEdit
public static java.util.List<java.lang.String> multiEdit(PropertyDescriptor propertyDesc, java.lang.String languageIso, java.util.List<TypedObject> items, java.lang.Object value)
Multi edit.- Parameters:
propertyDesc- the property desclanguageIso- the language isoitems- the itemsvalue- the value- Returns:
- the list< string>
-
primitiveValue
@Deprecated public static boolean primitiveValue(java.lang.Boolean value)
Deprecated.since 6.3, useBooleanUtils.toBoolean(Boolean)instead.Primitive value.- Parameters:
value- the value- Returns:
- true, if successful
-
primitiveValue
public static int primitiveValue(java.lang.Integer value)
Returns the primitive value for the given integer or 0 if null.
-
getCoreTypeService
@Deprecated public static TypeService 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 public static ModelService 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 java.util.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 java.util.Set<PropertyDescriptor> getOmittedProperties(ObjectValueContainer valueContainer, java.util.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
public static java.util.Set<PropertyDescriptor> getMandatoryAttributes(ObjectType type, boolean creationMode)
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 java.util.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, java.util.Set<ObjectType> types, PropertyDescriptor propertyDescriptor)
Property belongs to.- Parameters:
typeService- the type servicetypes- the typespropertyDescriptor- the pd- Returns:
- true, if successful
-
getAllDefaultValues
public static java.util.Map<PropertyDescriptor,java.lang.Object> getAllDefaultValues(TypeService typeService, ObjectTemplate template, java.util.Set<java.lang.String> languageIsos)
Gets the all default values.- Parameters:
typeService- the type servicetemplate- the templatelanguageIsos- the language isos- Returns:
- the all default values
-
isEmptyValue
protected static boolean isEmptyValue(java.lang.Object value)
Checks if is empty value.- Parameters:
value- the value- Returns:
- true, if is empty value
-
isEmptyLocalizedValue
protected static boolean isEmptyLocalizedValue(java.util.Map<java.lang.String,java.lang.Object> value)
Checks if is empty localized value.- Parameters:
value- the value- Returns:
- true, if is empty localized value
-
getAllAttributes
public static java.util.Map<java.lang.String,java.lang.Object> getAllAttributes(TypedObject typedObject)
Gets all attributes and their possible values from TypedObject.- Parameters:
typedObject- the typed object- Returns:
- the all attributes map
-
getEnumName
public static java.lang.String getEnumName(HybrisEnumValue hybrisEnum)
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
public static void filterOutRemovedItems(java.util.List<? extends TypedObject> items)
Filters out removed items.- Parameters:
items- the items
-
getPropertyValueAsString
public static java.lang.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 java.lang.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> java.util.Collection<E> createCollection(java.lang.Class<? extends java.util.Collection> clazz, java.util.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:
HashSetfor setsArrayListfor other collections
- 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
-
-