Class DefaultAssetService<P extends Asset>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.asset.service.DefaultAssetService<P>
All Implemented Interfaces:
AssetService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultAssetService<P extends Asset> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements AssetService<P>
Author:
Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultAssetService(AssetRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, InternalAssetProperties internalAssetProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    create(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Overridden so as to ensure instance fields are correctly initialized.
    createAll(@NonNull List<P> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Overridden so as to ensure instance fields are correctly initialized.
    boolean
    existsByFolderId(String folderId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Returns whether or not there are any assets with folderId as their Asset.folderId.
     
    protected AssetRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    org.springframework.data.domain.Page<Asset>
    readAllAssetsInFolder(String folderId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all of the assets in the given folder.
    org.springframework.data.domain.Page<P>
    readAllByContextIds(List<String> assetIds, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds all asset with IDs in the supplied list.
    readByUrlAndStorageType(String url, String storageType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the asset whose url and storage type (optional) match the provided values.
    readByUrlStartsWithAndStorageType(String prefix, String storageType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds all of the assets whose URL begins with a given string and whose storage type matches the given value.
    replace(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Overridden so as to ensure instance fields are correctly initialized.
    org.springframework.data.domain.Page<P>
    searchAll(String searchString, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    If searchString is provided, then this method will search for assets whose Asset.url, Asset.title, Asset.altText, or Asset.tags contain it.
    update(String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Overridden so as to ensure instance fields are correctly initialized.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Field Details

  • Constructor Details

    • DefaultAssetService

      public DefaultAssetService(AssetRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, InternalAssetProperties internalAssetProperties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • searchAll

      public org.springframework.data.domain.Page<P> searchAll(@Nullable String searchString, cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      If searchString is provided, then this method will search for assets whose Asset.url, Asset.title, Asset.altText, or Asset.tags contain it.

      If no searchString is provided, then this method will simply return all assets.

      This method also supports RSQL filtration via filters.

      Specified by:
      searchAll in interface AssetService<P extends Asset>
      Parameters:
      searchString - (optional) a string which should be found in Asset.url, Asset.title, Asset.altText, or Asset.tags
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      pageInfo - information about which page of results to return from the database
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      the assets matching the given search/filter arguments if provided, otherwise all assets
    • create

      public P create(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)

      Overridden so as to ensure instance fields are correctly initialized.

      Certain fields on Asset should only be set by the server on create such as Asset.getId(), Asset.getAuthor(), and Asset.getLastUpdatedDate() for all assets as well as Asset.getUrl(), Asset.getSize(), Asset.getMimeType() for internal asset.

      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
      Parameters:
      businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple versions may be available across sandboxes, catalogs and applications.
      Returns:
      newly created asset instance
    • createAll

      public List<P> createAll(@NonNull @NonNull List<P> businessInstances, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)

      Overridden so as to ensure instance fields are correctly initialized.

      Certain fields on Asset should only be set by the server on create such as Asset.getId(), Asset.getAuthor(), and Asset.getLastUpdatedDate() for all assets as well as Asset.getUrl(), Asset.getSize(), Asset.getMimeType() for internal asset.

      Specified by:
      createAll in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
      Overrides:
      createAll in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
      Parameters:
      businessInstances - The business domain instances. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple versions may be available across sandboxes, catalogs and applications.
      Returns:
      list of newly created asset instances
    • update

      public P update(String id, P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Overridden so as to ensure instance fields are correctly initialized.
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
      Parameters:
      id - Instance id
      businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple verions may be available across sandboxes, catalogs and applications.
      Returns:
      updated asset instance
    • replace

      public P replace(String id, P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Overridden so as to ensure instance fields are correctly initialized.
      Specified by:
      replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
      Overrides:
      replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
      Parameters:
      id - Instance id
      businessInstance - The business domain instance. In general, the DomainMapperManager is responsible for converting to a repository platform type for persistence.
      context - Context information used to discriminate the correct version of an entity by context id when multiple versions may be available across sandboxes, catalogs and applications.
      Returns:
      updated asset instance
    • readByUrlAndStorageType

      @Cacheable(value="assetCacheByUrl", keyGenerator="assetCacheByUrl", condition="@cacheStateManager.isEnabled(#root.caches, #root.args)") public Optional<P> readByUrlAndStorageType(String url, @Nullable String storageType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      Finds the asset whose url and storage type (optional) match the provided values.
      Specified by:
      readByUrlAndStorageType in interface AssetService<P extends Asset>
      Parameters:
      url - the url which should match with Asset.url
      storageType - (optional) the storage type which should match with Asset.storageType. If left null, results will not be filtered by storage type.
      contextInfo - context information around sandboxing and multitenant state
      Returns:
      an optional containing the asset whose url and storage type (optional) match the provided values, empty otherwise
    • readByUrlStartsWithAndStorageType

      public List<P> readByUrlStartsWithAndStorageType(String prefix, String storageType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      Finds all of the assets whose URL begins with a given string and whose storage type matches the given value.
      Specified by:
      readByUrlStartsWithAndStorageType in interface AssetService<P extends Asset>
      Parameters:
      prefix - the string which each Asset.url should start with
      storageType - the storage type which should match with Asset.storageType
      contextInfo - context information around sandbox and multitenant state
      Returns:
      a list of Assets whose urls start with the given prefix and whose storage types have the given value
    • readAllByContextIds

      public org.springframework.data.domain.Page<P> readAllByContextIds(List<String> assetIds, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      Finds all asset with IDs in the supplied list.
      Specified by:
      readAllByContextIds in interface AssetService<P extends Asset>
      Parameters:
      assetIds - the asset context IDs to search for
      pageInfo - pagination information
      contextInfo - the context to perform the operation in
      Returns:
      the asset that matched with the IDs in the given list
    • readAllAssetsInFolder

      public org.springframework.data.domain.Page<Asset> readAllAssetsInFolder(@Nullable String folderId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      Reads all of the assets in the given folder.
      Specified by:
      readAllAssetsInFolder in interface AssetService<P extends Asset>
      Parameters:
      folderId - the context ID of the folder whose children asset should be returned. If null, this will return all assets that are not in a folder.
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      pageInfo - pagination information
      contextInfo - the context to perform the operation in
      Returns:
      all of the assets in the given folder. Throws EntityMissingException if no folder was found with the given folderId.
    • existsByFolderId

      public boolean existsByFolderId(String folderId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: AssetService
      Returns whether or not there are any assets with folderId as their Asset.folderId. Essentially, this determines if there are any child assets directly in the given folder.
      Specified by:
      existsByFolderId in interface AssetService<P extends Asset>
      Parameters:
      folderId - the context ID of the folder whose assets should be found
      contextInfo - the context surrounding sandboxing and mulitenant state
      Returns:
      whether or not there are any assets with folderId as their Asset.folderId
    • getRepository

      protected AssetRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
    • getInternalAssetProperties

      protected InternalAssetProperties getInternalAssetProperties()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()