Search in sources :

Example 1 with SecureUser

use of uk.ac.ebi.spot.goci.model.SecureUser in project goci by EBISPOT.

the class StudyNoteController method viewStudyNotes.

@RequestMapping(value = "/studies/{studyId}/notes", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewStudyNotes(Model model, @PathVariable Long studyId, HttpServletRequest request) {
    // get the study
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    SecureUser user = currentUserDetailsService.getUserFromRequest(request);
    // an form object mapped from the studyNote object, it contains a list of notes
    MultiStudyNoteForm msnf = studyNoteOperationsService.generateMultiStudyNoteForm(study.getNotes(), study, user);
    model.addAttribute("multiStudyNoteForm", msnf);
    return "study_notes";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SecureUser

use of uk.ac.ebi.spot.goci.model.SecureUser in project goci by EBISPOT.

the class StudyNoteController method enableEditNote.

// This will enable save/remove button for a study note and disable all other action for other notes
@RequestMapping(value = "/studies/{studyId}/notes", method = RequestMethod.POST, params = { "editNote" })
public String enableEditNote(Model model, @PathVariable Long studyId, HttpServletRequest req) {
    // Index of value to remove
    final Integer rowId = Integer.valueOf(req.getParameter("editNote"));
    // get the study
    Study study = studyRepository.findOne(studyId);
    model.addAttribute("study", study);
    // get All note subjects for dropdown
    // remove subjects including 'Imported from previous system' 'SystemNote'
    Collection<NoteSubject> noteSubjects = noteSubjectService.findAvailableNoteSubjectForStudy(study);
    model.addAttribute("availableNoteSubject", noteSubjects);
    SecureUser user = currentUserDetailsService.getUserFromRequest(req);
    // an form object mapped from the studyNote object, it contains a list of notes
    MultiStudyNoteForm msnf = studyNoteOperationsService.generateMultiStudyNoteForm(study.getNotes(), study, user);
    // enable the edit for the note and disable all edit for other notes
    msnf.startEdit(rowId);
    model.addAttribute("multiStudyNoteForm", msnf);
    return "study_notes";
}
Also used : Study(uk.ac.ebi.spot.goci.model.Study) NoteSubject(uk.ac.ebi.spot.goci.model.NoteSubject) MultiStudyNoteForm(uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with SecureUser

use of uk.ac.ebi.spot.goci.model.SecureUser in project goci by EBISPOT.

the class SubmissionController method importSubmission.

@CrossOrigin
@RequestMapping(value = "/{submissionID}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String importSubmission(@PathVariable String submissionID, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
    List<String> statusMessages = new ArrayList<>();
    List<String> errorMessages = new ArrayList<>();
    try {
        Map<String, Submission> submissionList = submissionService.getSubmissions();
        DepositionSubmission depositionSubmission = submissionService.getSubmission(submissionID);
        SecureUser currentUser = currentUserDetailsService.getUserFromRequest(request);
        boolean importInProgress = submissionImportProgressService.importInProgress(depositionSubmission.getSubmissionId());
        if (importInProgress) {
            statusMessages = Arrays.asList(new String[] { "Import is already in progress. Please wait." });
        } else {
            SubmissionImportProgress submissionImportProgress = submissionImportProgressService.createNewImport(currentUser.getEmail(), depositionSubmission.getSubmissionId());
            depositionSubmissionImportService.importSubmission(depositionSubmission, currentUser, submissionImportProgress.getId());
            statusMessages = Arrays.asList(new String[] { "Import task has been submitted. You will receive an email when it's done." });
        }
        model.addAttribute("submissions", submissionList.values());
    } catch (Exception e) {
        e.printStackTrace();
        StringWriter stringWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(stringWriter));
        errorMessages.add(stringWriter.getBuffer().toString());
    }
    redirectAttributes.addFlashAttribute("errors", String.join("<br>", errorMessages));
    redirectAttributes.addFlashAttribute("changesSaved", String.join("<br>", statusMessages));
    return "redirect:/submissions/" + submissionID;
}
Also used : DepositionSubmission(uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission) Submission(uk.ac.ebi.spot.goci.model.deposition.Submission) DepositionSubmission(uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) SubmissionImportProgress(uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) PrintWriter(java.io.PrintWriter)

Example 4 with SecureUser

use of uk.ac.ebi.spot.goci.model.SecureUser in project goci by EBISPOT.

the class SubmissionController method updateSubmission.

@CrossOrigin
@RequestMapping(value = "/update/{submissionID}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.PUT)
public ResponseEntity<Submission> updateSubmission(@PathVariable String submissionID, @ModelAttribute Submission submission, Model model, HttpServletRequest request) {
    SecureUser currentUser = currentUserDetailsService.getUserFromRequest(request);
    submission = submissionService.updateSubmission(submission, currentUser);
    ResponseEntity<Submission> response = new ResponseEntity<>(submission, HttpStatus.OK);
    return response;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Submission(uk.ac.ebi.spot.goci.model.deposition.Submission) DepositionSubmission(uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser)

Example 5 with SecureUser

use of uk.ac.ebi.spot.goci.model.SecureUser in project goci by EBISPOT.

the class AssociationUploadService method upload.

@Transactional(readOnly = false)
public List<AssociationUploadErrorView> upload(MultipartFile file, Study study, SecureUser user) throws IOException, EnsemblMappingException {
    int s = study.getEvents().size();
    if (s > 0) {
        getLog().trace("Study " + study.getId().toString() + " has " + s + " events");
    }
    // File errors will contain any validation errors and be returned to controller if any are found
    List<AssociationUploadErrorView> fileErrors = new ArrayList<>();
    String originalFilename = file.getOriginalFilename();
    getLog().info("Uploading file: ".concat(originalFilename));
    // Upload file
    try {
        uploadFile(file, study.getId());
        // Send file, including path, to SNP batch loader process
        File uploadedFile = studyFileService.getFileFromFileName(study.getId(), originalFilename);
        ValidationSummary validationSummary = associationFileUploadService.processAndValidateAssociationFile(uploadedFile, "full");
        if (validationSummary != null) {
            // Check if we have any row errors
            long rowErrorCount = validationSummary.getRowValidationSummaries().parallelStream().filter(rowValidationSummary -> !rowValidationSummary.getErrors().isEmpty()).count();
            // Errors found
            if (rowErrorCount > 0) {
                studyFileService.deleteFile(study.getId(), originalFilename);
                getLog().error("Row errors found in file: " + originalFilename);
                validationSummary.getRowValidationSummaries().forEach(rowValidationSummary -> fileErrors.addAll(processRowError(rowValidationSummary)));
            } else {
                // Determine if we have any errors rather than warnings
                // Errors prevent saving association
                List<ValidationError> allAssociationsErrors = new ArrayList<>();
                validationSummary.getAssociationSummaries().forEach(associationSummary -> allAssociationsErrors.addAll(associationSummary.getErrors()));
                long associationErrorCount = allAssociationsErrors.parallelStream().filter(validationError -> !validationError.getWarning()).count();
                if (associationErrorCount > 0) {
                    studyFileService.deleteFile(study.getId(), originalFilename);
                    getLog().error("Association errors found in file: " + originalFilename);
                    validationSummary.getAssociationSummaries().forEach(associationSummary -> fileErrors.addAll(processAssociationError(associationSummary)));
                } else {
                    Integer numberOfAssociations = validationSummary.getAssociationSummaries().size();
                    String description = numberOfAssociations.toString().concat(" associations created from upload of '").concat(originalFilename).concat("'");
                    createBatchUploadEvent(study, description, user);
                    saveAssociations(validationSummary.getAssociationSummaries(), study, user);
                }
            }
        }
        return fileErrors;
    } catch (IOException e) {
        throw new IOException(e);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StudyRepository(uk.ac.ebi.spot.goci.repository.StudyRepository) AssociationFileUploadService(uk.ac.ebi.spot.goci.service.AssociationFileUploadService) SecureUser(uk.ac.ebi.spot.goci.model.SecureUser) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Collection(java.util.Collection) EnsemblMappingException(uk.ac.ebi.spot.goci.exception.EnsemblMappingException) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) IOException(java.io.IOException) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) File(java.io.File) TrackingOperationService(uk.ac.ebi.spot.goci.service.TrackingOperationService) List(java.util.List) Association(uk.ac.ebi.spot.goci.model.Association) MultipartFile(org.springframework.web.multipart.MultipartFile) Study(uk.ac.ebi.spot.goci.model.Study) AssociationSummary(uk.ac.ebi.spot.goci.model.AssociationSummary) Transactional(org.springframework.transaction.annotation.Transactional) ValidationSummary(uk.ac.ebi.spot.goci.model.ValidationSummary) RowValidationSummary(uk.ac.ebi.spot.goci.model.RowValidationSummary) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AssociationUploadErrorView(uk.ac.ebi.spot.goci.curation.model.AssociationUploadErrorView) ValidationError(uk.ac.ebi.spot.goci.model.ValidationError) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)9 Study (uk.ac.ebi.spot.goci.model.Study)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 MultiStudyNoteForm (uk.ac.ebi.spot.goci.curation.model.MultiStudyNoteForm)4 NoteSubject (uk.ac.ebi.spot.goci.model.NoteSubject)3 ArrayList (java.util.ArrayList)2 StudyNoteForm (uk.ac.ebi.spot.goci.curation.model.StudyNoteForm)2 ErrorNotification (uk.ac.ebi.spot.goci.curation.model.errors.ErrorNotification)2 EnsemblMappingException (uk.ac.ebi.spot.goci.exception.EnsemblMappingException)2 Association (uk.ac.ebi.spot.goci.model.Association)2 StudyNote (uk.ac.ebi.spot.goci.model.StudyNote)2 DepositionSubmission (uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission)2 Submission (uk.ac.ebi.spot.goci.model.deposition.Submission)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1