use of uk.ac.bbsrc.tgac.miso.core.data.Submission in project miso-lims by miso-lims.
the class EnaSubmissionPreparation method toBytes.
public byte[] toBytes() {
try (ByteArrayOutputStream outputBytes = new ByteArrayOutputStream()) {
ZipOutputStream output = new ZipOutputStream(outputBytes);
submission.setSubmissionDate(new Date());
Document submissionDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element s = submissionDocument.createElementNS(null, "SUBMISSION");
s.setAttribute("alias", submission.getAlias());
s.setAttribute("submission_date", DF_TIMESTAMP.format(submission.getSubmissionDate()));
s.setAttribute("submission_comment", submission.getDescription());
s.setAttribute("center_name", centreName);
Element title = submissionDocument.createElementNS(null, "TITLE");
title.setTextContent(submission.getTitle());
s.appendChild(title);
Element contacts = submissionDocument.createElementNS(null, "CONTACTS");
Stream.concat(Stream.of(user), submission.getExperiments().stream().map(experiment -> experiment.getCreator()).filter(Objects::nonNull)).map(User::getFullName).distinct().map(contactName -> {
Element contact = submissionDocument.createElementNS(null, "CONTACT");
contact.setAttribute("name", contactName);
return contact;
}).forEach(contacts::appendChild);
s.appendChild(contacts);
Element actions = submissionDocument.createElementNS(null, "ACTIONS");
for (ChildSubmissionFile subFile : FILES) {
subFile.generateDocument(output);
if (!subFile.isEmpty()) {
if (submissionAction == SubmissionActionType.ADD || submissionAction == SubmissionActionType.VALIDATE) {
Element action = submissionDocument.createElementNS(null, "ACTION");
Element validate = submissionDocument.createElementNS(null, submissionAction.name());
validate.setAttribute("schema", subFile.name());
validate.setAttribute("source", subFile.fileName());
action.appendChild(validate);
actions.appendChild(action);
}
}
}
s.appendChild(actions);
if (submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0) != null) {
submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0).appendChild(s);
} else {
Element submissionSet = submissionDocument.createElementNS(null, "SUBMISSION_SET");
submissionDocument.appendChild(submissionSet);
submissionSet.appendChild(s);
}
ZipEntry mainFile = new ZipEntry("SUBMISSON.xml");
output.putNextEntry(mainFile);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(output);
DOMSource source = new DOMSource(submissionDocument);
transformer.transform(source, result);
output.closeEntry();
output.close();
return outputBytes.toByteArray();
} catch (ParserConfigurationException | TransformerException | IOException e) {
throw new RuntimeException("Cannot generate data.");
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.Submission in project miso-lims by miso-lims.
the class SubmissionRestController method download.
@ResponseBody
@GetMapping(path = "/{submissionId}/download")
public byte[] download(@PathVariable("submissionId") Long submissionId, @QueryParam("action") String action, @QueryParam("centreName") String centreName, HttpServletResponse response) throws IOException {
Submission submission = submissionService.get(submissionId);
if (submission == null) {
throw new RestException("Submission not found", Status.NOT_FOUND);
}
User user = authorizationManager.getCurrentUser();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(new MediaType("application", "zip"));
response.setHeader("Content-Disposition", "attachment; filename=" + String.format("SUBMISSON%d-%s.zip", submission.getId(), new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
return new EnaSubmissionPreparation(submission, user, centreName, SubmissionActionType.valueOf(action)).toBytes();
}
use of uk.ac.bbsrc.tgac.miso.core.data.Submission in project miso-lims by miso-lims.
the class EditSubmissionController method newSubmission.
@GetMapping(value = "/new")
public ModelAndView newSubmission(@QueryParam("experimentIds") String experimentIds, ModelMap model) throws IOException {
Submission submission = new Submission();
submission.setExperiments(COMMA.splitAsStream(experimentIds).map(Long::parseLong).map(WhineyFunction.rethrow(experimentService::get)).collect(Collectors.toSet()));
submission.setCreationDate(new Date());
return setupForm(submission, "New Submission", model);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Submission in project miso-lims by miso-lims.
the class HibernateSubmissionDaoIT method getCreateItem.
@Override
public Submission getCreateItem() {
Submission sub = new Submission();
sub.setAlias("Test Sub");
sub.setTitle("Test sub");
sub.setCreationDate(new Date());
sub.setVerified(false);
sub.setCompleted(false);
return sub;
}
use of uk.ac.bbsrc.tgac.miso.core.data.Submission in project miso-lims by miso-lims.
the class Dtos method to.
public static Submission to(@Nonnull SubmissionDto dto) {
Submission to = new Submission();
setLong(to::setId, dto.getId(), false);
setString(to::setAccession, dto.getAccession());
setString(to::setAlias, dto.getAlias());
to.setCompleted(dto.isCompleted());
setDate(to::setCreationDate, dto.getCreationDate());
setString(to::setDescription, dto.getDescription());
setDate(to::setSubmissionDate, dto.getSubmittedDate());
setString(to::setTitle, dto.getTitle());
to.setVerified(dto.isVerified());
if (dto.getExperimentIds() != null && !dto.getExperimentIds().isEmpty()) {
to.setExperiments(dto.getExperimentIds().stream().map(id -> {
Experiment exp = new Experiment();
exp.setId(id);
return exp;
}).collect(Collectors.toSet()));
}
return to;
}
Aggregations