public static void ajaxEditDocument(Long documentId, String newTitle, String newContent) { Document document = Document.findById(documentId); document.changeSubject(newTitle); Config config = Config.getInstance(); User currentUser = User.findById(config.getSingedInUserId()); Version newVersion = new Version(currentUser, document, newContent).save(); System.out.println("* A new version is successfully created."); document.addVersion(newVersion); document.save(); }
/* * Create a document and save using Ajax */ public static void ajaxCreateDocument(String subject, String content, Long parentId) { /* * Create a document and save * Create first version of the document * Create permalink of that version */ // By creating a document, I assume that the document is created by the // program, and versions in the document are created by users // Create a new document for current user, current user is defined in Config Document document = new Document(subject, parentId).save(); System.out.println("* A new document is successfully created."); Config config = Config.getInstance(); User currentUser = User.findById(config.getSingedInUserId()); Version aversion = new Version(currentUser, document, content).save(); System.out.println("* A new version is successfully created."); document.addVersion(aversion); Documents.ajaxAllDocuments(); }