Created
September 28, 2016 04:57
-
-
Save jongyoul/5723ce59bf5df4791ff8d9d6fd614c29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void runParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, | |
Message fromMessage) throws IOException { | |
final String paragraphId = (String) fromMessage.get("id"); | |
if (paragraphId == null) { | |
return; | |
} | |
String noteId = getOpenNoteId(conn); | |
final Note note = notebook.getNote(noteId); | |
NotebookAuthorization notebookAuthorization = notebook.getNotebookAuthorization(); | |
if (!notebookAuthorization.isWriter(noteId, userAndRoles)) { | |
permissionError(conn, "write", fromMessage.principal, | |
userAndRoles, notebookAuthorization.getWriters(noteId)); | |
return; | |
} | |
Paragraph p = note.getParagraph(paragraphId); | |
String text = (String) fromMessage.get("paragraph"); | |
p.setText(text); | |
p.setTitle((String) fromMessage.get("title")); | |
if (!fromMessage.principal.equals("anonymous")) { | |
AuthenticationInfo authenticationInfo = new AuthenticationInfo(fromMessage.principal, | |
fromMessage.ticket); | |
p.setAuthenticationInfo(authenticationInfo); | |
} else { | |
p.setAuthenticationInfo(new AuthenticationInfo()); | |
} | |
Map<String, Object> params = (Map<String, Object>) fromMessage | |
.get("params"); | |
p.settings.setParams(params); | |
Map<String, Object> config = (Map<String, Object>) fromMessage | |
.get("config"); | |
p.setConfig(config); | |
// if it's the last paragraph, let's add a new one | |
boolean isTheLastParagraph = note.isLastParagraph(p.getId()); | |
if (!(text.trim().equals(p.getMagic()) || Strings.isNullOrEmpty(text)) && | |
isTheLastParagraph) { | |
note.addParagraph(); | |
} | |
AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal); | |
note.persist(subject); | |
try { | |
note.run(paragraphId); | |
} catch (Exception ex) { | |
LOG.error("Exception from run", ex); | |
if (p != null) { | |
p.setReturn( | |
new InterpreterResult(InterpreterResult.Code.ERROR, ex.getMessage()), | |
ex); | |
p.setStatus(Status.ERROR); | |
broadcast(note.getId(), new Message(OP.PARAGRAPH).put("paragraph", p)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment