use of uk.ac.ebi.spot.goci.model.deposition.Submission 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;
}
use of uk.ac.ebi.spot.goci.model.deposition.Submission in project goci by EBISPOT.
the class SubmissionController method buildSubmission.
private Submission buildSubmission(DepositionSubmission depositionSubmission) {
Submission testSub = new Submission();
testSub.setId(depositionSubmission.getSubmissionId());
testSub.setImportStatus(Submission.ImportStatus.NOT_READY);
if (depositionSubmission.getPublication() != null) {
testSub.setPubMedID(depositionSubmission.getPublication().getPmid());
testSub.setAuthor(depositionSubmission.getPublication().getFirstAuthor());
testSub.setCurator(depositionSubmission.getCreated().getUser().getName());
testSub.setStatus(depositionSubmission.getStatus());
testSub.setTitle(depositionSubmission.getPublication().getTitle());
testSub.setJournal(depositionSubmission.getPublication().getJournal());
testSub.setCreated(depositionSubmission.getCreated().getTimestamp().toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
testSub.setPublicationStatus(depositionSubmission.getPublication().getStatus());
testSub.setSubmissionType(DepositionUtil.getSubmissionType(depositionSubmission));
testSub.setPublicationDate(depositionSubmission.getPublication().getPublicationDate());
if (depositionSubmission.getPublication().getCorrespondingAuthor() != null) {
DepositionAuthor author = depositionSubmission.getPublication().getCorrespondingAuthor();
if (author.getGroup() != null) {
testSub.setCorrespondingAuthor(author.getGroup());
} else {
testSub.setCorrespondingAuthor(author.getFirstName() + ' ' + author.getLastName());
}
}
if (testSub.getSubmissionType().equals(Submission.SubmissionType.UNKNOWN)) {
testSub.setStatus("REVIEW");
}
} else if (depositionSubmission.getBodyOfWork() != null) {
if (depositionSubmission.getBodyOfWork().getFirstAuthor() != null) {
if (depositionSubmission.getBodyOfWork().getFirstAuthor().getGroup() != null) {
testSub.setAuthor(depositionSubmission.getBodyOfWork().getFirstAuthor().getGroup());
} else {
testSub.setAuthor(depositionSubmission.getBodyOfWork().getFirstAuthor().getFirstName() + ' ' + depositionSubmission.getBodyOfWork().getFirstAuthor().getLastName());
}
}
if (depositionSubmission.getBodyOfWork().getCorrespondingAuthors() != null) {
DepositionAuthor author = depositionSubmission.getBodyOfWork().getCorrespondingAuthors().get(0);
if (author.getGroup() != null) {
testSub.setCorrespondingAuthor(author.getGroup());
} else {
testSub.setCorrespondingAuthor(author.getFirstName() + ' ' + author.getLastName());
}
}
testSub.setStatus(depositionSubmission.getStatus());
testSub.setTitle(depositionSubmission.getBodyOfWork().getTitle());
testSub.setJournal(depositionSubmission.getBodyOfWork().getJournal());
testSub.setCreated(depositionSubmission.getCreated().getTimestamp().toString(DateTimeFormat.forPattern("yyyy-MM-dd")));
testSub.setPublicationStatus(depositionSubmission.getBodyOfWork().getStatus());
testSub.setSubmissionType(DepositionUtil.getSubmissionType(depositionSubmission));
if (testSub.getSubmissionType().equals(Submission.SubmissionType.UNKNOWN)) {
testSub.setStatus("REVIEW");
}
}
boolean importInProgress = submissionImportProgressService.importInProgress(depositionSubmission.getSubmissionId());
if (importInProgress) {
testSub.setStatus("IMPORT_IN_PROGRESS");
}
if (testSub.getStatus().equalsIgnoreCase("SUBMITTED") && !testSub.getSubmissionType().equals(Submission.SubmissionType.PRE_PUBLISHED) && !testSub.getSubmissionType().equals(Submission.SubmissionType.UNKNOWN)) {
testSub.setImportStatus(Submission.ImportStatus.READY);
}
return testSub;
}
use of uk.ac.ebi.spot.goci.model.deposition.Submission 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;
}
use of uk.ac.ebi.spot.goci.model.deposition.Submission in project goci by EBISPOT.
the class SubmissionController method viewSubmission.
@RequestMapping(value = "/{submissionId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET)
public String viewSubmission(Model model, @PathVariable String submissionId) {
DepositionSubmission depositionSubmission = submissionService.getSubmission(submissionId);
Submission submission = buildSubmission(depositionSubmission);
model.addAttribute("submission", submission);
model.addAttribute("submissionData", depositionSubmission);
model.addAttribute("submissionError", submissionService.checkSubmissionErrors(depositionSubmission));
try {
model.addAttribute("submissionString", mapper.writeValueAsString(depositionSubmission));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return "single_submission";
}
use of uk.ac.ebi.spot.goci.model.deposition.Submission in project goci by EBISPOT.
the class DepositionSubmissionImportService method importSubmission.
@Async
@Transactional
public void importSubmission(DepositionSubmission depositionSubmission, SecureUser currentUser, Long submissionImportId) {
ImportLog importLog = new ImportLog();
getLog().info("Evaluating submission type for: {}", depositionSubmission.getSubmissionId());
Submission.SubmissionType submissionType = DepositionUtil.getSubmissionType(depositionSubmission);
getLog().info("Found submission type for: {}", submissionType.name());
Curator curator = curatorRepository.findByEmail(currentUser.getEmail());
String submissionID = depositionSubmission.getSubmissionId();
getLog().info("[{}] Retrieving publication: {}", submissionID, depositionSubmission.getPublication().getPmid());
Publication publication = publicationService.findByPumedId(depositionSubmission.getPublication().getPmid());
getLog().info("[{}] Found publication: {}", submissionID, publication.getPubmedId());
getLog().info("[{}] Looking for studies in the local DB ...", submissionID);
Collection<Study> dbStudies = studyService.findByPublication(depositionSubmission.getPublication().getPmid());
List<Long> dbStudyIds = dbStudies.stream().map(Study::getId).collect(Collectors.toList());
getLog().info("[{}] Found {} studies: {}", submissionID, dbStudies.size(), dbStudyIds);
List<DepositionStudyDto> studies = depositionSubmission.getStudies();
List<String> gcsts = studies.stream().map(DepositionStudyDto::getAccession).collect(Collectors.toList());
getLog().info("[{}] Found {} studies in the submission retrieved from the Deposition App: {}", submissionID, studies.size(), gcsts);
boolean outcome = true;
if (submissionType == Submission.SubmissionType.SUM_STATS) {
// if submission type is SUM_STATS only
getLog().info("[{}] Found SUM_STATS submission.", submissionID, studies.size());
ImportLogStep importStep = importLog.addStep(new ImportLogStep("Publishing summary stats", submissionID));
Pair<Boolean, List<String>> result = depositionStudyService.publishSummaryStats(studies, dbStudies);
if (result.getLeft()) {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
importLog.addErrors(result.getRight(), "Publishing summary stats");
importStep = importLog.addStep(new ImportLogStep("Updating submission status: CURATION_COMPLETE", submissionID));
String stepOutcome = ingestService.updateSubmissionStatus(depositionSubmission, "CURATION_COMPLETE", "PUBLISHED_WITH_SS");
if (stepOutcome != null) {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
importLog.addWarning(stepOutcome, "Updating submission status: CURATION_COMPLETE");
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
}
} else {
importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
importLog.addErrors(result.getRight(), "Publishing summary stats");
outcome = false;
}
} else {
ImportLogStep studiesStep = importLog.addStep(new ImportLogStep("Verifying studies", submissionID));
if (studies != null) {
// && dbStudies.size() == 1) { //only do this for un-curated publications
importLog.updateStatus(studiesStep.getId(), ImportLog.SUCCESS);
getLog().info("[{}] Validating associations ...", submissionID);
ImportLogStep importStep = importLog.addStep(new ImportLogStep("Validating associations", submissionID));
for (DepositionStudyDto studyDto : studies) {
List<DepositionAssociationDto> associations = depositionSubmission.getAssociations();
if (associations != null) {
List<String> errors = associationValidationService.validateAssociations(studyDto.getStudyTag(), studyDto.getAccession(), associations);
importLog.addWarnings(errors, "Validating associations");
}
}
getLog().info("[{}] Associations validated. Found {} errors and {} warnings.", submissionID, importLog.getErrorList().size(), importLog.getWarnings().size());
if (!importLog.getErrorList().isEmpty()) {
importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
outcome = false;
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
getLog().info("[{}] Deleting proxy studies created when the publication was initially imported.", submissionID);
importStep = importLog.addStep(new ImportLogStep("Deleting proxy studies", submissionID));
String result = depositionStudyService.deleteStudies(dbStudies, curator, currentUser);
if (result != null) {
importLog.addError(result, "Deleting proxy studies");
importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
outcome = false;
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
}
if (outcome) {
outcome = studiesProcessingService.processStudies(depositionSubmission, currentUser, publication, curator, importLog);
if (outcome) {
getLog().info("[{}] Deleting unpublished studies and body of works.", submissionID);
importStep = importLog.addStep(new ImportLogStep("Deleting unpublished data", submissionID));
result = cleanupPrePublishedStudies(studies);
if (result != null) {
importLog.addWarning(result, "Deleting unpublished data");
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
}
importStep = importLog.addStep(new ImportLogStep("Updating submission status: CURATION_COMPLETE", submissionID));
result = ingestService.updateSubmissionStatus(depositionSubmission, "CURATION_COMPLETE", "CURATION_STARTED");
if (result != null) {
importLog.addWarning(result, "Updating submission status: CURATION_COMPLETE");
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS_WITH_WARNINGS);
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
}
}
}
}
} else {
importLog.updateStatus(studiesStep.getId(), ImportLog.FAIL);
importLog.addError("Submission [" + submissionID + "] has no studies", "Verifying studies");
outcome = false;
}
}
if (outcome) {
if (depositionSubmission.getPublication().getCorrespondingAuthor() != null) {
getLog().info("Creating Publication extensions for corresponding authors ...");
PublicationExtension author = new PublicationExtension();
author.setCorrespondingAuthorEmail(depositionSubmission.getPublication().getCorrespondingAuthor().getEmail());
if (depositionSubmission.getPublication().getCorrespondingAuthor().getGroup() != null) {
author.setCorrespondingAuthorName(depositionSubmission.getPublication().getCorrespondingAuthor().getGroup());
} else {
author.setCorrespondingAuthorName(depositionSubmission.getPublication().getCorrespondingAuthor().getFirstName() + ' ' + depositionSubmission.getPublication().getCorrespondingAuthor().getLastName());
}
publicationExtensionRepository.save(author);
getLog().info("Publication extension created: {}", author.getId());
List<PublicationExtension> authorList = new ArrayList<>();
authorList.add(author);
publication.setCorrespondingAuthors(authorList);
publicationService.save(publication);
getLog().info("Publication [{}] saved.", publication.getPubmedId());
}
} else {
ImportLogStep importStep = importLog.addStep(new ImportLogStep("Updating submission status: IMPORT_FAILED", submissionID));
String stepOutcome = ingestService.updateSubmissionStatus(depositionSubmission, "IMPORT_FAILED", "");
if (stepOutcome != null) {
importLog.updateStatus(importStep.getId(), ImportLog.FAIL);
importLog.addError(stepOutcome, "Updating submission status: IMPORT_FAILED");
} else {
importLog.updateStatus(importStep.getId(), ImportLog.SUCCESS);
}
}
mailService.sendSubmissionImportNotification(outcome, depositionSubmission.getPublication().getPmid(), submissionID, importLog, currentUser.getEmail());
getLog().info("Import process finalized: {}", depositionSubmission.getSubmissionId());
getLog().info(importLog.pretty(false));
submissionImportProgressService.deleteImport(submissionImportId);
}
Aggregations