Search in sources :

Example 1 with StaticAssetStorage

use of org.broadleafcommerce.cms.file.domain.StaticAssetStorage in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageServiceImpl method readStaticAssetStorageByStaticAssetId.

@Override
public StaticAssetStorage readStaticAssetStorageByStaticAssetId(final Long id) {
    final StaticAssetStorage[] storage = new StaticAssetStorage[1];
    transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {

        @Override
        public void execute() {
            storage[0] = staticAssetStorageDao.readStaticAssetStorageByStaticAssetId(id);
        }
    }, RuntimeException.class);
    return storage[0];
}
Also used : StaticAssetStorage(org.broadleafcommerce.cms.file.domain.StaticAssetStorage) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)

Example 2 with StaticAssetStorage

use of org.broadleafcommerce.cms.file.domain.StaticAssetStorage in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageServiceImpl method findStaticAssetStorageById.

@Override
public StaticAssetStorage findStaticAssetStorageById(final Long id) {
    final StaticAssetStorage[] storage = new StaticAssetStorage[1];
    transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {

        @Override
        public void execute() {
            storage[0] = staticAssetStorageDao.readStaticAssetStorageById(id);
        }
    }, RuntimeException.class);
    return storage[0];
}
Also used : StaticAssetStorage(org.broadleafcommerce.cms.file.domain.StaticAssetStorage) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)

Example 3 with StaticAssetStorage

use of org.broadleafcommerce.cms.file.domain.StaticAssetStorage in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageServiceImpl method lookupAssetAndCreateLocalFile.

protected File lookupAssetAndCreateLocalFile(StaticAsset staticAsset, File baseLocalFile) throws IOException, SQLException {
    if (StorageType.FILESYSTEM.equals(staticAsset.getStorageType())) {
        File returnFile = broadleafFileService.getResource(staticAsset.getFullUrl());
        if (!returnFile.getAbsolutePath().equals(baseLocalFile.getAbsolutePath())) {
            createLocalFileFromInputStream(new FileInputStream(returnFile), baseLocalFile);
        }
        return broadleafFileService.getResource(staticAsset.getFullUrl());
    } else {
        StaticAssetStorage storage = readStaticAssetStorageByStaticAssetId(staticAsset.getId());
        if (storage != null) {
            InputStream is = storage.getFileData().getBinaryStream();
            createLocalFileFromInputStream(is, baseLocalFile);
        }
    }
    return baseLocalFile;
}
Also used : StaticAssetStorage(org.broadleafcommerce.cms.file.domain.StaticAssetStorage) BufferedInputStream(java.io.BufferedInputStream) GloballySharedInputStream(org.broadleafcommerce.common.file.service.GloballySharedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream)

Example 4 with StaticAssetStorage

use of org.broadleafcommerce.cms.file.domain.StaticAssetStorage in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageServiceImpl method save.

@Override
public StaticAssetStorage save(final StaticAssetStorage assetStorage) {
    final StaticAssetStorage[] storage = new StaticAssetStorage[1];
    transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {

        @Override
        public void execute() {
            storage[0] = staticAssetStorageDao.save(assetStorage);
        }
    }, RuntimeException.class);
    return storage[0];
}
Also used : StaticAssetStorage(org.broadleafcommerce.cms.file.domain.StaticAssetStorage) StreamCapableTransactionalOperationAdapter(org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)

Example 5 with StaticAssetStorage

use of org.broadleafcommerce.cms.file.domain.StaticAssetStorage in project BroadleafCommerce by BroadleafCommerce.

the class StaticAssetStorageDaoImpl method readStaticAssetStorageByStaticAssetId.

@Override
public StaticAssetStorage readStaticAssetStorageByStaticAssetId(Long id) {
    Query query = em.createNamedQuery("BC_READ_STATIC_ASSET_STORAGE_BY_STATIC_ASSET_ID");
    query.setParameter("id", id);
    return (StaticAssetStorage) query.getSingleResult();
}
Also used : Query(javax.persistence.Query) StaticAssetStorage(org.broadleafcommerce.cms.file.domain.StaticAssetStorage)

Aggregations

StaticAssetStorage (org.broadleafcommerce.cms.file.domain.StaticAssetStorage)6 StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)3 BufferedInputStream (java.io.BufferedInputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 GloballySharedInputStream (org.broadleafcommerce.common.file.service.GloballySharedInputStream)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Blob (java.sql.Blob)1 Query (javax.persistence.Query)1 FileWorkArea (org.broadleafcommerce.common.file.domain.FileWorkArea)1 Transactional (org.springframework.transaction.annotation.Transactional)1