org.broadleafcommerce.cms.file.service
Class StaticAssetServiceImpl

java.lang.Object
  extended by org.broadleafcommerce.cms.common.AbstractContentService
      extended by org.broadleafcommerce.cms.file.service.StaticAssetServiceImpl
All Implemented Interfaces:
StaticAssetService, SandBoxItemListener

@Service(value="blStaticAssetService")
public class StaticAssetServiceImpl
extends AbstractContentService
implements StaticAssetService

Created by bpolster.


Field Summary
protected  boolean automaticallyApproveAndPromoteStaticAssets
           
protected  ImageArtifactProcessor imageArtifactProcessor
           
protected  SandBoxItemDao sandBoxItemDao
           
protected  StaticAssetDao staticAssetDao
           
protected  StaticAssetPathService staticAssetPathService
           
protected  StaticAssetStorageService staticAssetStorageService
           
protected  boolean storeAssetsOnFileSystem
           
 
Constructor Summary
StaticAssetServiceImpl()
           
 
Method Summary
 StaticAsset addStaticAsset(StaticAsset staticAsset, SandBox destinationSandbox)
          This method is intended to be called from within the CMS admin only.
protected  String buildAssetURL(Map<String,String> assetProperties, String originalFilename)
          Will assemble the url from the passed in properties as /{entityType}/{fileName} /product/7001-ab12 If the properties above are not set, it will generate the fileName randomly.
 String convertAssetPath(String assetPath, String contextPath, boolean secureRequest)
           
 Long countAssets(SandBox sandbox, org.hibernate.Criteria c)
           
 StaticAsset createStaticAssetFromFile(org.springframework.web.multipart.MultipartFile file, Map<String,String> properties)
          Used when uploading a file to Broadleaf.
 void deleteStaticAsset(StaticAsset staticAsset, SandBox destinationSandbox)
          If deleting and item where page.originalPageId != null then the item is deleted from the database.
 List<StaticAsset> findAssets(SandBox sandbox, org.hibernate.Criteria c)
           
 StaticAsset findStaticAssetByFullUrl(String fullUrl, SandBox targetSandBox)
           
 StaticAsset findStaticAssetById(Long id)
           
protected  String generateFileName(int size)
          Generates a filename as a set of Hex digits.
 boolean getAutomaticallyApproveAndPromoteStaticAssets()
          If set to true, then this service will not use the SandBox concept and will instead automatically promote images to production as they are entered into the system.
protected  String getCountUrl(String fullUrl, int count, boolean legacyFormat)
          Gets the count URL based on the original fullUrl.
protected  String getFileExtension(String fileName)
           
protected  void getMimeType(org.springframework.web.multipart.MultipartFile file, StaticAsset newAsset)
           
 String getStaticAssetEnvironmentSecureUrlPrefix()
           
 String getStaticAssetEnvironmentUrlPrefix()
           
 String getStaticAssetUrlPrefix()
           
 void itemPromoted(SandBoxItem sandBoxItem, SandBox destinationSandBox)
           
 void itemRejected(SandBoxItem sandBoxItem, SandBox destinationSandBox)
           
 void itemReverted(SandBoxItem sandBoxItem)
           
 List<StaticAsset> readAllStaticAssets()
           
 void setAutomaticallyApproveAndPromoteStaticAssets(boolean automaticallyApproveAndPromoteStaticAssets)
          If set to true, then this service will not use the SandBox concept and will instead automatically promote images to production as they are entered into the system.
 StaticAsset updateStaticAsset(StaticAsset staticAsset, SandBox destSandbox)
          This method is intended to be called from within the CMS admin only.
 
Methods inherited from class org.broadleafcommerce.cms.common.AbstractContentService
countItems, findItems
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imageArtifactProcessor

protected ImageArtifactProcessor imageArtifactProcessor

storeAssetsOnFileSystem

@Value(value="${asset.use.filesystem.storage}")
protected boolean storeAssetsOnFileSystem

automaticallyApproveAndPromoteStaticAssets

@Value(value="${automatically.approve.static.assets}")
protected boolean automaticallyApproveAndPromoteStaticAssets

staticAssetDao

protected StaticAssetDao staticAssetDao

sandBoxItemDao

protected SandBoxItemDao sandBoxItemDao

staticAssetStorageService

protected StaticAssetStorageService staticAssetStorageService

staticAssetPathService

protected StaticAssetPathService staticAssetPathService
Constructor Detail

StaticAssetServiceImpl

public StaticAssetServiceImpl()
Method Detail

findStaticAssetById

public StaticAsset findStaticAssetById(Long id)
Specified by:
findStaticAssetById in interface StaticAssetService

readAllStaticAssets

public List<StaticAsset> readAllStaticAssets()
Specified by:
readAllStaticAssets in interface StaticAssetService

getFileExtension

protected String getFileExtension(String fileName)

generateFileName

protected String generateFileName(int size)
Generates a filename as a set of Hex digits.

Parameters:
size -
Returns:

buildAssetURL

protected String buildAssetURL(Map<String,String> assetProperties,
                               String originalFilename)
Will assemble the url from the passed in properties as /{entityType}/{fileName} /product/7001-ab12 If the properties above are not set, it will generate the fileName randomly.

Parameters:
url -
asset -
assetProperties -
Returns:

createStaticAssetFromFile

@Transactional(value="blTransactionManager")
public StaticAsset createStaticAssetFromFile(org.springframework.web.multipart.MultipartFile file,
                                                           Map<String,String> properties)
Description copied from interface: StaticAssetService
Used when uploading a file to Broadleaf. This method will create the corresponding asset. Depending on the the implementation, the actual asset may be saved to the DB or to the file system. The default implementation StaticAssetServiceImpl has a environment properties that determine this behavior asset.use.filesystem.storage, and asset.server.file.system.path. The properties allows for implementors to update other Asset properties at the same time they are uploading a file. The default implementation uses this for an optional URL to be specified.

Specified by:
createStaticAssetFromFile in interface StaticAssetService
Parameters:
file - - the file being uploaded
properties - - additional meta-data properties
Returns:
See Also:
StaticAssetServiceImpl

getCountUrl

protected String getCountUrl(String fullUrl,
                             int count,
                             boolean legacyFormat)
Gets the count URL based on the original fullUrl. If requested in legacy format this will return URLs like: /path/to/image.jpg-1 /path/to/image.jpg-2 Whereas if this is in non-lagacy format (legacy == false): /path/to/image-1.jpg /path/to/image-2.jpg Used to deal with duplicate URLs of uploaded assets


getMimeType

protected void getMimeType(org.springframework.web.multipart.MultipartFile file,
                           StaticAsset newAsset)

findStaticAssetByFullUrl

public StaticAsset findStaticAssetByFullUrl(String fullUrl,
                                            SandBox targetSandBox)
Specified by:
findStaticAssetByFullUrl in interface StaticAssetService

addStaticAsset

public StaticAsset addStaticAsset(StaticAsset staticAsset,
                                  SandBox destinationSandbox)
Description copied from interface: StaticAssetService
This method is intended to be called from within the CMS admin only. Adds the passed in page to the DB. Creates a sandbox/site if one doesn't already exist.

Specified by:
addStaticAsset in interface StaticAssetService

updateStaticAsset

public StaticAsset updateStaticAsset(StaticAsset staticAsset,
                                     SandBox destSandbox)
Description copied from interface: StaticAssetService
This method is intended to be called from within the CMS admin only. Updates the page according to the following rules: 1. If sandbox has changed from null to a value This means that the user is editing an item in production and the edit is taking place in a sandbox. Clone the page and add it to the new sandbox and set the cloned page's originalPageId to the id of the page being updated. 2. If the sandbox has changed from one value to another This means that the user is moving the item from one sandbox to another. Update the siteId for the page to the one associated with the new sandbox 3. If the sandbox has changed from a value to null This means that the item is moving from the sandbox to production. If the page has an originalPageId, then update that page by setting it's archived flag to true. Then, update the siteId of the page being updated to be the siteId of the original page. 4. If the sandbox is the same then just update the page.

Specified by:
updateStaticAsset in interface StaticAssetService

deleteStaticAsset

public void deleteStaticAsset(StaticAsset staticAsset,
                              SandBox destinationSandbox)
Description copied from interface: StaticAssetService
If deleting and item where page.originalPageId != null then the item is deleted from the database. If the originalPageId is null, then this method marks the items as deleted within the passed in sandbox.

Specified by:
deleteStaticAsset in interface StaticAssetService

findAssets

public List<StaticAsset> findAssets(SandBox sandbox,
                                    org.hibernate.Criteria c)
Specified by:
findAssets in interface StaticAssetService

countAssets

public Long countAssets(SandBox sandbox,
                        org.hibernate.Criteria c)
Specified by:
countAssets in interface StaticAssetService

itemPromoted

public void itemPromoted(SandBoxItem sandBoxItem,
                         SandBox destinationSandBox)
Specified by:
itemPromoted in interface SandBoxItemListener

itemRejected

public void itemRejected(SandBoxItem sandBoxItem,
                         SandBox destinationSandBox)
Specified by:
itemRejected in interface SandBoxItemListener

itemReverted

public void itemReverted(SandBoxItem sandBoxItem)
Specified by:
itemReverted in interface SandBoxItemListener

getStaticAssetUrlPrefix

public String getStaticAssetUrlPrefix()
Specified by:
getStaticAssetUrlPrefix in interface StaticAssetService
See Also:
StaticAssetPathService.getStaticAssetUrlPrefix()

getStaticAssetEnvironmentUrlPrefix

public String getStaticAssetEnvironmentUrlPrefix()
Specified by:
getStaticAssetEnvironmentUrlPrefix in interface StaticAssetService
See Also:
StaticAssetPathService.getStaticAssetEnvironmentUrlPrefix()

getStaticAssetEnvironmentSecureUrlPrefix

public String getStaticAssetEnvironmentSecureUrlPrefix()
Specified by:
getStaticAssetEnvironmentSecureUrlPrefix in interface StaticAssetService
See Also:
StaticAssetPathService.getStaticAssetEnvironmentSecureUrlPrefix()

getAutomaticallyApproveAndPromoteStaticAssets

public boolean getAutomaticallyApproveAndPromoteStaticAssets()
Description copied from interface: StaticAssetService
If set to true, then this service will not use the SandBox concept and will instead automatically promote images to production as they are entered into the system. This is recommended for the best workflow within the BLC-CMS and has been set as the default behavior.

Specified by:
getAutomaticallyApproveAndPromoteStaticAssets in interface StaticAssetService

setAutomaticallyApproveAndPromoteStaticAssets

public void setAutomaticallyApproveAndPromoteStaticAssets(boolean automaticallyApproveAndPromoteStaticAssets)
Description copied from interface: StaticAssetService
If set to true, then this service will not use the SandBox concept and will instead automatically promote images to production as they are entered into the system. This is recommended for the best workflow within the BLC-CMS and has been set as the default behavior.

Specified by:
setAutomaticallyApproveAndPromoteStaticAssets in interface StaticAssetService

convertAssetPath

public String convertAssetPath(String assetPath,
                               String contextPath,
                               boolean secureRequest)
Specified by:
convertAssetPath in interface StaticAssetService
See Also:
StaticAssetPathService.convertAssetPath(String, String, boolean)


Copyright © 2013. All Rights Reserved.