public final void dispose() { try { if (session != null) { try { session.save(); } finally { session.close(); } } } finally { try { session = null; lc.logout(); lc = null; } catch (LoginException e) { log.error(e); // don't rethrow inside finally } } } }
@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; } }
@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; } }
@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 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; } }
@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 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(); } } }