public void addNote( final String canonicalName, Note currentNote, AssessmentData assessment, GenericCallback<String> callback) { if (!AuthorizationCache.impl.hasRight( SimpleSISClient.currentUser, AuthorizableObject.WRITE, assessment)) { WindowUtils.errorAlert( "You do not have sufficient permissions to perform " + "this operation."); return; } NativeDocument doc = SimpleSISClient.getHttpBasicNativeDocument(); String type = assessment.getType(); String url = "/notes/" + type; url += "/" + assessment.getAssessmentID(); url += "/" + canonicalName; if (type.equals(BaseAssessment.USER_ASSESSMENT_STATUS)) url += "/" + currentNote.getUser(); addNoteToCache(canonicalName, currentNote, assessment); doc.post(url, currentNote.toXML(), callback); }
public void fetchNotes(final AssessmentData assessment, final GenericCallback<String> callback) { if (!noteMap.containsKey(getNoteMapID(assessment))) { final NativeDocument ndoc = SimpleSISClient.getHttpBasicNativeDocument(); ndoc.get( "/notes/" + assessment.getType() + "/" + assessment.getAssessmentID(), new GenericCallback<String>() { public void onFailure(Throwable caught) { callback.onSuccess("OK"); } public void onSuccess(String result) { HashMap<String, ArrayList<Note>> assessNotes = new HashMap<String, ArrayList<Note>>(); NativeNodeList nodeList = ndoc.getDocumentElement().getElementsByTagName("notes"); for (int i = 0; i < nodeList.getLength(); i++) { NativeElement el = nodeList.elementAt(i); String canonicalName = el.getAttribute("id"); assessNotes.put(canonicalName, Note.notesFromXML(el)); } noteMap.put(getNoteMapID(assessment), assessNotes); callback.onSuccess(result); } }); } else callback.onSuccess("OK"); }
private String getNoteMapID(AssessmentData assessment) { return assessment.getAssessmentID() + assessment.getType(); }