Search in sources :

Example 1 with SubmissionImportProgress

use of uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress 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 2 with SubmissionImportProgress

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

the class SubmissionImportProgressService method getSubmissions.

public List<String> getSubmissions() {
    List<SubmissionImportProgress> submissionImportProgresses = submissionImportProgressRepository.findAll();
    List<String> ids = new ArrayList<>();
    for (SubmissionImportProgress submissionImportProgress : submissionImportProgresses) {
        ids.add(submissionImportProgress.getSubmissionId());
    }
    return ids;
}
Also used : ArrayList(java.util.ArrayList) SubmissionImportProgress(uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress)

Example 3 with SubmissionImportProgress

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

the class SubmissionImportProgressService method createNewImport.

public SubmissionImportProgress createNewImport(String userEmail, String submissionId) {
    log.info("Creating new import for [{}]: {}", submissionId, userEmail);
    SubmissionImportProgress submissionImportProgress = new SubmissionImportProgress(null, Calendar.getInstance().getTime(), submissionId, userEmail);
    submissionImportProgress = submissionImportProgressRepository.save(submissionImportProgress);
    log.info("Import progress created: {}", submissionImportProgress.getId());
    return submissionImportProgress;
}
Also used : SubmissionImportProgress(uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress)

Aggregations

SubmissionImportProgress (uk.ac.ebi.spot.goci.model.deposition.SubmissionImportProgress)3 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SecureUser (uk.ac.ebi.spot.goci.model.SecureUser)1 DepositionSubmission (uk.ac.ebi.spot.goci.model.deposition.DepositionSubmission)1 Submission (uk.ac.ebi.spot.goci.model.deposition.Submission)1