private static void decorateDatastreamNode( final DocumentReader docReader, final DocumentWriter docWriter) { if (!docReader.getMixinTypeNames().contains(FEDORA_DATASTREAM)) { LOGGER.trace("Adding mixin: {}, to {}", FEDORA_DATASTREAM, docReader.getDocumentId()); docWriter.addMixinType(FEDORA_DATASTREAM); } }
private void saveProperties(final DocumentReader docReader) { LOGGER.trace("Persisting properties for {}", docReader.getDocumentId()); final Map<Name, Property> properties = docReader.getProperties(); final ExtraProperties extraProperties = extraPropertiesFor(docReader.getDocumentId(), true); extraProperties .addAll(properties) .except(JCR_PRIMARY_TYPE, JCR_CREATED, JCR_LASTMODIFIED, JCR_DATA); extraProperties.save(); }
@Override public String sha1(final File file) { final String id = idFor(file); final Document doc = super.getDocumentById(id); final DocumentReader docReader = readDocument(doc); if (null != docReader.getProperty(CONTENT_DIGEST)) { return docReader.getProperty(CONTENT_DIGEST).toString(); } return super.sha1(file); }
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()); }
/** * This method returns the object/document for the node with the federated arg 'id'. * * <p>Additionally, this method adds Fedora datastream and content properties to the result of the * parent class implementation. */ @Override public Document getDocumentById(final String id) { LOGGER.debug("Getting Federated document: {}", id); if (null == id || id.isEmpty()) { LOGGER.warn("Can not get document with null id"); return null; } final Document doc = super.getDocumentById(id); final DocumentReader docReader = readDocument(doc); final DocumentWriter docWriter = writeDocument(doc); final String primaryType = docReader.getPrimaryTypeName(); if (!docReader.getMixinTypeNames().contains(FEDORA_RESOURCE)) { LOGGER.trace("Adding mixin: {}, to {}", FEDORA_RESOURCE, id); docWriter.addMixinType(FEDORA_RESOURCE); } // Is Fedora Datastream? if (primaryType.equals(NT_FILE)) { decorateDatastreamNode(docReader, docWriter); // Is Fedora Content? } else if (primaryType.equals(NT_RESOURCE)) { decorateContentNode(docReader, docWriter); } // Persist new properties if (!isReadonly()) { saveProperties(docReader); } return docWriter.document(); }
private static BinaryValue getBinaryValue(final DocumentReader docReader) { final Property binaryProperty = docReader.getProperty(JCR_DATA); return (BinaryValue) binaryProperty.getFirstValue(); }