/** * May be called by implementing classes to open a System session on the repository. * * @since 8.1 */ public void openSystemSession() { session = CoreInstance.openCoreSessionSystem(repositoryName, originatingUsername); }
/** * Make sure we open the repository, to initialize its connection manager. */ protected void activateRepository(String repositoryName) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(repositoryName)) { // do nothing, just open and close } }
/** * May be called by implementing classes to open a session on the given repository. * * @param repositoryName the repository name * @return the session (also available in {@code session} field) * @deprecated since 8.1. Use {@link #openSystemSession()} to open a session on the configured repository name, * otherwise use {@link CoreInstance#openCoreSessionSystem(String)}. */ @Deprecated public CoreSession initSession(String repositoryName) { session = CoreInstance.openCoreSessionSystem(repositoryName, originatingUsername); return session; }
public CloseableCoreSession openCoreSessionSystem() { return CoreInstance.openCoreSessionSystem(getRepositoryName()); }
protected CoreSession getReconnectedCoreSession(String repoName, String originatingUsername) { if (reconnectedCoreSession == null) { try { loginCtx = Framework.login(); } catch (LoginException e) { log.error("Cannot log in", e); return null; } reconnectedCoreSession = CoreInstance.openCoreSessionSystem(repoName, originatingUsername); } else { // Sanity Check if (!reconnectedCoreSession.getRepositoryName().equals(repoName)) { if (repoName != null) { throw new IllegalStateException("Can no reconnected a Bundle tied to several Core instances !"); } } } return reconnectedCoreSession; }
@Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) throws CommentSecurityException { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel createdComment = internalCreateComment(session, docModel, comment, path); session.save(); return createdComment; } }
return null; try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(repo)) { Map<DocumentRef, List<LogEntry>> docLogs = new HashMap<DocumentRef, List<LogEntry>>();
@Override public DocumentModel createComment(DocumentModel docModel, String comment, String author) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel commentDM = session.createDocumentModel(COMMENT_DOC_TYPE); commentDM.setPropertyValue(CommentsConstants.COMMENT_TEXT, comment); commentDM.setPropertyValue(CommentsConstants.COMMENT_AUTHOR, author); commentDM.setPropertyValue(CommentsConstants.COMMENT_CREATION_DATE, Calendar.getInstance()); commentDM = internalCreateComment(session, docModel, commentDM, null); session.save(); return commentDM; } }
return null; try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(repo)) { RelationManager relManager = getRelationManager(); Graph graph = relManager.getGraphByName(graphName);
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel comment) throws CommentSecurityException { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { comment.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(session, docModel.getId())); DocumentModel doc = internalCreateComment(session, docModel, comment, null); session.save(); doc.detach(true); return doc; } }
@Override public void deleteComment(DocumentModel docModel, DocumentModel comment) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentRef ref = comment.getRef(); if (!session.exists(ref)) { throw new NuxeoException("Comment Document does not exist: " + comment.getId()); } session.removeDocument(ref); notifyEvent(session, CommentEvents.COMMENT_REMOVED, docModel, comment); session.save(); } }
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel parent, DocumentModel child) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel parentDocModel = session.getDocument(parent.getRef()); String containerPath = parent.getPath().removeLastSegments(1).toString(); DocumentModel newComment = internalCreateComment(session, parentDocModel, child, containerPath); session.save(); return newComment; } }
sessionSystem = CoreInstance.openCoreSessionSystem(doc.getRepositoryName());
return resources; try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(repo)) { IORelationResources relResources = (IORelationResources) resources; Map<String, String> namespaces = relResources.getNamespaces();
DocumentReader reader = null; DocumentWriter writer = null; try (CloseableCoreSession coreSession = CoreInstance.openCoreSessionSystem(repo)) { DocumentPipe pipe = new DocumentPipeImpl(10);
@Override public DocumentTranslationMap importDocuments(InputStream in, String repo, DocumentRef root) { DocumentReader reader = null; DocumentModelWriter writer = null; try (CloseableCoreSession coreSession = CoreInstance.openCoreSessionSystem(repo)) { final DocumentModel dst = coreSession.getDocument(root); reader = new NuxeoArchiveReader(in); writer = new DocumentModelWriter(coreSession, dst.getPathAsString()); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); DocumentTranslationMap map = pipe.run(); coreSession.save(); return map; } catch (IOException e) { throw new NuxeoException(e); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } }
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel commentModel) throws CommentSecurityException { NuxeoPrincipal principal = commentModel.getCoreSession().getPrincipal(); // Open a session as system user since the parent document model can be a comment try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentRef docRef = getAncestorRef(session, docModel); if (!session.hasPermission(principal, docRef, SecurityConstants.READ)) { throw new CommentSecurityException( "The user " + principal.getName() + " can not create comments on document " + docModel.getId()); } String path = getCommentContainerPath(session, docModel.getId()); DocumentModel commentModelToCreate = session.createDocumentModel(path, COMMENT_NAME, commentModel.getType()); commentModelToCreate.copyContent(commentModel); commentModelToCreate.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(session, docModel.getId())); DocumentModel comment = session.createDocument(commentModelToCreate); comment.detach(true); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, comment); return comment; } }