private void checkExistingAncestor(final String path) { // check the closest existing ancestor for containment violations. String parentPath = path.substring(0, path.lastIndexOf("/")); while (!(parentPath.isEmpty() || parentPath.equals("/"))) { if (nodeService.exists(session.getFedoraSession(), parentPath)) { if (!(getResourceFromPath(parentPath) instanceof Container)) { throw new ClientErrorException("Unable to add child " + path.replace(parentPath, "") + " to resource " + parentPath + ".", CONFLICT); } break; } parentPath = parentPath.substring(0, parentPath.lastIndexOf("/")); } }
final Collection<Throwable> problems = repositoryService.restoreRepository(session.getFedoraSession(), backupDirectory); if (!problems.isEmpty()) {
/** * Set the baseURL for JMS events. * @param uriInfo the uri info * @param headers HTTP headers **/ protected void setUpJMSInfo(final UriInfo uriInfo, final HttpHeaders headers) { try { String baseURL = getBaseUrlProperty(uriInfo); if (baseURL.length() == 0) { baseURL = uriInfo.getBaseUri().toString(); } LOGGER.debug("setting baseURL = " + baseURL); session.getFedoraSession().addSessionData(BASE_URL, baseURL); if (!StringUtils.isBlank(headers.getHeaderString("user-agent"))) { session.getFedoraSession().addSessionData(USER_AGENT, headers.getHeaderString("user-agent")); } } catch (final Exception ex) { LOGGER.warn("Error setting baseURL", ex.getMessage()); } }
final Collection<Throwable> problems = repositoryService.backupRepository(session.getFedoraSession(), backupDirectory);
private FedoraBinary createBinaryMementoFromRequest(final FedoraBinary binaryResource, final Instant mementoInstant, final InputStream requestBodyStream, final ExternalContentHandler extContent, final String digest) throws InvalidChecksumException, UnsupportedAlgorithmException { final Collection<String> checksums = parseDigestHeader(digest); final Collection<URI> checksumURIs = checksums == null ? new HashSet<>() : checksums.stream().map( checksum -> checksumURI(checksum)).collect(Collectors.toSet()); // Create internal binary either from supplied body or copy external uri if (extContent == null || extContent.isCopy()) { InputStream contentStream = requestBodyStream; if (extContent != null) { contentStream = extContent.fetchExternalContent(); } return versionService.createBinaryVersion(session.getFedoraSession(), binaryResource, mementoInstant, contentStream, checksumURIs, storagePolicyDecisionPoint); } else { return versionService.createExternalBinaryVersion(session.getFedoraSession(), binaryResource, mementoInstant, checksumURIs, extContent.getHandling(), extContent.getURL()); } }
batchService.refresh(session.getId(), getUserPrincipal()); final Response.ResponseBuilder res = noContent(); session.getFedoraSession().getExpires().ifPresent(expires -> { res.expires(from(expires)); }); batchService.begin(session.getFedoraSession(), getUserPrincipal()); session.makeBatchSession(); LOGGER.info("Created transaction '{}'", session.getId()); session.getFedoraSession().getExpires().ifPresent(expires -> { res.expires(from(expires)); });
private FedoraResource createFedoraResource(final String path, final String interactionModel, final MediaType contentType, final boolean contentPresent, final boolean contentExternal) { final MediaType simpleContentType = contentPresent ? getSimpleContentType(contentType) : null; final FedoraResource result; if ("ldp:NonRDFSource".equals(interactionModel) || contentExternal || (contentPresent && interactionModel == null && !isRDF(simpleContentType))) { result = binaryService.findOrCreate(session.getFedoraSession(), path); } else { result = containerService.findOrCreate(session.getFedoraSession(), path); } final String resInteractionModel = getInteractionModel(result); if (StringUtils.isNoneBlank(interactionModel) && StringUtils.isNoneBlank(resInteractionModel) && !resInteractionModel.equals(interactionModel)) { throw new InteractionModelViolationException("Changing the interaction model " + resInteractionModel + " to " + interactionModel + " is not allowed!"); } return result; }
private String mintNewPid(final String slug) { String pid; if (slug != null && !slug.isEmpty()) { pid = slug; } else if (pidMinter != null) { pid = pidMinter.get(); } else { pid = defaultPidMinter.get(); } // reverse translate the proffered or created identifier LOGGER.trace("Using external identifier {} to create new resource.", pid); LOGGER.trace("Using prefixed external identifier {} to create new resource.", uriInfo.getBaseUri() + "/" + pid); final URI newResourceUri = uriInfo.getAbsolutePathBuilder().clone().path(FedoraLdp.class) .resolveTemplate("path", pid, false).build(); pid = translator().asString(createResource(newResourceUri.toString())); try { pid = URLDecoder.decode(pid, "UTF-8"); } catch (final UnsupportedEncodingException e) { // noop } // remove leading slash left over from translation LOGGER.trace("Using internal identifier {} to create new resource.", pid); if (nodeService.exists(session.getFedoraSession(), pid)) { LOGGER.trace("Resource with path {} already exists; minting new path instead", pid); return mintNewPid(null); } return pid; }
/** * Create a new identifier converter within the given session with the given URI template * @param session the session * @param uriBuilder the uri builder */ public HttpResourceConverter(final HttpSession session, final UriBuilder uriBuilder) { this.session = session.getFedoraSession(); this.uriBuilder = uriBuilder; this.batch = session.isBatchSession(); this.uriTemplate = new UriTemplate(uriBuilder.toTemplate()); resetTranslationChain(); }
final String source = translator().asString(translator().toDomain(externalPath)); if (!nodeService.exists(session.getFedoraSession(), source)) { throw new ClientErrorException("The source path does not exist", CONFLICT); } else if (nodeService.exists(session.getFedoraSession(), destination)) { throw new ClientErrorException("Destination resource already exists", PRECONDITION_FAILED); nodeService.copyObject(session.getFedoraSession(), source, destination); session.commit();
if (!nodeService.exists(session.getFedoraSession(), source)) { throw new ClientErrorException("The source path does not exist", CONFLICT); } else if (nodeService.exists(session.getFedoraSession(), destination)) { throw new ClientErrorException("Destination resource already exists", PRECONDITION_FAILED); nodeService.moveObject(session.getFedoraSession(), source, destination); session.commit(); return created(new URI(destinationUri)).build();
session.getFedoraSession(), nodeService); final FedoraBinary binaryResource = (FedoraBinary) resource; if (createFromExisting) { memento = versionService.createBinaryVersion(session.getFedoraSession(), binaryResource, mementoInstant, storagePolicyDecisionPoint); } else { final FedoraResource rdfMemento = versionService.createVersion(session.getFedoraSession(), originalResource, idTranslator, mementoInstant, bodyStream, format);
hasRestrictedPath(newObjectPath); final AcquiredLock lock = lockManager.lockForWrite(newObjectPath, session.getFedoraSession(), nodeService);
final AcquiredLock lock = lockManager.lockForWrite(resource().getPath(), session.getFedoraSession(), nodeService);
final AcquiredLock lock = lockManager.lockForWrite(aclResource.getPath(), session.getFedoraSession(), nodeService);
final AcquiredLock lock = lockManager.lockForWrite(path, session.getFedoraSession(), nodeService); try { LOGGER.info("PUT acl resource '{}'", externalPath);
final AcquiredLock lock = lockManager.lockForWrite(path, session.getFedoraSession(), nodeService); extContent != null ? extContent.getContentType() : requestContentType); if (nodeService.exists(session.getFedoraSession(), path)) { resource = resource();