コード例 #1
0
  /**
   * Adds content to a space.
   *
   * @return the checksum of the content as computed by the storage provider
   */
  @Override
  public String addContent(
      String spaceID,
      String contentID,
      InputStream content,
      String contentMimeType,
      Map<String, String> userProperties,
      long contentSize,
      String checksum,
      String storeID)
      throws ResourceException, InvalidIdException {
    IdUtil.validateContentId(contentID);

    try {
      StorageProvider storage = storageProviderFactory.getStorageProvider(storeID);

      try {
        // overlay new properties on top of older extended properties
        // so that old tags and custom properties are preserved.
        // c.f. https://jira.duraspace.org/browse/DURACLOUD-757
        Map<String, String> oldUserProperties = storage.getContentProperties(spaceID, contentID);
        // remove all non extended properties
        if (userProperties != null) {
          oldUserProperties.putAll(userProperties);
          // use old mimetype if none specified.
          String oldMimetype =
              oldUserProperties.remove(StorageProvider.PROPERTIES_CONTENT_MIMETYPE);
          if (contentMimeType == null || contentMimeType.trim() == "") {
            contentMimeType = oldMimetype;
          }

          oldUserProperties = StorageProviderUtil.removeCalculatedProperties(oldUserProperties);
        }

        userProperties = oldUserProperties;
      } catch (NotFoundException ex) {
        // do nothing - no properties to update
        // since file did not previous exist.
      }

      return storage.addContent(
          spaceID, contentID, contentMimeType, userProperties, contentSize, checksum, content);
    } catch (NotFoundException e) {
      throw new ResourceNotFoundException("add content", spaceID, contentID, e);
    } catch (ChecksumMismatchException e) {
      throw new ResourceChecksumException("add content", spaceID, contentID, e);
    } catch (Exception e) {
      storageProviderFactory.expireStorageProvider(storeID);
      throw new ResourceException("add content", spaceID, contentID, e);
    }
  }
コード例 #2
0
 protected Map<String, String> removeCalculatedProperties(Map<String, String> properties) {
   return StorageProviderUtil.removeCalculatedProperties(properties);
 }