private static void decorateContentNode(
      final DocumentReader docReader, final DocumentWriter docWriter) {
    if (!docReader.getMixinTypeNames().contains(FEDORA_BINARY)) {
      LOGGER.trace("Adding mixin: {}, to {}", FEDORA_BINARY, docReader.getDocumentId());
      docWriter.addMixinType(FEDORA_BINARY);
    }

    if (null == docReader.getProperty(CONTENT_DIGEST)) {
      final BinaryValue binaryValue = getBinaryValue(docReader);
      final String dsChecksum = binaryValue.getHexHash();
      final String dsURI = asURI("SHA-1", dsChecksum).toString();

      LOGGER.trace(
          "Adding {} property of {} to {}", CONTENT_DIGEST, dsURI, docReader.getDocumentId());
      docWriter.addProperty(CONTENT_DIGEST, dsURI);
    }

    if (null == docReader.getProperty(CONTENT_SIZE)) {
      final BinaryValue binaryValue = getBinaryValue(docReader);
      final long binarySize = binaryValue.getSize();

      LOGGER.trace(
          "Adding {} property of {} to {}", CONTENT_SIZE, binarySize, docReader.getDocumentId());
      docWriter.addProperty(CONTENT_SIZE, binarySize);
    }

    LOGGER.debug("Decorated data property at path: {}", docReader.getDocumentId());
  }
Пример #2
0
  @Override
  public BinaryValue storeValue(InputStream stream) throws BinaryStoreException {
    // store into temporary file system store and get SHA-1
    BinaryValue temp = cache.storeValue(stream);
    try {
      // prepare new binary key based on SHA-1
      BinaryKey key = new BinaryKey(temp.getKey().toString());

      // check for duplicate content
      if (this.contentExists(key, ALIVE)) {
        return new StoredBinaryValue(this, key, temp.getSize());
      }

      // check unused content
      if (this.contentExists(key, UNUSED)) {
        session.execute("UPDATE modeshape.binary SET usage=1 WHERE cid='" + key + "';");
        return new StoredBinaryValue(this, key, temp.getSize());
      }

      // store content
      PreparedStatement query =
          session.prepare(
              "INSERT INTO modeshape.binary (cid, usage_time, payload, usage) VALUES ( ?,?,?,1 );");
      BoundStatement statement = new BoundStatement(query);
      session.execute(statement.bind(key.toString(), new Date(), buffer(stream)));
      return new StoredBinaryValue(this, key, temp.getSize());
    } catch (BinaryStoreException e) {
      throw e;
    } catch (IOException e) {
      throw new BinaryStoreException(e);
    } catch (RuntimeException e) {
      throw new BinaryStoreException(e);
    } finally {
      // remove content from temp store
      cache.markAsUnused(temp.getKey());
    }
  }