Exemplo n.º 1
0
  /**
   * This method copies the content found in space srcSpaceID with id srcContentID to the space
   * destSpaceID within the same content store (storeID) to the id of destContentID.
   *
   * @param srcStoreID of content to copy
   * @param srcSpaceID of content to copy
   * @param srcContentID of content to copy
   * @param destSpaceID of copied content
   * @param destContentID of copied content
   * @param destStoreID of copied content
   * @return MD5 checksum of the content as computed by the storage provider
   * @throws ResourceException
   */
  @Override
  public String copyContent(
      String srcStoreID,
      String srcSpaceID,
      String srcContentID,
      String destStoreID,
      String destSpaceID,
      String destContentID)
      throws ResourceException {
    BrokeredStorageProvider srcProvider = getStorageProvider(srcStoreID);
    BrokeredStorageProvider destProvider = getStorageProvider(destStoreID);

    if (srcProvider.equals(destProvider)) {
      return copyContent(
          srcProvider, srcSpaceID, srcContentID, destSpaceID, destContentID, srcStoreID);
    } else {
      return copyContentBetweenStorageProviders(
          srcProvider,
          srcSpaceID,
          srcContentID,
          srcStoreID,
          destProvider,
          destSpaceID,
          destContentID,
          destStoreID);
    }
  }
Exemplo n.º 2
0
  private String copyContentBetweenStorageProviders(
      BrokeredStorageProvider srcStorage,
      String srcSpaceID,
      String srcContentID,
      String srcStoreID,
      BrokeredStorageProvider destStorage,
      String destSpaceID,
      String destContentID,
      String destStoreID)
      throws ResourceException {
    try {
      InputStream inputStream = srcStorage.getContent(srcSpaceID, srcContentID);

      Map<String, String> properties = srcStorage.getContentProperties(srcSpaceID, srcContentID);

      Long contentSize = null;

      try {
        String contentSizeString = properties.get(StorageProvider.PROPERTIES_CONTENT_SIZE);
        if (contentSizeString != null) {
          contentSize = Long.parseLong(contentSizeString);
        }
      } catch (NumberFormatException ex) {
        String msg = "content size could not be parsed: " + ex.getMessage();
        log.warn(msg, ex);
      }

      String md5 =
          destStorage.addContent(
              destSpaceID,
              destContentID,
              properties.get(StorageProvider.PROPERTIES_CONTENT_MIMETYPE),
              properties,
              contentSize,
              properties.get(StorageProvider.PROPERTIES_CONTENT_CHECKSUM),
              inputStream);

      return md5;
    } catch (NotFoundException e) {
      throw new ResourceNotFoundException(
          "copy content",
          srcStorage.getTargetType().name(),
          srcSpaceID,
          srcContentID,
          destStorage.getTargetType().name(),
          destSpaceID,
          destContentID,
          e);
    } catch (StorageStateException e) {
      throw new ResourceStateException(
          "copy content",
          srcStorage.getTargetType().name(),
          srcSpaceID,
          srcContentID,
          destStorage.getTargetType().name(),
          destSpaceID,
          destContentID,
          e);
    } catch (Exception e) {
      storageProviderFactory.expireStorageProvider(srcStoreID);
      storageProviderFactory.expireStorageProvider(destStoreID);
      throw new ResourceException(
          "copy content",
          srcStorage.getTargetType().name(),
          srcSpaceID,
          srcContentID,
          destStorage.getTargetType().name(),
          destSpaceID,
          destContentID,
          e);
    }
  }