Skip to content
Snippets Groups Projects
Commit ed1a9a88 authored by srosse's avatar srosse
Browse files

OO-1317: allow concurrent editing of the same note

parent 9a1c0af4
No related branches found
No related tags found
No related merge requests found
......@@ -37,18 +37,18 @@ import org.olat.core.id.Persistable;
* @author Alexander Schneider
*/
public interface Note extends CreateInfo, ModifiedInfo, Persistable {
public abstract Identity getOwner();
public abstract String getResourceTypeName();
public abstract Long getResourceTypeId();
public abstract String getSubtype();
public abstract String getNoteTitle();
public abstract String getNoteText();
public Identity getOwner();
public String getResourceTypeName();
public Long getResourceTypeId();
public String getSubtype();
public String getNoteTitle();
public String getNoteText();
public abstract void setOwner(Identity identity);
public abstract void setResourceTypeName(String resourceTypeName);
public abstract void setResourceTypeId(Long resourceTypeId);
public abstract void setSubtype(String subtype);
public abstract void setNoteTitle(String nodeTitle);
public abstract void setNoteText(String noteText);
public void setOwner(Identity identity);
public void setResourceTypeName(String resourceTypeName);
public void setResourceTypeId(Long resourceTypeId);
public void setSubtype(String subtype);
public void setNoteTitle(String nodeTitle);
public void setNoteText(String noteText);
}
\ No newline at end of file
......@@ -66,7 +66,7 @@ public class NoteController extends FormBasicController implements GenericEventL
private FormSubmit submitButton;
@Autowired
private NoteManager nm;
private NoteManager noteManager;
/**
* @param ureq
......@@ -101,7 +101,7 @@ public class NoteController extends FormBasicController implements GenericEventL
private void init(UserRequest ureq, String resourceTypeName, Long resourceTypeId, String noteTitle) {
Identity owner = ureq.getIdentity();
n = nm.loadNoteOrCreateInRAM(owner, resourceTypeName, resourceTypeId);
n = noteManager.loadNoteOrCreateInRAM(owner, resourceTypeName, resourceTypeId);
n.setNoteTitle(noteTitle);
// register for local event (for the same user), is used to dispose
......@@ -138,12 +138,12 @@ public class NoteController extends FormBasicController implements GenericEventL
private void createOrUpdateNote(String content) {
n.setNoteText(content);
if (n.getKey() == null) {
nm.saveNote(n);
noteManager.saveNote(n);
Long newKey = n.getKey();
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Note.class, newKey);
sec.fireEventToListenersOf(new NoteEvent(getIdentity().getKey()), ores);
} else {
nm.updateNote(n);
n = noteManager.updateNote(n);
}
}
......@@ -192,9 +192,9 @@ public class NoteController extends FormBasicController implements GenericEventL
createOrUpdateNote(text);
// ...and then hide the submit button, show the edit button, and make the field disabled (i.e. display-only) again.
this.submitButton.setVisible(false);
this.editButton.setVisible(true);
this.noteField.setEnabled(false);
submitButton.setVisible(false);
editButton.setVisible(true);
noteField.setEnabled(false);
}
/**
......@@ -207,10 +207,10 @@ public class NoteController extends FormBasicController implements GenericEventL
// persisting: see formOK
// If the user clicked the edit button, set the rich text input field to enabled and hide the edit button.
if ((source == this.editButton) && (this.editButton.isEnabled())) {
this.noteField.setEnabled(true);
this.editButton.setVisible(false);
this.submitButton.setVisible(true);
if ((source == editButton) && (editButton.isEnabled())) {
noteField.setEnabled(true);
editButton.setVisible(false);
submitButton.setVisible(true);
// this is to force the redraw of the form so that the submit button gets shown:
flc.setDirty(true);
......@@ -218,8 +218,7 @@ public class NoteController extends FormBasicController implements GenericEventL
// since clicking the edit button is registered as a change on the form, the submit button would get orange,
// so we need the following line to set the form back to unchanged since at this point, the user has not
// yet really changed anything.
this.mainForm.setDirtyMarking(false);
mainForm.setDirtyMarking(false);
}
}
}
\ No newline at end of file
......@@ -139,8 +139,13 @@ public class NoteManager implements UserDataDeletable {
* @param n
*/
public Note updateNote(Note n) {
n.setLastModified(new Date());
Note mergedNote = dbInstance.getCurrentEntityManager().merge(n);
Note reloadedNote = dbInstance.getCurrentEntityManager()
.find(NoteImpl.class, n.getKey());
reloadedNote.setLastModified(new Date());
reloadedNote.setNoteTitle(n.getNoteTitle());
reloadedNote.setNoteText(n.getNoteText());
Note mergedNote = dbInstance.getCurrentEntityManager().merge(reloadedNote);
fireBookmarkEvent(n.getOwner());
return mergedNote;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment