Class TypeTools


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

      • TypeTools

        public TypeTools()
    • 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 service
        value - 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, 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 java.lang.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 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 type
        baseItem - the base item
        typeService - the type service
        configurationService - the configuration service
        Returns:
        the initial values
      • 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 java.lang.Object getObjectAttributeValue​(TypedObject object,
                                                               java.lang.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,
                                                                java.util.Set<PropertyDescriptor> propertyDescriptors,
                                                                java.util.Set<java.lang.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,
                                                                java.util.Set<PropertyDescriptor> propertyDescriptors,
                                                                java.util.Set<java.lang.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,
                                                                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 type
        supertype - 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 service
        type - 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 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
      • 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 TypeService
        value - 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 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 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 desc
        languageIso - the language iso
        items - the items
        value - the value
        Returns:
        the list< string>
      • primitiveValue

        @Deprecated
        public static boolean primitiveValue​(java.lang.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​(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 container
        template - the template
        creationMode - 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 container
        descriptors - the descriptors
        creationMode - the creation mode
        Returns:
        the omitted properties
      • propertyBelongsTo

        public static boolean propertyBelongsTo​(TypeService typeService,
                                                java.util.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 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 service
        template - the template
        languageIsos - 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 by items collection.

        *If cannot create a new instance with the same type, then it will creates:

        • HashSet for sets
        • ArrayList for 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