Search in sources :

Example 1 with ErrorNotification

use of uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification in project goci by EBISPOT.

the class StudyOperationsService method addStudyNote.

public ErrorNotification addStudyNote(Study study, StudyNote studyNote, SecureUser user) {
    ErrorNotification notification = new ErrorNotification();
    // xintodo need to refactor after removing curator table
    Curator curator = curatorService.getCuratorIdByEmail(user.getEmail());
    studyNote.setCurator(curator);
    // user cannot touch system notes
    if (studyNoteOperationsService.isSystemNote(studyNote)) {
        notification.addError(new NoteIsLockedError());
    }
    if (!notification.hasErrors()) {
        studyNoteService.saveStudyNote(studyNote);
    }
    return notification;
}
Also used : NoteIsLockedError(uk.ac.ebi.spot.goci.curation.model.errors.NoteIsLockedError) ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification)

Example 2 with ErrorNotification

use of uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification in project goci by EBISPOT.

the class StudyOperationsService method duplicateStudyNoteToSiblingStudies.

public ErrorNotification duplicateStudyNoteToSiblingStudies(Study sourceStudy, Long nodeId, SecureUser user) {
    // find all studies with the same pubmed id
    // THOR
    Collection<Study> studies = publicationService.findStudiesByPubmedId(sourceStudy.getPublicationId().getPubmedId());
    // remove the source study
    studies = studies.stream().filter(targetStudy -> sourceStudy.getId() != targetStudy.getId()).collect(Collectors.toList());
    // find the note
    StudyNote noteToCopy = studyNoteService.findOne(nodeId);
    ErrorNotification notification = new ErrorNotification();
    // copy note to studies
    studies.stream().forEach(targetStudy -> {
        ErrorNotification en = addStudyNote(targetStudy, studyNoteOperationsService.duplicateNote(targetStudy, noteToCopy, user), user);
        if (en.hasErrors()) {
            notification.addError(en.getErrors());
        }
    });
    studyNoteOperationsService.updateDuplicatedNote(noteToCopy, user);
    return notification;
}
Also used : ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification)

Example 3 with ErrorNotification

use of uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification 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.findAvailableNoteSubjectForStudy(study);
    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";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) StudyNoteForm(uk.ac.ebi.spot.goci.curation.model.StudyNoteForm) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) NoteSubject(uk.ac.ebi.spot.goci.model.NoteSubject) StudyNote(uk.ac.ebi.spot.goci.model.StudyNote) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ErrorNotification

use of uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification 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.findAvailableNoteSubjectForStudy(study);
            model.addAttribute("availableNoteSubject", noteSubjects);
            model.addAttribute("multiStudyNoteForm", multiStudyNoteForm);
            return "study_notes";
        } else {
            return "redirect:/studies/" + studyId + "/notes";
        }
    }
    return "redirect:/studies/" + studyId + "/notes";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) StudyNoteForm(uk.ac.ebi.spot.goci.curation.model.StudyNoteForm) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) NoteSubject(uk.ac.ebi.spot.goci.model.NoteSubject) StudyNote(uk.ac.ebi.spot.goci.model.StudyNote) ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ErrorNotification

use of uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification in project goci by EBISPOT.

the class StudyNoteController method duplicateNoteAcrossPublication.

@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "duplicateNote" })
public String duplicateNoteAcrossPublication(Model model, @PathVariable Long studyId, HttpServletRequest req) {
    final Long noteId = Long.valueOf(req.getParameter("duplicateNote"));
    SecureUser user = currentUserDetailsService.getUserFromRequest(req);
    Study study = studyRepository.findOne(studyId);
    ErrorNotification notification = studyOperationsService.duplicateStudyNoteToSiblingStudies(study, noteId, user);
    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", "Duplicate FAIL! " + notification.errorMessage());
    // redirectAttributes.addFlashAttribute("errors", "Duplicate FAIL! " + notification.errorMessage());
    // req.setAttribute("errors", "Duplicate FAIL! " + notification.errorMessage());
    }
    return "redirect:/studies/" + studyId + "/notes";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) ErrorNotification(uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ErrorNotification (uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Study (uk.ac.ebi.spot.goci.model.Study)3 MultiStudyNoteForm (uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm)2 StudyNoteForm (uk.ac.ebi.spot.goci.curation.model.StudyNoteForm)2 NoteSubject (uk.ac.ebi.spot.goci.model.NoteSubject)2 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)2 StudyNote (uk.ac.ebi.spot.goci.model.StudyNote)2 NoteIsLockedError (uk.ac.ebi.spot.goci.curation.model.errors.NoteIsLockedError)1