public Response createTransaction(@PathParam("path") final String externalPath) throws URISyntaxException { if (batchService.exists(session.getId(), getUserPrincipal())) { LOGGER.debug("renewing transaction {}", session.getId()); 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()); new URI(translator().toDomain("/tx:" + session.getId()).toString())); session.getFedoraSession().getExpires().ifPresent(expires -> { res.expires(from(expires)); });
/** * 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(); }
/** * Retrieve a JCR session from an active transaction * * @param servletRequest the servlet request * @param txId the transaction id * @return a JCR session that is associated with the transaction */ protected HttpSession getSessionFromTransaction(final HttpServletRequest servletRequest, final String txId) { final Principal userPrincipal = servletRequest.getUserPrincipal(); final String userName = userPrincipal == null ? null : userPrincipal.getName(); final FedoraSession session = batchService.getSession(txId, userName); final HttpSession batchSession = new HttpSession(session); batchSession.makeBatchSession(); LOGGER.debug("Returning a session in the batch {} for user {}", batchSession, userName); return batchSession; }
private Response finalizeTransaction(@PathParam("path") final String externalPath, final String username, final boolean commit) { final String path = toPath(translator(), externalPath); if (!path.equals("/")) { return status(BAD_REQUEST).build(); } if (!session.isBatchSession()) { LOGGER.debug("cannot finalize an empty tx id {} at path {}", session.getId(), path); return status(BAD_REQUEST).build(); } if (commit) { LOGGER.debug("commiting transaction {} at path {}", session.getId(), path); batchService.commit(session.getId(), username); } else { LOGGER.debug("rolling back transaction {} at path {}", session.getId(), path); batchService.abort(session.getId(), username); } return noContent().build(); } }
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();
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("/")); } }
/** * Commit a non-batch session */ public void commit() { if (!isBatchSession()) { session.commit(); } }
/** * Delete a tombstone resource (freeing the original resource to be reused) * @return the free resource */ @DELETE public Response delete() { LOGGER.info("Delete tombstone: {}", resource()); resource().delete(); session.commit(); return noContent().build(); }
@Override public void dispose(final HttpSession session) { LOGGER.trace("Disposing session {}", session); session.expire(); } }
/** * Create a JCR session for the given HTTP servlet request with a * SecurityContext attached. * * @param servletRequest the servlet request * @return a newly created JCR session */ protected HttpSession createSession(final HttpServletRequest servletRequest) { LOGGER.debug("Returning an authenticated session in the default workspace"); return new HttpSession(repo.login(credentialsService.getCredentials(servletRequest))); }
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(); } catch (final RepositoryRuntimeException e) {
final Collection<Throwable> problems = repositoryService.restoreRepository(session.getFedoraSession(), backupDirectory); if (!problems.isEmpty()) {
/** * Expire a non-batch session */ public void expire() { if (!isBatchSession()) { session.expire(); } }
/** * Deletes an object. * * @return response */ @DELETE public Response deleteObject() { hasRestrictedPath(externalPath); if (resource() instanceof Container) { final String depth = headers.getHeaderString("Depth"); LOGGER.debug("Depth header value is: {}", depth); if (depth != null && !depth.equalsIgnoreCase("infinity")) { throw new ClientErrorException("Depth header, if present, must be set to 'infinity' for containers", SC_BAD_REQUEST); } } evaluateRequestPreconditions(request, servletResponse, resource(), session); LOGGER.info("Delete resource '{}'", externalPath); final AcquiredLock lock = lockManager.lockForDelete(resource().getPath()); try { resource().delete(); session.commit(); return noContent().build(); } finally { lock.release(); } }
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); session.commit(); return createUpdateResponse(memento, true); } catch (final Exception e) {
/** * 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()); } }
@Override protected void addResourceHttpHeaders(final FedoraResource resource) { super.addResourceHttpHeaders(resource); if (session.isBatchSession()) { final String canonical = translator().reverse() .convert(resource) .toString() .replaceFirst("/tx:[^/]+", ""); servletResponse.addHeader(LINK, "<" + canonical + ">;rel=\"canonical\""); } addExternalContentHeaders(resource); }
/** * Deletes an object. * * @return response */ @DELETE public Response deleteObject() throws ItemNotFoundException { hasRestrictedPath(externalPath); LOGGER.info("Delete resource '{}'", externalPath); final AcquiredLock lock = lockManager.lockForDelete(resource().getPath()); try { final FedoraResource aclResource = resource().getAcl(); if (aclResource != null) { aclResource.delete(); } session.commit(); if (aclResource == null) { if (resource().hasType(FEDORA_REPOSITORY_ROOT)) { throw new ClientErrorException("The default root ACL is system generated and cannot be deleted. " + "To override the default root ACL you must PUT a user-defined ACL to this endpoint.", CONFLICT); } throw new ItemNotFoundException(); } return noContent().build(); } finally { lock.release(); } }
hasRestrictedPath(newObjectPath); final AcquiredLock lock = lockManager.lockForWrite(newObjectPath, session.getFedoraSession(), nodeService); (requestBodyStream == null || requestContentType == null)); session.commit(); } catch (final Exception e) { checkForInsufficientStorageException(e, e);
final Collection<Throwable> problems = repositoryService.backupRepository(session.getFedoraSession(), backupDirectory);