Search in sources :

Example 1 with Submission

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.");
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Transformer(javax.xml.transform.Transformer) DOMSource(javax.xml.transform.dom.DOMSource) User(com.eaglegenomics.simlims.core.User) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransformerException(javax.xml.transform.TransformerException) RunPartition(uk.ac.bbsrc.tgac.miso.core.data.Experiment.RunPartition) Date(java.util.Date) StreamResult(javax.xml.transform.stream.StreamResult) ParentLibrary(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ParentLibrary) SimpleDateFormat(java.text.SimpleDateFormat) HealthType(uk.ac.bbsrc.tgac.miso.core.data.type.HealthType) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) Run(uk.ac.bbsrc.tgac.miso.core.data.Run) Sample(uk.ac.bbsrc.tgac.miso.core.data.Sample) Document(org.w3c.dom.Document) Library(uk.ac.bbsrc.tgac.miso.core.data.Library) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) ZipEntry(java.util.zip.ZipEntry) DateFormat(java.text.DateFormat) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ListLibraryAliquotView(uk.ac.bbsrc.tgac.miso.core.data.impl.view.ListLibraryAliquotView) SubmissionActionType(uk.ac.bbsrc.tgac.miso.core.data.type.SubmissionActionType) Set(java.util.Set) IOException(java.io.IOException) OutputKeys(javax.xml.transform.OutputKeys) Partition(uk.ac.bbsrc.tgac.miso.core.data.Partition) Study(uk.ac.bbsrc.tgac.miso.core.data.Study) Objects(java.util.Objects) Stream(java.util.stream.Stream) Element(org.w3c.dom.Element) LimsUtils.isStringEmptyOrNull(uk.ac.bbsrc.tgac.miso.core.util.LimsUtils.isStringEmptyOrNull) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Pair(uk.ac.bbsrc.tgac.miso.core.data.Pair) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Pool(uk.ac.bbsrc.tgac.miso.core.data.Pool) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) PoolElement(uk.ac.bbsrc.tgac.miso.core.data.impl.view.PoolElement) Element(org.w3c.dom.Element) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) Date(java.util.Date) ZipOutputStream(java.util.zip.ZipOutputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 2 with Submission

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();
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) User(com.eaglegenomics.simlims.core.User) Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) MediaType(org.springframework.http.MediaType) SimpleDateFormat(java.text.SimpleDateFormat) EnaSubmissionPreparation(uk.ac.bbsrc.tgac.miso.core.util.EnaSubmissionPreparation) Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Submission

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);
}
Also used : Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) Date(java.util.Date) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with Submission

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;
}
Also used : Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) Date(java.util.Date)

Example 5 with Submission

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;
}
Also used : Submission(uk.ac.bbsrc.tgac.miso.core.data.Submission) Experiment(uk.ac.bbsrc.tgac.miso.core.data.Experiment) IonTorrentRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IonTorrentRunDto) QcHierarchyNodeDto(uk.ac.bbsrc.tgac.miso.dto.dashi.QcHierarchyNodeDto) RunPositionDto(uk.ac.bbsrc.tgac.miso.dto.run.RunPositionDto) PacBioRunDto(uk.ac.bbsrc.tgac.miso.dto.run.PacBioRunDto) Ls454RunDto(uk.ac.bbsrc.tgac.miso.dto.run.Ls454RunDto) IlluminaNotificationDto(ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto) OxfordNanoporeRunDto(uk.ac.bbsrc.tgac.miso.dto.run.OxfordNanoporeRunDto) IlluminaRunDto(uk.ac.bbsrc.tgac.miso.dto.run.IlluminaRunDto) NotificationDto(ca.on.oicr.gsi.runscanner.dto.NotificationDto) OxfordNanoporeNotificationDto(ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto) RunDto(uk.ac.bbsrc.tgac.miso.dto.run.RunDto) SolidRunDto(uk.ac.bbsrc.tgac.miso.dto.run.SolidRunDto) OrderAliquotDto(uk.ac.bbsrc.tgac.miso.dto.PoolOrderDto.OrderAliquotDto)

Aggregations

Submission (uk.ac.bbsrc.tgac.miso.core.data.Submission)6 Date (java.util.Date)4 User (com.eaglegenomics.simlims.core.User)2 SimpleDateFormat (java.text.SimpleDateFormat)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Experiment (uk.ac.bbsrc.tgac.miso.core.data.Experiment)2 IlluminaNotificationDto (ca.on.oicr.gsi.runscanner.dto.IlluminaNotificationDto)1 NotificationDto (ca.on.oicr.gsi.runscanner.dto.NotificationDto)1 OxfordNanoporeNotificationDto (ca.on.oicr.gsi.runscanner.dto.OxfordNanoporeNotificationDto)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 OutputKeys (javax.xml.transform.OutputKeys)1