use of uk.ac.ebi.spot.goci.curation.model.StudyNoteForm in project goci by EBISPOT.
the class StudyNoteOperationsService method generateSystemNoteForms.
public List<StudyNoteForm> generateSystemNoteForms(Collection<StudyNote> notes) {
List<StudyNoteForm> sysNoteForms = new ArrayList<StudyNoteForm>();
if (!notes.isEmpty()) {
filterSystemNote(notes).forEach(sysNote -> {
StudyNoteForm row = convertToStudyNoteForm(sysNote);
sysNoteForms.add(row);
});
}
return sysNoteForms;
}
use of uk.ac.ebi.spot.goci.curation.model.StudyNoteForm in project goci by EBISPOT.
the class StudyNoteOperationsService method generateNonSystemNoteForms.
public List<StudyNoteForm> generateNonSystemNoteForms(Collection<StudyNote> notes) {
List<StudyNoteForm> sysNoteForms = new ArrayList<StudyNoteForm>();
if (!notes.isEmpty()) {
filterNomalNote(notes).forEach(sysNote -> {
StudyNoteForm row = convertToStudyNoteForm(sysNote);
sysNoteForms.add(row);
});
}
return sysNoteForms;
}
use of uk.ac.ebi.spot.goci.curation.model.StudyNoteForm in project goci by EBISPOT.
the class StudyNoteController method saveNote.
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "saveNote" })
public String saveNote(@ModelAttribute("multiStudyNoteForm") @Valid MultiStudyNoteForm multiStudyNoteForm, BindingResult bindingResult, Model model, @PathVariable Long studyId, HttpServletRequest req) {
//Index of value to save
final Integer rowId = Integer.valueOf(req.getParameter("saveNote"));
//get the study
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
//the newly added note can only be assigned one of the availlable subject, not including system note subjects.
Collection<NoteSubject> noteSubjects = noteSubjectService.findNonSystemNoteSubject();
model.addAttribute("availableNoteSubject", noteSubjects);
//form validation
if (bindingResult.hasErrors()) {
//reload system notes because they are not part of the input
multiStudyNoteForm.setSystemNoteForms(studyNoteOperationsService.generateSystemNoteForms(study.getNotes()));
model.addAttribute("availableNoteSubject", noteSubjects);
model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
return "study_notes";
}
//convert studynoteform to studynote domain object and save
StudyNoteForm snf = multiStudyNoteForm.getNomalNoteForms().get(rowId.intValue());
StudyNote noteToEdit = studyNoteOperationsService.convertToStudyNote(snf, study);
SecureUser user = currentUserDetailsService.getUserFromRequest(req);
ErrorNotification notification = studyOperationsService.addStudyNote(study, noteToEdit, user);
if (!notification.hasErrors()) {
return "redirect:/studies/" + studyId + "/notes";
} else {
//deal with error
// we want to display the error to the user simply on top of the form
getLog().warn("Request: " + req.getRequestURL() + " raised an error." + notification.errorMessage());
model.addAttribute("errors", "Update FAIL! " + notification.errorMessage());
multiStudyNoteForm.setSystemNoteForms(studyNoteOperationsService.generateSystemNoteForms(study.getNotes()));
model.addAttribute("availableNoteSubject", noteSubjects);
model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
}
return "study_notes";
}
use of uk.ac.ebi.spot.goci.curation.model.StudyNoteForm in project goci by EBISPOT.
the class StudyNoteController method addNoteToTable.
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "addNote" })
public String addNoteToTable(Model model, @PathVariable Long studyId, HttpServletRequest request) {
//get the study
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
if (study.getHousekeeping().getIsPublished()) {
return "redirect:/studies/" + studyId + "/notes";
}
//the newly added note can only be assigned one of the availlable subject, not including system note subjects.
Collection<NoteSubject> noteSubjects = noteSubjectService.findNonSystemNoteSubject();
model.addAttribute("availableNoteSubject", noteSubjects);
// an form object mapped from the studyNote object, it contains a list of notes
MultiStudyNoteForm msnf = studyNoteOperationsService.generateMultiStudyNoteForm(study.getNotes(), study);
SecureUser user = currentUserDetailsService.getUserFromRequest(request);
//create a default study note with default setting
StudyNote emptyNote = studyNoteOperationsService.createGeneralNote(study, user);
StudyNoteForm emptyNoteForm = studyNoteOperationsService.convertToStudyNoteForm(emptyNote);
//attach the empty form
msnf.getNomalNoteForms().add(emptyNoteForm);
//Index of value to add
final Integer rowId = msnf.getNomalNoteForms().size() - 1;
//enable the edit for the new note and disable all edit for other notes
msnf.startEdit(rowId);
//reload system notes because they are not part of the input
msnf.setSystemNoteForms(studyNoteOperationsService.generateSystemNoteForms(study.getNotes()));
model.addAttribute("multiStudyNoteForm", msnf);
return "study_notes";
}
use of uk.ac.ebi.spot.goci.curation.model.StudyNoteForm in project goci by EBISPOT.
the class StudyNoteController method removeNote.
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "removeNote" })
public String removeNote(@ModelAttribute("multiStudyNoteForm") MultiStudyNoteForm multiStudyNoteForm, BindingResult bindingResult, Model model, @PathVariable Long studyId, HttpServletRequest req) {
//Index of value to remove
final Integer rowId = Integer.valueOf(req.getParameter("removeNote"));
//get the study
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
StudyNoteForm snf = multiStudyNoteForm.getNomalNoteForms().get(rowId.intValue());
StudyNote noteToRemove = studyNoteOperationsService.convertToStudyNote(snf, study);
//if not removing empty row
if (noteToRemove.getId() != null) {
ErrorNotification notification = studyOperationsService.deleteStudyNote(study, noteToRemove);
if (notification.hasErrors()) {
//we want to display the error to the user simply on top of the form
getLog().warn("Request: " + req.getRequestURL() + " raised an error." + notification.errorMessage());
model.addAttribute("errors", "Delete FAIL! " + notification.errorMessage());
Collection<NoteSubject> noteSubjects = noteSubjectService.findNonSystemNoteSubject();
model.addAttribute("availableNoteSubject", noteSubjects);
model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
return "study_notes";
} else {
return "redirect:/studies/" + studyId + "/notes";
}
}
return "redirect:/studies/" + studyId + "/notes";
}
Aggregations