예제 #1
0
  protected void migrateImage(
      long fileEntryId,
      long companyId,
      long groupId,
      long folderId,
      String name,
      long smallImageId,
      long largeImageId,
      long custom1ImageId,
      long custom2ImageId)
      throws Exception {

    Image largeImage = null;

    if (largeImageId != 0) {
      largeImage = ImageLocalServiceUtil.getImage(largeImageId);

      long repositoryId = DLFolderConstants.getDataRepositoryId(groupId, folderId);

      try {
        migrateFile(repositoryId, companyId, name, largeImage);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Ignoring exception for image " + largeImageId, e);
        }
      }
    }

    long thumbnailImageId = 0;

    if (smallImageId != 0) {
      thumbnailImageId = smallImageId;
    } else if (custom1ImageId != 0) {
      thumbnailImageId = custom1ImageId;
    } else if (custom2ImageId != 0) {
      thumbnailImageId = custom2ImageId;
    }

    Image thumbnailImage = null;

    if (thumbnailImageId != 0) {
      thumbnailImage = ImageLocalServiceUtil.getImage(thumbnailImageId);

      Connection con = null;
      PreparedStatement ps = null;
      ResultSet rs = null;

      try {
        InputStream is = _sourceHook.getImageAsStream(thumbnailImage);

        con = DataAccess.getConnection();

        ps =
            con.prepareStatement(
                "select max(fileVersionId) from DLFileVersion where "
                    + "fileEntryId = "
                    + fileEntryId);

        rs = ps.executeQuery();

        if (rs.next()) {
          long fileVersionId = rs.getLong(1);

          ImageProcessorUtil.storeThumbnail(
              companyId,
              groupId,
              fileEntryId,
              fileVersionId,
              custom1ImageId,
              custom2ImageId,
              is,
              thumbnailImage.getType());
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Ignoring exception for image " + thumbnailImageId, e);
        }
      } finally {
        DataAccess.cleanUp(con, ps, rs);
      }
    }

    if (largeImageId != 0) {
      _sourceHook.deleteImage(largeImage);

      runSQL("delete from Image where imageId = " + largeImageId);
    }

    if ((largeImageId != thumbnailImageId) && (thumbnailImageId != 0)) {
      _sourceHook.deleteImage(thumbnailImage);

      runSQL("delete from Image where imageId = " + thumbnailImageId);
    }
  }
예제 #2
0
 @Override
 public long getDataRepositoryId() {
   return DLFolderConstants.getDataRepositoryId(getGroupId(), getFolderId());
 }