Class DefaultAssetService<P extends Asset>
- All Implemented Interfaces:
AssetService<P>
,com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
- Author:
- Nathan Moore (nathanmoore)., Samarth Dhruva (samarthd)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultAssetService
(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 TypeMethodDescriptionOverridden 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 withfolderId
as theirAsset.folderId
.protected InternalAssetProperties
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) IfsearchString
is provided, then this method will search for assets whoseAsset.url
,Asset.title
,Asset.altText
, orAsset.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
-
CACHE_BY_URL
- See Also:
-
-
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
IfsearchString
is provided, then this method will search for assets whoseAsset.url
,Asset.title
,Asset.altText
, orAsset.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 interfaceAssetService<P extends Asset>
- Parameters:
searchString
- (optional) a string which should be found inAsset.url
,Asset.title
,Asset.altText
, orAsset.tags
filters
- additional filters to apply in the query. Should beEmptyNode
if no additional filters should be applied.pageInfo
- information about which page of results to return from the databasecontextInfo
- 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 asAsset.getId()
,Asset.getAuthor()
, andAsset.getLastUpdatedDate()
for all assets as well asAsset.getUrl()
,Asset.getSize()
,Asset.getMimeType()
forinternal asset
.- Specified by:
create
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
- Overrides:
create
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
- Parameters:
businessInstance
- The business domain instance. In general, theDomainMapperManager
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 asAsset.getId()
,Asset.getAuthor()
, andAsset.getLastUpdatedDate()
for all assets as well asAsset.getUrl()
,Asset.getSize()
,Asset.getMimeType()
forinternal asset
.- Specified by:
createAll
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
- Overrides:
createAll
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
- Parameters:
businessInstances
- The business domain instances. In general, theDomainMapperManager
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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
- Overrides:
update
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
- Parameters:
id
- Instance idbusinessInstance
- The business domain instance. In general, theDomainMapperManager
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 interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>
- Overrides:
replace
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>
- Parameters:
id
- Instance idbusinessInstance
- The business domain instance. In general, theDomainMapperManager
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 interfaceAssetService<P extends Asset>
- Parameters:
url
- the url which should match withAsset.url
storageType
- (optional) the storage type which should match withAsset.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 interfaceAssetService<P extends Asset>
- Parameters:
prefix
- the string which eachAsset.url
should start withstorageType
- the storage type which should match withAsset.storageType
contextInfo
- context information around sandbox and multitenant state- Returns:
- a list of
Assets
whoseurls
start with the given prefix and whosestorage 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 interfaceAssetService<P extends Asset>
- Parameters:
assetIds
- the asset context IDs to search forpageInfo
- pagination informationcontextInfo
- 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 interfaceAssetService<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 beEmptyNode
if no additional filters should be applied.pageInfo
- pagination informationcontextInfo
- 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 withfolderId
as theirAsset.folderId
. Essentially, this determines if there are any child assets directly in the given folder.- Specified by:
existsByFolderId
in interfaceAssetService<P extends Asset>
- Parameters:
folderId
- the context ID of the folder whose assets should be foundcontextInfo
- the context surrounding sandboxing and mulitenant state- Returns:
- whether or not there are any assets with
folderId
as theirAsset.folderId
-
getRepository
-
getInternalAssetProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-