コード例 #1
0
  @Transactional("blTransactionManagerAssetStorageInfo")
  @Override
  public void createStaticAssetStorageFromFile(MultipartFile file, StaticAsset staticAsset)
      throws IOException {
    if (StorageType.DATABASE.equals(staticAsset.getStorageType())) {
      StaticAssetStorage storage = staticAssetStorageDao.create();
      storage.setStaticAssetId(staticAsset.getId());
      Blob uploadBlob = staticAssetStorageDao.createBlob(file);
      storage.setFileData(uploadBlob);
      staticAssetStorageDao.save(storage);
    } else if (StorageType.FILESYSTEM.equals(staticAsset.getStorageType())) {
      FileWorkArea tempWorkArea = broadleafFileService.initializeWorkArea();
      String destFileName =
          tempWorkArea.getFilePathLocation() + removeLeadingSlash(staticAsset.getFullUrl());

      InputStream input = file.getInputStream();
      byte[] buffer = new byte[fileBufferSize];

      File destFile = new File(destFileName);
      if (!destFile.getParentFile().exists()) {
        if (!destFile.getParentFile().mkdirs()) {
          throw new RuntimeException(
              "Unable to create parent directories for file: " + destFileName);
        }
      }

      OutputStream output = new FileOutputStream(destFile);
      boolean deleteFile = false;
      try {
        int bytesRead;
        int totalBytesRead = 0;
        while ((bytesRead = input.read(buffer)) != -1) {
          totalBytesRead += bytesRead;
          if (totalBytesRead > maxUploadableFileSize) {
            deleteFile = true;
            throw new IOException("Maximum Upload File Size Exceeded");
          }
          output.write(buffer, 0, bytesRead);
        }

        broadleafFileService.addOrUpdateResource(tempWorkArea, destFile, true);
      } finally {
        output.close();
        broadleafFileService.closeWorkArea(tempWorkArea);
      }
    }
  }
コード例 #2
0
 @Transactional("blTransactionManagerAssetStorageInfo")
 @Override
 public Blob createBlob(MultipartFile uploadedFile) throws IOException {
   return staticAssetStorageDao.createBlob(uploadedFile);
 }
コード例 #3
0
 @Transactional("blTransactionManagerAssetStorageInfo")
 @Override
 public void delete(StaticAssetStorage assetStorage) {
   staticAssetStorageDao.delete(assetStorage);
 }
コード例 #4
0
 @Transactional("blTransactionManagerAssetStorageInfo")
 @Override
 public StaticAssetStorage save(StaticAssetStorage assetStorage) {
   return staticAssetStorageDao.save(assetStorage);
 }
コード例 #5
0
 @Transactional("blTransactionManagerAssetStorageInfo")
 @Override
 public StaticAssetStorage readStaticAssetStorageByStaticAssetId(Long id) {
   return staticAssetStorageDao.readStaticAssetStorageByStaticAssetId(id);
 }
コード例 #6
0
 @Transactional("blTransactionManagerAssetStorageInfo")
 @Override
 public StaticAssetStorage create() {
   return staticAssetStorageDao.create();
 }