Class Asset

java.lang.Object
com.broadleafcommerce.asset.domain.Asset
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.ContextStateAware, Serializable

public class Asset extends Object implements Serializable, com.broadleafcommerce.data.tracking.core.ContextStateAware

A Asset encapsulates information related to stored, digital content such as images, videos, or text files.

A Asset maps a stored file to an accessible URL, maintains SEO data such as alt text and title, and maintains audit data such as date uploaded and the uploader. Furthermore, Asset can be given tags to provide a means of designating special purposes for the asset, group otherwise related assets such as "banners", or provide a label for some other arbitrary purpose.

Asset can represent externally stored files (such as a video on a 3rd-party video-sharing website like Vimeo or YouTube) or internally stored files (such as on the local filesystem).

Author:
Nathan Moore (nathanmoore).
See Also:
  • Constructor Details

    • Asset

      public Asset()
  • Method Details

    • getSizeWithUnits

      public String getSizeWithUnits()
      Added to provide a more human-readable way to display size by appending the units. For conciseness, this method also goes to the trouble of dynamically detecting the closest SI prefix that allows the size to be displayed without a decimal or thousands separator. Thus, if the size is 100,000,000 bytes, this would return 100MB.
      Returns:
      the size of the digital content represented by this asset with SI abbreviation.
    • setSizeWithUnits

      public void setSizeWithUnits(String sizeWithUnits)
    • getId

      public String getId()
      the context ID of this asset
      Returns:
      the id for this asset
    • getUrl

      public String getUrl()

      Location used to resolve this asset by callers using the service such as "/icon.png" for an internal asset or "https://www.youtube.com/watch?v=a1S2d3F4" for external asset.

      Note: In the case of internal asset, this field is not the full path. The rest of the path is constructed using the prefixes defined in InternalAssetProperties.

      Note that embedCode and this field can never both be present.

      Returns:
      the url for this asset
      See Also:
    • getEmbedCode

      public String getEmbedCode()
      If and only if the type is DefaultAssetType.EMBED, this field holds the HTML to embed.

      Note that url and this field can never both be present.

      Returns:
      the HTML to embed
    • getAltText

      public String getAltText()
      Text that corresponds to the HTML alt attribute that should be used when this asset is rendered in a browser. This is used as an alternative for screen-readers and as an SEO enhancement describing the asset.
      Returns:
      the altText for this asset
    • getTitle

      public String getTitle()
      Text that corresponds to the HTML title attribute that should be used when this asset is rendered in a browser. This is used a tooltip or caption.
      Returns:
      the title for this asset
    • getTags

      public LinkedHashSet<String> getTags()

      Descriptive or identifying labels.

      Tags can be used to:

      • provide a means of designating special purposes for the asset
      • group otherwise related assets such as "banners"
      • provide a label for some other, arbitrary purpose

      Returns:
      the tags for this asset
    • getLocale

      public Locale getLocale()
      Designate this asset to be used in a specific Locale.
      Returns:
      the the locale this asset should be displayed in
    • getType

      public String getType()
      Describes the general type of the asset. This is used to determine how to render the asset on the frontend. For example, if the type is DefaultAssetType.IMAGE, then the frontend will know to render it in an <img/> tag.

      For assets with an external storageType, this field is required input. For internal assets, this is inferred from the mimeType during upload.

      Returns:
      the general type of the asset
      See Also:
    • getExternalProvider

      public String getExternalProvider()
      For assets with an external storageType, this field is required and names where the external asset is sourced from. This field should be null for assets with an internal storageType.
      Returns:
      the provider (for example, the name of the CDN) that is hosting the external asset
    • getMimeType

      public String getMimeType()

      MIME storageType of the file represented by this asset: image/png, image/jpeg, application/pdf, &c.

      See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types for more info on MIME types

      Returns:
      the mimeType for this asset
    • getSize

      public long getSize()
      Size in bytes of the file represented by this asset.
      Returns:
      the size in bytes for this asset
    • getUploadDate

      public Instant getUploadDate()
      Date the file was uploaded to create this asset.
      Returns:
      the uploadDate for this asset
    • getLastUpdatedDate

      public Instant getLastUpdatedDate()
      Date the file was last updated.
      Returns:
      the lastUpdatedDate for this asset
    • getAuthor

      public String getAuthor()
      User who created this asset.
      Returns:
      the author for this asset
    • getStorageType

      public String getStorageType()
      Defines where the digital content represented by this asset is stored. The default types are DefaultAssetStorageType.INTERNAL and DefaultAssetStorageType.EXTERNAL.
      Returns:
      the storageType for this asset
      See Also:
    • getFolderId

      public String getFolderId()
      The context ID of the folder in which this asset is placed. A asset with a null folderId is not returned from folder content endpoints like /folder/{id}/assets.
      Returns:
      the context ID of the folder in which this asset is placed
    • getAttributes

      public Map<String,Object> getAttributes()
      Additional attributes of the asset.
      Returns:
      additional attributes of the asset
    • getContextState

      public com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState getContextState()
      A subset of Tracking information to expose the context state for this object.
      Specified by:
      getContextState in interface com.broadleafcommerce.data.tracking.core.ContextStateAware
      Returns:
      a subset of Tracking information to expose the context state for this object
    • setId

      public void setId(String id)
      the context ID of this asset
      Parameters:
      id - the value to set as the id for this asset
    • setUrl

      public void setUrl(String url)

      Location used to resolve this asset by callers using the service such as "/icon.png" for an internal asset or "https://www.youtube.com/watch?v=a1S2d3F4" for external asset.

      Note: In the case of internal asset, this field is not the full path. The rest of the path is constructed using the prefixes defined in InternalAssetProperties.

      Note that embedCode and this field can never both be present.

      Parameters:
      url - the value to set as the url for this asset
      See Also:
    • setEmbedCode

      public void setEmbedCode(String embedCode)
      If and only if the type is DefaultAssetType.EMBED, this field holds the HTML to embed.

      Note that url and this field can never both be present.

      Parameters:
      embedCode - the HTML to embed
    • setAltText

      public void setAltText(String altText)
      Text that corresponds to the HTML alt attribute that should be used when this asset is rendered in a browser. This is used as an alternative for screen-readers and as an SEO enhancement describing the asset.
      Parameters:
      altText - the value to set as the altText for this asset
    • setTitle

      public void setTitle(String title)
      Text that corresponds to the HTML title attribute that should be used when this asset is rendered in a browser. This is used a tooltip or caption.
      Parameters:
      title - the value to set as the title for this asset
    • setTags

      public void setTags(LinkedHashSet<String> tags)

      Descriptive or identifying labels.

      Tags can be used to:

      • provide a means of designating special purposes for the asset
      • group otherwise related assets such as "banners"
      • provide a label for some other, arbitrary purpose

      Parameters:
      tags - the value to set as the tags for this asset
    • setLocale

      public void setLocale(Locale locale)
      Designate this asset to be used in a specific Locale.
      Parameters:
      locale - which locale this asset should be displayed in
    • setType

      public void setType(String type)
      Describes the general type of the asset. This is used to determine how to render the asset on the frontend. For example, if the type is DefaultAssetType.IMAGE, then the frontend will know to render it in an <img/> tag.

      For assets with an external storageType, this field is required input. For internal assets, this is inferred from the mimeType during upload.

      Parameters:
      type - the general type of the asset
      See Also:
    • setExternalProvider

      public void setExternalProvider(String externalProvider)
      For assets with an external storageType, this field is required and names where the external asset is sourced from. This field should be null for assets with an internal storageType.
      Parameters:
      externalProvider - the provider (for example, the name of the CDN) that is hosting the external asset
    • setMimeType

      public void setMimeType(String mimeType)

      MIME storageType of the file represented by this asset: image/png, image/jpeg, application/pdf, &c.

      See https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types for more info on MIME types

      Parameters:
      mimeType - the value to set as the mimeType for this asset
    • setSize

      public void setSize(long size)
      Size in bytes of the file represented by this asset.
      Parameters:
      size - the value to set as the size in bytes for this asset
    • setUploadDate

      public void setUploadDate(Instant uploadDate)
      Date the file was uploaded to create this asset.
      Parameters:
      uploadDate - the value to set as the uploadDate for this asset
    • setLastUpdatedDate

      public void setLastUpdatedDate(Instant lastUpdatedDate)
      Date the file was last updated.
      Parameters:
      lastUpdatedDate - the value to set as the lastUpdatedDate for this asset
    • setAuthor

      public void setAuthor(String author)
      User who created this asset.
      Parameters:
      author - the value to set as the author for this asset
    • setStorageType

      public void setStorageType(String storageType)
      Defines where the digital content represented by this asset is stored. The default types are DefaultAssetStorageType.INTERNAL and DefaultAssetStorageType.EXTERNAL.
      Parameters:
      storageType - the value to set as the storageType for this asset
      See Also:
    • setFolderId

      public void setFolderId(String folderId)
      The context ID of the folder in which this asset is placed. A asset with a null folderId is not returned from folder content endpoints like /folder/{id}/assets.
      Parameters:
      folderId - the context ID of the folder in which this asset is placed
    • setAttributes

      public void setAttributes(Map<String,Object> attributes)
      Additional attributes of the asset.
      Parameters:
      attributes - additional attributes of the asset
    • setContextState

      public void setContextState(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState)
      A subset of Tracking information to expose the context state for this object.
      Specified by:
      setContextState in interface com.broadleafcommerce.data.tracking.core.ContextStateAware
      Parameters:
      contextState - a subset of Tracking information to expose the context state for this object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object