Class TypeTools

java.lang.Object
de.hybris.platform.cockpit.util.TypeTools

public class TypeTools extends Object
Usefull utility methods for dealing with the cockpit type system.
  • Constructor Details

    • TypeTools

      public TypeTools()
  • Method Details

    • getValueAsString

      public static String getValueAsString(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).
      Parameters:
      labelService - the label service
      value - the value
      Returns:
      the string representation
    • getValueAsString

      public static String getValueAsString(LabelService labelService, Object value, int size)
    • getTypeName

      @Deprecated public static String getTypeName(BaseType type, TypeService typeService)
      Deprecated.
      since 6.3, use ObjectType.getName() instead.
      Get the type name in the current session language.
      Parameters:
      type - the type
      typeService - the typeservice
      Returns:
      the type name
    • getTypeDescription

      @Deprecated public static String getTypeDescription(BaseType type, TypeService typeService)
      Deprecated.
      since 6.3, use ObjectType.getDescription() instead.
      Get the type description in the current session language.
      Parameters:
      type - the type
      typeService - 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 type
      baseItem - the base item
      typeService - the type service
      configurationService - the configuration service
      Returns:
      the initial values
    • getMultiplicityString

      @Deprecated public static String getMultiplicityString(PropertyDescriptor propertyDescriptor)
      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 descriptor
      typeService - the type service
      Returns:
      the value type as object template
    • getObjectAttributeValue

      @Deprecated public static Object getObjectAttributeValue(TypedObject object, String attributeQualifier, TypeService typeService)
      Deprecated.
      Gets the object attribute value.
      Parameters:
      object - the object
      attributeQualifier - the attribute qualifier
      typeService - 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 object
      propertyDescriptors - the property descriptors
      langIsos - 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 object
      propertyDescriptors - the property descriptors
      langIsos - the lang isos
      lazyLoad - 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

      public static List<ObjectType> getAllSupertypes(ObjectType type)
      Gets the all supertypes.
      Parameters:
      type - the type
      Returns:
      the all supertypes
    • getAllSubtypes

      public static 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 type
      supertype - the supertype
      Returns:
      true, if successful
    • itemToPkList

      @Deprecated public static List<PK> itemToPkList(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 List<ObjectTemplate> getTemplatesForCreation(TypeService typeService, BaseType type)
      Gets the templates for creation.
      Parameters:
      typeService - the type service
      type - 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 service
      type - the type
      initialDepth - the initial depth
      showAbstract - 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, use UIAccessRightService isWritable methods instead.
      Checks if is editable.
      Parameters:
      systemService - the system service
      type - object type
      propertyDescriptor - property descriptor
      creationMode - 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, use UIAccessRightService isReadable methods instead.
      Checks if is readable.
      Parameters:
      systemService - the system service
      type - object type
      propertyDescriptor - property descriptor
      creationMode - the creation mode
      Returns:
      true, if is readable
    • isInitial

      @Deprecated public static boolean isInitial(PropertyDescriptor propertyDescriptor)
      Deprecated.
      Checks if is initial.
      Parameters:
      propertyDescriptor - the pd
      Returns:
      true, if is initial
    • isPartof

      @Deprecated public static boolean isPartof(PropertyDescriptor propertyDescriptor)
      Deprecated.
    • item2Container

      public static Object item2Container(TypeService typeService, 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 TypeService
      value - the value
      Returns:
      converted value
    • container2Item

      public static Object container2Item(TypeService typeService, 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 TypeService
      containerValue - the value
      Returns:
      converted value
    • checkInstanceOfCategory

      public static boolean checkInstanceOfCategory(TypeService typeService, TypedObject object)
      Check instance of category.
      Parameters:
      typeService - the type service
      object - the object
      Returns:
      true, if successful
    • checkInstanceOfCatalogVersion

      public static boolean checkInstanceOfCatalogVersion(TypeService typeService, TypedObject object)
      Check instance of catalog version.
      Parameters:
      typeService - the type service
      object - the object
      Returns:
      true, if successful
    • checkInstanceOfProduct

      public static boolean checkInstanceOfProduct(TypeService typeService, TypedObject object)
      Check instance of product.
      Parameters:
      typeService - the type service
      object - the object
      Returns:
      true, if successful
    • checkInstanceOfMedia

      public static boolean checkInstanceOfMedia(TypeService typeService, TypedObject object)
      Check instance of media.
      Parameters:
      typeService - the type service
      object - 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 desc
      languageIso - the language iso
      items - the items
      value - the value
      Returns:
      the list< string>
    • primitiveValue

      @Deprecated public static boolean primitiveValue(Boolean value)
      Deprecated.
      since 6.3, use BooleanUtils.toBoolean(Boolean) instead.
      Primitive value.
      Parameters:
      value - the value
      Returns:
      true, if successful
    • primitiveValue

      public static int primitiveValue(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 Set<PropertyDescriptor> getOmittedProperties(ObjectValueContainer valueContainer, ObjectTemplate template, boolean creationMode)
      Gets the omitted properties.
      Parameters:
      valueContainer - the value container
      template - the template
      creationMode - 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 container
      descriptors - the descriptors
      creationMode - the creation mode
      Returns:
      the omitted properties
    • getMandatoryAttributes

      public static Set<PropertyDescriptor> getMandatoryAttributes(ObjectType type, boolean creationMode)
      Gets the mandatory attributes. Can only be used in a zk environment. Use getMandatoryAttributes(ObjectType, boolean, PropertyService) from outside zk.
      Parameters:
      type - the type
      creationMode - the creation mode
      Returns:
      the mandatory attributes
    • getMandatoryAttributes

      public static Set<PropertyDescriptor> getMandatoryAttributes(ObjectType type, boolean creationMode, PropertyService propertyService)
      Same as getMandatoryAttributes(ObjectType, boolean) but uses PropertyService to check if mandatory.
    • isMandatory

      @Deprecated public static boolean isMandatory(PropertyDescriptor propertyDescriptor, boolean creationMode)
      Checks if is mandatory.
      Parameters:
      propertyDescriptor - the pd
      creationMode - 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 service
      types - the types
      propertyDescriptor - 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 service
      template - the template
      languageIsos - the language isos
      Returns:
      the all default values
    • isEmptyValue

      protected static boolean isEmptyValue(Object value)
      Checks if is empty value.
      Parameters:
      value - the value
      Returns:
      true, if is empty value
    • isEmptyLocalizedValue

      protected static boolean isEmptyLocalizedValue(Map<String,Object> value)
      Checks if is empty localized value.
      Parameters:
      value - the value
      Returns:
      true, if is empty localized value
    • getAllAttributes

      public static Map<String,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 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(List<? extends TypedObject> items)
      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 by items collection.

      *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