Exemplo n.º 1
0
  protected void copyThumbnails(FileVersion sourceFileVersion, FileVersion destinationFileVersion) {

    try {
      if (isThumbnailEnabled(THUMBNAIL_INDEX_DEFAULT)) {
        if (hasThumbnail(sourceFileVersion, THUMBNAIL_INDEX_DEFAULT)
            && !hasThumbnail(destinationFileVersion, THUMBNAIL_INDEX_DEFAULT)) {

          InputStream is = doGetThumbnailAsStream(sourceFileVersion, THUMBNAIL_INDEX_DEFAULT);

          String thumbnailFilePath =
              getThumbnailFilePath(
                  destinationFileVersion,
                  getThumbnailType(destinationFileVersion),
                  THUMBNAIL_INDEX_DEFAULT);

          addFileToStore(
              destinationFileVersion.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is);
        }
      }

      if (isThumbnailEnabled(THUMBNAIL_INDEX_CUSTOM_1)) {
        if (hasThumbnail(sourceFileVersion, THUMBNAIL_INDEX_CUSTOM_1)
            && !hasThumbnail(destinationFileVersion, THUMBNAIL_INDEX_CUSTOM_1)) {

          InputStream is = doGetThumbnailAsStream(sourceFileVersion, THUMBNAIL_INDEX_CUSTOM_1);

          String thumbnailFilePath =
              getThumbnailFilePath(
                  destinationFileVersion,
                  getThumbnailType(destinationFileVersion),
                  THUMBNAIL_INDEX_CUSTOM_1);

          addFileToStore(
              destinationFileVersion.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is);
        }
      }

      if (isThumbnailEnabled(THUMBNAIL_INDEX_CUSTOM_2)) {
        if (hasThumbnail(sourceFileVersion, THUMBNAIL_INDEX_CUSTOM_2)
            && !hasThumbnail(destinationFileVersion, THUMBNAIL_INDEX_CUSTOM_2)) {

          InputStream is = doGetThumbnailAsStream(sourceFileVersion, THUMBNAIL_INDEX_CUSTOM_2);

          String thumbnailFilePath =
              getThumbnailFilePath(
                  destinationFileVersion,
                  getThumbnailType(destinationFileVersion),
                  THUMBNAIL_INDEX_CUSTOM_2);

          addFileToStore(
              destinationFileVersion.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is);
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  private void _generateImagesPB(
      FileVersion fileVersion,
      PDPage pdPage,
      int dpi,
      int height,
      int width,
      boolean thumbnail,
      int index)
      throws Exception {

    // Generate images

    RenderedImage renderedImage =
        pdPage.convertToImage(BufferedImage.TYPE_INT_RGB, PropsValues.DL_FILE_ENTRY_THUMBNAIL_DPI);

    if (height != 0) {
      renderedImage = ImageProcessorUtil.scale(renderedImage, width, height);
    } else {
      renderedImage = ImageProcessorUtil.scale(renderedImage, width);
    }

    // Store images

    String tempFileId =
        DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File thumbnailTempFile = null;

    try {
      if (thumbnail) {
        thumbnailTempFile = getThumbnailTempFile(tempFileId);

        thumbnailTempFile.createNewFile();

        ImageIO.write(renderedImage, THUMBNAIL_TYPE, new FileOutputStream(thumbnailTempFile));

        addFileToStore(
            fileVersion.getCompanyId(), THUMBNAIL_PATH,
            getThumbnailFilePath(fileVersion), thumbnailTempFile);
      } else {
        thumbnailTempFile = getPreviewTempFile(tempFileId, index);

        thumbnailTempFile.createNewFile();

        ImageIO.write(renderedImage, PREVIEW_TYPE, new FileOutputStream(thumbnailTempFile));

        addFileToStore(
            fileVersion.getCompanyId(), PREVIEW_PATH,
            getPreviewFilePath(fileVersion, index), thumbnailTempFile);
      }
    } finally {
      FileUtil.delete(thumbnailTempFile);
    }
  }
  @Override
  protected boolean hasPreview(FileVersion fileVersion, String type) throws Exception {

    String previewFilePath = getPreviewFilePath(fileVersion, 1);

    return DLStoreUtil.hasFile(fileVersion.getCompanyId(), REPOSITORY_ID, previewFilePath);
  }
Exemplo n.º 4
0
 public void deleteFiles(FileVersion fileVersion, String thumbnailType) {
   deleteFiles(
       fileVersion.getCompanyId(),
       fileVersion.getGroupId(),
       fileVersion.getFileEntryId(),
       fileVersion.getFileVersionId(),
       thumbnailType);
 }
Exemplo n.º 5
0
  protected long doGetPreviewFileSize(FileVersion fileVersion, int index, String type)
      throws PortalException, SystemException {

    return DLStoreUtil.getFileSize(
        fileVersion.getCompanyId(),
        CompanyConstants.SYSTEM,
        getPreviewFilePath(fileVersion, index, type));
  }
Exemplo n.º 6
0
  protected long doGetThumbnailFileSize(FileVersion fileVersion, int index)
      throws PortalException, SystemException {

    String type = getThumbnailType(fileVersion);

    return DLStoreUtil.getFileSize(
        fileVersion.getCompanyId(),
        CompanyConstants.SYSTEM,
        getThumbnailFilePath(fileVersion, type, index));
  }
Exemplo n.º 7
0
  protected boolean hasPreview(FileVersion fileVersion, String type) throws Exception {

    String previewFilePath = getPreviewFilePath(fileVersion, type);

    if (DLStoreUtil.hasFile(fileVersion.getCompanyId(), REPOSITORY_ID, previewFilePath)) {

      return true;
    } else {
      return false;
    }
  }
  private boolean _isGenerateThumbnail(FileVersion fileVersion) throws Exception {

    String thumbnailFilePath = getThumbnailFilePath(fileVersion);

    if (PropsValues.DL_FILE_ENTRY_THUMBNAIL_ENABLED
        && !DLStoreUtil.hasFile(fileVersion.getCompanyId(), REPOSITORY_ID, thumbnailFilePath)) {

      return true;
    } else {
      return false;
    }
  }
  private boolean _isGeneratePreview(FileVersion fileVersion) throws Exception {

    String previewFilePath = getPreviewFilePath(fileVersion, 1);

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_ENABLED
        && !DLStoreUtil.hasFile(fileVersion.getCompanyId(), REPOSITORY_ID, previewFilePath)) {

      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 10
0
  protected int doGetPreviewFileCount(FileVersion fileVersion) throws Exception {

    try {
      String[] fileNames =
          DLStoreUtil.getFileNames(
              fileVersion.getCompanyId(), REPOSITORY_ID, getPathSegment(fileVersion, true));

      return fileNames.length;
    } catch (Exception e) {
    }

    return 0;
  }
  private boolean _hasImages(FileVersion fileVersion) throws Exception {
    boolean previewExists =
        DLStoreUtil.hasFile(
            fileVersion.getCompanyId(), REPOSITORY_ID, getPreviewFilePath(fileVersion, 1));
    boolean thumbnailExists =
        DLStoreUtil.hasFile(
            fileVersion.getCompanyId(), REPOSITORY_ID, getThumbnailFilePath(fileVersion));

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_ENABLED && PropsValues.DL_FILE_ENTRY_THUMBNAIL_ENABLED) {

      if (previewExists && thumbnailExists) {
        return true;
      }
    } else if (PropsValues.DL_FILE_ENTRY_PREVIEW_ENABLED && previewExists) {
      return true;
    } else if (PropsValues.DL_FILE_ENTRY_THUMBNAIL_ENABLED && thumbnailExists) {

      return true;
    }

    return false;
  }
Exemplo n.º 12
0
  protected boolean hasThumbnail(FileVersion fileVersion, int index) {
    try {
      String imageType = getThumbnailType(fileVersion);

      return DLStoreUtil.hasFile(
          fileVersion.getCompanyId(),
          REPOSITORY_ID,
          getThumbnailFilePath(fileVersion, imageType, index));
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
Exemplo n.º 13
0
  protected void copyPreviews(FileVersion sourceFileVersion, FileVersion destinationFileVersion) {

    try {
      String[] previewTypes = getPreviewTypes();

      for (String previewType : previewTypes) {
        if (hasPreview(sourceFileVersion, previewType)
            && !hasPreview(destinationFileVersion, previewType)) {

          String previewFilePath = getPreviewFilePath(destinationFileVersion, previewType);

          InputStream is = doGetPreviewAsStream(sourceFileVersion, previewType);

          addFileToStore(destinationFileVersion.getCompanyId(), PREVIEW_PATH, previewFilePath, is);
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
Exemplo n.º 14
0
  protected void storeThumbnailmage(FileVersion fileVersion, RenderedImage renderedImage, int index)
      throws Exception {

    if (!isThumbnailEnabled(index) || hasThumbnail(fileVersion, index)) {
      return;
    }

    String type = getThumbnailType(fileVersion);

    String maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT;
    String maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH;

    if (index == THUMBNAIL_INDEX_CUSTOM_1) {
      maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_HEIGHT;
      maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_1_MAX_WIDTH;
    } else if (index == THUMBNAIL_INDEX_CUSTOM_2) {
      maxHeightPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_HEIGHT;
      maxWidthPropsKey = PropsKeys.DL_FILE_ENTRY_THUMBNAIL_CUSTOM_2_MAX_WIDTH;
    }

    RenderedImage thumbnailRenderedImage =
        ImageToolUtil.scale(
            renderedImage,
            PrefsPropsUtil.getInteger(maxHeightPropsKey),
            PrefsPropsUtil.getInteger(maxWidthPropsKey));

    byte[] bytes = ImageToolUtil.getBytes(thumbnailRenderedImage, type);

    File file = null;

    try {
      file = FileUtil.createTempFile(bytes);

      addFileToStore(
          fileVersion.getCompanyId(), THUMBNAIL_PATH,
          getThumbnailFilePath(fileVersion, type, index), file);
    } finally {
      FileUtil.delete(file);
    }
  }
Exemplo n.º 15
0
  @Override
  protected void storeThumbnailImages(FileVersion fileVersion, File file) throws Exception {

    if (!hasThumbnail(fileVersion, THUMBNAIL_INDEX_DEFAULT)) {
      addFileToStore(
          fileVersion.getCompanyId(),
          THUMBNAIL_PATH,
          getThumbnailFilePath(fileVersion, THUMBNAIL_INDEX_DEFAULT),
          file);
    }

    if (isThumbnailEnabled(THUMBNAIL_INDEX_CUSTOM_1)
        || isThumbnailEnabled(THUMBNAIL_INDEX_CUSTOM_2)) {

      ImageBag imageBag = ImageToolUtil.read(file);

      RenderedImage renderedImage = imageBag.getRenderedImage();

      storeThumbnailImage(fileVersion, renderedImage, THUMBNAIL_INDEX_CUSTOM_1);
      storeThumbnailImage(fileVersion, renderedImage, THUMBNAIL_INDEX_CUSTOM_2);
    }
  }
  @Override
  protected void copyPreviews(FileVersion sourceFileVersion, FileVersion destinationFileVersion) {

    if (!PropsValues.DL_FILE_ENTRY_PREVIEW_ENABLED) {
      return;
    }

    try {
      if (hasPreview(sourceFileVersion) && !hasPreview(destinationFileVersion)) {

        int count = getPreviewFileCount(sourceFileVersion);

        for (int i = 0; i < count; i++) {
          String previewFilePath = getPreviewFilePath(destinationFileVersion, i + 1);

          InputStream is = doGetPreviewAsStream(sourceFileVersion, i + 1, PREVIEW_TYPE);

          addFileToStore(destinationFileVersion.getCompanyId(), PREVIEW_PATH, previewFilePath, is);
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  private void _generateImagesPB(FileVersion fileVersion, File file) throws Exception {

    String tempFileId =
        DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    File thumbnailFile = getThumbnailTempFile(tempFileId);

    int previewFilesCount = 0;

    PDDocument pdDocument = null;

    try {
      pdDocument = PDDocument.load(file);

      previewFilesCount = pdDocument.getNumberOfPages();
    } finally {
      if (pdDocument != null) {
        pdDocument.close();
      }
    }

    File[] previewFiles = new File[previewFilesCount];

    for (int i = 0; i < previewFilesCount; i++) {
      previewFiles[i] = getPreviewTempFile(tempFileId, i);
    }

    boolean generatePreview = _isGeneratePreview(fileVersion);
    boolean generateThumbnail = _isGenerateThumbnail(fileVersion);

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
      ProcessCallable<String> processCallable =
          new LiferayPDFBoxProcessCallable(
              ServerDetector.getServerId(),
              PropsUtil.get(PropsKeys.LIFERAY_HOME),
              Log4JUtil.getCustomLogSettings(),
              file,
              thumbnailFile,
              previewFiles,
              getThumbnailType(fileVersion),
              getPreviewType(fileVersion),
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DPI,
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT,
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH,
              generatePreview,
              generateThumbnail);

      Future<String> future =
          ProcessExecutor.execute(ClassPathUtil.getPortalClassPath(), processCallable);

      String processIdentity = String.valueOf(fileVersion.getFileVersionId());

      futures.put(processIdentity, future);

      future.get();
    } else {
      LiferayPDFBoxConverter liferayConverter =
          new LiferayPDFBoxConverter(
              file,
              thumbnailFile,
              previewFiles,
              getPreviewType(fileVersion),
              getThumbnailType(fileVersion),
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DPI,
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT,
              PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH,
              generatePreview,
              generateThumbnail);

      liferayConverter.generateImagesPB();
    }

    if (generateThumbnail) {
      try {
        storeThumbnailImages(fileVersion, thumbnailFile);
      } finally {
        FileUtil.delete(thumbnailFile);
      }

      if (_log.isInfoEnabled()) {
        _log.info("PDFBox generated a thumbnail for " + fileVersion.getFileVersionId());
      }
    }

    if (generatePreview) {
      int index = 0;

      for (File previewFile : previewFiles) {
        try {
          addFileToStore(
              fileVersion.getCompanyId(), PREVIEW_PATH,
              getPreviewFilePath(fileVersion, index + 1), previewFile);
        } finally {
          FileUtil.delete(previewFile);
        }

        index++;
      }

      if (_log.isInfoEnabled()) {
        _log.info(
            "PDFBox generated "
                + getPreviewFileCount(fileVersion)
                + " preview pages for "
                + fileVersion.getFileVersionId());
      }
    }
  }
  private void _generateImagesIM(
      FileVersion fileVersion,
      File file,
      int depth,
      int dpi,
      int height,
      int width,
      boolean thumbnail)
      throws Exception {

    // Generate images

    String tempFileId =
        DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    IMOperation imOperation = new IMOperation();

    imOperation.alpha("off");

    imOperation.density(dpi, dpi);

    if (height != 0) {
      imOperation.adaptiveResize(width, height);
    } else {
      imOperation.adaptiveResize(width);
    }

    imOperation.depth(depth);

    if (thumbnail) {
      imOperation.addImage(file.getPath() + "[0]");
      imOperation.addImage(getThumbnailTempFilePath(tempFileId));
    } else {
      imOperation.addImage(file.getPath());
      imOperation.addImage(getPreviewTempFilePath(tempFileId, -1));
    }

    _convertCmd.run(imOperation);

    // Store images

    if (thumbnail) {
      File thumbnailTempFile = getThumbnailTempFile(tempFileId);

      try {
        addFileToStore(
            fileVersion.getCompanyId(), THUMBNAIL_PATH,
            getThumbnailFilePath(fileVersion), thumbnailTempFile);
      } finally {
        FileUtil.delete(thumbnailTempFile);
      }
    } else {

      // ImageMagick converts single page PDFs without appending an
      // index. Rename file for consistency.

      File singlePagePreviewFile = getPreviewTempFile(tempFileId, -1);

      if (singlePagePreviewFile.exists()) {
        singlePagePreviewFile.renameTo(getPreviewTempFile(tempFileId, 1));
      }

      int total = getPreviewTempFileCount(fileVersion);

      for (int i = 0; i < total; i++) {
        File previewTempFile = getPreviewTempFile(tempFileId, i + 1);

        try {
          addFileToStore(
              fileVersion.getCompanyId(),
              PREVIEW_PATH,
              getPreviewFilePath(fileVersion, i + 1),
              previewTempFile);
        } finally {
          FileUtil.delete(previewTempFile);
        }
      }
    }
  }
  private void _generateImagesGS(FileVersion fileVersion, File file, boolean thumbnail)
      throws Exception {

    // Generate images

    String tempFileId =
        DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    List<String> arguments = new ArrayList<String>();

    arguments.add("-sDEVICE=png16m");

    if (thumbnail) {
      arguments.add("-sOutputFile=" + getThumbnailTempFilePath(tempFileId));
      arguments.add("-dFirstPage=1");
      arguments.add("-dLastPage=1");
    } else {
      arguments.add("-sOutputFile=" + getPreviewTempFilePath(tempFileId, -1));
    }

    arguments.add("-dPDFFitPage");
    arguments.add("-dTextAlphaBits=4");
    arguments.add("-dGraphicsAlphaBits=4");
    arguments.add("-r" + PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_DPI);

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH != 0) {
      arguments.add("-dDEVICEWIDTH" + PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_WIDTH);
    }

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT != 0) {
      arguments.add("-dDEVICEHEIGHT" + PropsValues.DL_FILE_ENTRY_PREVIEW_DOCUMENT_MAX_HEIGHT);
    }

    arguments.add(file.getPath());

    Future<?> future = GhostscriptUtil.execute(arguments);

    String processIdentity = String.valueOf(fileVersion.getFileVersionId());

    futures.put(processIdentity, future);

    future.get();

    // Store images

    if (thumbnail) {
      File thumbnailTempFile = getThumbnailTempFile(tempFileId);

      try {
        storeThumbnailImages(fileVersion, thumbnailTempFile);
      } finally {
        FileUtil.delete(thumbnailTempFile);
      }
    } else {
      int total = getPreviewTempFileCount(fileVersion);

      for (int i = 0; i < total; i++) {
        File previewTempFile = getPreviewTempFile(tempFileId, i + 2);

        try {
          addFileToStore(
              fileVersion.getCompanyId(),
              PREVIEW_PATH,
              getPreviewFilePath(fileVersion, i + 1),
              previewTempFile);
        } finally {
          FileUtil.delete(previewTempFile);
        }
      }
    }
  }
Exemplo n.º 20
0
  private void _generateVideoXuggler(
      FileVersion fileVersion, File sourceFile, File destinationFile, String containerType)
      throws Exception {

    if (hasPreview(fileVersion, containerType)) {
      return;
    }

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();

    if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) {
      ProcessCallable<String> processCallable =
          new LiferayVideoProcessCallable(
              ServerDetector.getServerId(),
              PropsUtil.get(PropsKeys.LIFERAY_HOME),
              Log4JUtil.getCustomLogSettings(),
              sourceFile,
              destinationFile,
              containerType,
              PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false),
              PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true));

      ProcessChannel<String> processChannel =
          ProcessExecutorUtil.execute(ClassPathUtil.getPortalProcessConfig(), processCallable);

      Future<String> future = processChannel.getProcessNoticeableFuture();

      String processIdentity = String.valueOf(fileVersion.getFileVersionId());

      futures.put(processIdentity, future);

      future.get();
    } else {
      LiferayConverter liferayConverter =
          new LiferayVideoConverter(
              sourceFile.getCanonicalPath(),
              destinationFile.getCanonicalPath(),
              containerType,
              PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false),
              PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true));

      liferayConverter.convert();
    }

    addFileToStore(
        fileVersion.getCompanyId(), PREVIEW_PATH,
        getPreviewFilePath(fileVersion, containerType), destinationFile);

    if (_log.isInfoEnabled()) {
      _log.info(
          "Xuggler generated a "
              + containerType
              + " preview video for "
              + fileVersion.getTitle()
              + " in "
              + stopWatch.getTime()
              + " ms");
    }
  }
  public FileEntry moveFileEntryToTrash(long userId, FileEntry fileEntry)
      throws PortalException, SystemException {

    // File entry

    DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

    dlFileEntry.setTitle(DLAppUtil.appendTrashNamespace(dlFileEntry.getTitle()));

    dlFileEntryPersistence.update(dlFileEntry, false);

    List<DLFileVersion> dlFileVersions =
        dlFileVersionLocalService.getFileVersions(
            fileEntry.getFileEntryId(), WorkflowConstants.STATUS_ANY);

    dlFileVersions = ListUtil.sort(dlFileVersions, new FileVersionVersionComparator());

    FileVersion fileVersion = new LiferayFileVersion(dlFileVersions.get(0));

    int oldStatus = fileVersion.getStatus();

    // File version

    dlFileEntryLocalService.updateStatus(
        userId,
        fileVersion.getFileVersionId(),
        WorkflowConstants.STATUS_IN_TRASH,
        new HashMap<String, Serializable>(),
        new ServiceContext());

    // File shortcut

    dlFileShortcutLocalService.disableFileShortcuts(fileEntry.getFileEntryId());

    // File rank

    dlFileRankLocalService.disableFileRanks(fileEntry.getFileEntryId());

    // Social

    socialActivityLocalService.addActivity(
        userId,
        fileEntry.getGroupId(),
        DLFileEntryConstants.getClassName(),
        fileEntry.getFileEntryId(),
        SocialActivityConstants.TYPE_MOVE_TO_TRASH,
        StringPool.BLANK,
        0);

    // Trash

    List<ObjectValuePair<Long, Integer>> fileVersionStatuses =
        new ArrayList<ObjectValuePair<Long, Integer>>(dlFileVersions.size());

    for (DLFileVersion dlFileVersion : dlFileVersions) {
      ObjectValuePair<Long, Integer> fileVersionStatus = new ObjectValuePair<Long, Integer>();

      fileVersionStatus.setKey(dlFileVersion.getFileVersionId());

      int status = dlFileVersion.getStatus();

      if (status == WorkflowConstants.STATUS_PENDING) {
        status = WorkflowConstants.STATUS_DRAFT;
      }

      fileVersionStatus.setValue(status);

      fileVersionStatuses.add(fileVersionStatus);
    }

    trashEntryLocalService.addTrashEntry(
        userId,
        fileEntry.getGroupId(),
        DLFileEntryConstants.getClassName(),
        fileEntry.getFileEntryId(),
        oldStatus,
        fileVersionStatuses,
        null);

    // Workflow

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
      workflowInstanceLinkLocalService.deleteWorkflowInstanceLink(
          fileVersion.getCompanyId(),
          fileVersion.getGroupId(),
          DLFileEntryConstants.getClassName(),
          fileVersion.getFileVersionId());
    }

    return fileEntry;
  }