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.booleanexistsByFolderId(String folderId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns whether or not there are any assets withfolderIdas theirAsset.folderId.protected InternalAssetPropertiesprotected AssetRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected com.broadleafcommerce.common.extension.TypeFactoryorg.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) IfsearchStringis provided, then this method will search for assets whoseAsset.url,Asset.title,Asset.altText, orAsset.tagscontain 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, readAllMethods 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, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSortMethods 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:AssetServiceIfsearchStringis provided, then this method will search for assets whoseAsset.url,Asset.title,Asset.altText, orAsset.tagscontain it.If no
searchStringis provided, then this method will simply return all assets.This method also supports RSQL filtration via
filters.- Specified by:
searchAllin interfaceAssetService<P extends Asset>- Parameters:
searchString- (optional) a string which should be found inAsset.url,Asset.title,Asset.altText, orAsset.tagsfilters- additional filters to apply in the query. Should beEmptyNodeif 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
Assetshould 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:
createin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>- Overrides:
createin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>- Parameters:
businessInstance- The business domain instance. In general, theDomainMapperManageris 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
assetinstance
-
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
Assetshould 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:
createAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>- Overrides:
createAllin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>- Parameters:
businessInstances- The business domain instances. In general, theDomainMapperManageris 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
assetinstances
-
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:
updatein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>- Overrides:
updatein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>- Parameters:
id- Instance idbusinessInstance- The business domain instance. In general, theDomainMapperManageris 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
assetinstance
-
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:
replacein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends Asset>- Overrides:
replacein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends Asset>- Parameters:
id- Instance idbusinessInstance- The business domain instance. In general, theDomainMapperManageris 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
assetinstance
-
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:AssetServiceFinds the asset whose url and storage type (optional) match the provided values.- Specified by:
readByUrlAndStorageTypein interfaceAssetService<P extends Asset>- Parameters:
url- the url which should match withAsset.urlstorageType- (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:AssetServiceFinds all of the assets whose URL begins with a given string and whose storage type matches the given value.- Specified by:
readByUrlStartsWithAndStorageTypein interfaceAssetService<P extends Asset>- Parameters:
prefix- the string which eachAsset.urlshould start withstorageType- the storage type which should match withAsset.storageTypecontextInfo- context information around sandbox and multitenant state- Returns:
- a list of
Assetswhoseurlsstart with the given prefix and whosestorage typeshave 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:AssetServiceFinds all asset with IDs in the supplied list.- Specified by:
readAllByContextIdsin 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:AssetServiceReads all of the assets in the given folder.- Specified by:
readAllAssetsInFolderin 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 beEmptyNodeif 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
EntityMissingExceptionif 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:AssetServiceReturns whether or not there are any assets withfolderIdas theirAsset.folderId. Essentially, this determines if there are any child assets directly in the given folder.- Specified by:
existsByFolderIdin 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
folderIdas theirAsset.folderId
-
getRepository
-
getInternalAssetProperties
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-