/** * @param session the session * @param path the path */ @Override public FedoraResource findOrCreate(final FedoraSession session, final String path) { throw new RepositoryRuntimeException("unimplemented"); } }
@Override public String getPath() { try { final String path = node.getPath(); return path.endsWith("/" + JCR_CONTENT) ? path.substring(0, path.length() - JCR_CONTENT.length() - 1) : path; } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public void delete() { try { node.remove(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public FedoraResource getOriginalResource() { try { final Property originalProperty = node.getProperty(MEMENTO_ORIGINAL); final Node originalNode = originalProperty.getNode(); return Optional.of(originalNode).map(nodeConverter::convert).orElse(null); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } } }
@Override protected boolean hasDescriptionProperty(final String relPath) { try { final Node descNode = getDescriptionNodeOrNull(); if (descNode == null) { return false; } return descNode.hasProperty(relPath); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
/** * Check if the node has a fedora:tombstone mixin * @param node the node * @return true if the node has the fedora object mixin */ public static boolean hasMixin(final Node node) { try { return node.isNodeType(FEDORA_TOMBSTONE); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public boolean hasProperty(final String relPath) { try { return getNode().hasProperty(relPath); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
protected Session getSession() { try { return getNode().getSession(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public String getProxyURL() { try { if (hasProperty(PROXY_FOR)) { return getProperty(PROXY_FOR).getString(); } return null; } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public InputStream getInputStream() { try { LOGGER.debug("getInputStream getExternalIdentifier: {} {} ", property().getName(), getExternalIdentifier()); return URI.create(getExternalIdentifier()).toURL().openStream(); } catch (final MalformedURLException e) { throw new RepositoryRuntimeException("Malformed URL: " + getExternalIdentifier(), e); } catch (final Exception e) { throw new RepositoryRuntimeException(e); } }
@Override public Stream<FedoraResource> getChildren(final Boolean recursive) { try { if (recursive) { return nodeToGoodChildren(node).flatMap(FedoraResourceImpl::getAllChildren); } return nodeToGoodChildren(node); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public String getFilename() { try { if (hasDescriptionProperty(FILENAME)) { return getDescriptionProperty(FILENAME).getString().replace(FIELD_DELIMITER + XSDstring.getURI(), ""); } return node.getName(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public InputStream getContent() { try { return getBinaryContent().getStream(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
protected Node findNode(final FedoraSession session, final String path) { final Session jcrSession = getJcrSession(session); try { return jcrSession.getNode(path); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public InputStream getInputStream() { try { return property.getBinary().getStream(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public String getExternalIdentifier() { try { LOGGER.debug("getExternalIdentifier for property {} ", property().getName()); return property().getValue().getString(); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } } }
@Override public Collection<URI> checkFixity(final IdentifierConverter<Resource, FedoraResource> idTranslator, final Collection<String> algorithms) throws UnsupportedAlgorithmException { try { LOGGER.debug("Checking resource: {}", getPath()); return CacheEntryFactory.forProperty(getProperty(JCR_DATA)).checkFixity(algorithms); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Override public List<Map<String, Collection<Object>>> apply(final RdfStream stream) { final LDPath<RDFNode> ldpathForResource = getLdpathResource(stream); final Resource context = createResource(stream.topic().getURI()); try { return ImmutableList.of(unsafeCast( ldpathForResource.programQuery(context, new InputStreamReader(query)))); } catch (final LDPathParseException e) { throw new RepositoryRuntimeException(e); } }
@Override public FedoraResource getOriginalResource() { if (!isMemento()) { return this; } try { return nodeConverter.convert(node.getParent().getParent()); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
private Container createContainer(final FedoraSession session, final String path) { try { final Node node = findOrCreateNode(session, path, NT_FOLDER); if (node.canAddMixin(FEDORA_RESOURCE)) { node.addMixin(FEDORA_RESOURCE); node.addMixin(FEDORA_CONTAINER); } return new ContainerImpl(node); } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }