Search in sources :

Example 66 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project webin-cli by enasequence.

the class ReadsXmlWriter method createRunXml.

String createRunXml(ReadsManifest manifest, String submissionTitle, String submissionAlias, String centerName, Path inputDir, Path uploadDir) {
    try {
        String title = submissionTitle;
        Element runSetE = new Element("RUN_SET");
        Element runE = new Element("RUN");
        runSetE.addContent(runE);
        Document doc = new Document(runSetE);
        runE.setAttribute("alias", submissionAlias);
        if (null != centerName && !centerName.isEmpty()) {
            runE.setAttribute("center_name", centerName);
        }
        runE.addContent(new Element("TITLE").setText(title));
        Element experimentRefE = new Element("EXPERIMENT_REF");
        runE.addContent(experimentRefE);
        experimentRefE.setAttribute("refname", submissionAlias);
        Element dataBlockE = new Element("DATA_BLOCK");
        runE.addContent(dataBlockE);
        Element filesE = new Element("FILES");
        dataBlockE.addContent(filesE);
        manifest.files(FileType.BAM).stream().map(file -> file.getFile().toPath()).forEach(file -> filesE.addContent(createFileElement(inputDir, uploadDir, file, "bam", null)));
        manifest.files(FileType.CRAM).stream().map(file -> file.getFile().toPath()).forEach(file -> filesE.addContent(createFileElement(inputDir, uploadDir, file, "cram", null)));
        manifest.files(FileType.FASTQ).stream().forEach(file -> filesE.addContent(createFileElement(inputDir, uploadDir, file.getFile().toPath(), "fastq", file.getAttributes())));
        Element runAttributesE = new Element("RUN_ATTRIBUTES");
        if (manifest.getSubmissionTool() != null && !manifest.getSubmissionTool().isEmpty()) {
            Element submissionToolRunAttributeTagE = new Element("TAG").setText("SUBMISSION_TOOL");
            Element submissionToolRunAttributeValueE = new Element("VALUE").setText(manifest.getSubmissionTool());
            Element submissionToolRunAttributeE = new Element("RUN_ATTRIBUTE");
            submissionToolRunAttributeE.addContent(submissionToolRunAttributeTagE);
            submissionToolRunAttributeE.addContent(submissionToolRunAttributeValueE);
            runAttributesE.addContent(submissionToolRunAttributeE);
        }
        if (manifest.getSubmissionToolVersion() != null && !manifest.getSubmissionToolVersion().isEmpty()) {
            Element submissionToolVersionRunAttributeTagE = new Element("TAG").setText("SUBMISSION_TOOL_VERSION");
            Element submissionToolVersionRunAttributeValueE = new Element("VALUE").setText(manifest.getSubmissionToolVersion());
            Element submissionToolVersionRunAttributeE = new Element("RUN_ATTRIBUTE");
            submissionToolVersionRunAttributeE.addContent(submissionToolVersionRunAttributeTagE);
            submissionToolVersionRunAttributeE.addContent(submissionToolVersionRunAttributeValueE);
            runAttributesE.addContent(submissionToolVersionRunAttributeE);
        }
        if (runAttributesE.getContentSize() > 0) {
            runE.addContent(runAttributesE);
        }
        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        StringWriter stringWriter = new StringWriter();
        xmlOutput.output(doc, stringWriter);
        return stringWriter.toString();
    } catch (IOException ex) {
        throw WebinCliException.systemError(ex);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Format(org.jdom2.output.Format) StringWriter(java.io.StringWriter) XmlWriterHelper.createFileElement(uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createFileElement) SubmissionBundle(uk.ac.ebi.ena.webin.cli.submit.SubmissionBundle) ReadsManifest(uk.ac.ebi.ena.webin.cli.validator.manifest.ReadsManifest) ReadsValidationResponse(uk.ac.ebi.ena.webin.cli.validator.response.ReadsValidationResponse) FileType(uk.ac.ebi.ena.webin.cli.validator.manifest.ReadsManifest.FileType) IOException(java.io.IOException) HashMap(java.util.HashMap) XMLOutputter(org.jdom2.output.XMLOutputter) WebinCliException(uk.ac.ebi.ena.webin.cli.WebinCliException) Document(org.jdom2.Document) Map(java.util.Map) XmlWriter(uk.ac.ebi.ena.webin.cli.xml.XmlWriter) Path(java.nio.file.Path) Element(org.jdom2.Element) XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) XmlWriterHelper.createFileElement(uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createFileElement) Element(org.jdom2.Element) IOException(java.io.IOException) Document(org.jdom2.Document)

Example 67 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project webin-cli by enasequence.

the class ReadsXmlWriter method createExperimentXml.

private String createExperimentXml(ReadsManifest manifest, ReadsValidationResponse response, String submissionTitle, String submissionAlias, String centerName) {
    String instrument = manifest.getInstrument();
    String description = StringUtils.isBlank(manifest.getDescription()) ? "unspecified" : manifest.getDescription();
    String libraryStrategy = manifest.getLibraryStrategy();
    String librarySource = manifest.getLibrarySource();
    String librarySelection = manifest.getLibrarySelection();
    String libraryName = manifest.getLibraryName();
    String platform = manifest.getPlatform();
    Integer insertSize = manifest.getInsertSize();
    try {
        String title = submissionTitle;
        Element experimentSetE = new Element("EXPERIMENT_SET");
        Element experimentE = new Element("EXPERIMENT");
        experimentSetE.addContent(experimentE);
        Document doc = new Document(experimentSetE);
        experimentE.setAttribute("alias", submissionAlias);
        if (null != centerName && !centerName.isEmpty()) {
            experimentE.setAttribute("center_name", centerName);
        }
        experimentE.addContent(new Element("TITLE").setText(title));
        Element studyRefE = new Element("STUDY_REF");
        experimentE.addContent(studyRefE);
        if (manifest.getStudy() != null) {
            studyRefE.setAttribute("accession", manifest.getStudy().getBioProjectId());
        }
        Element designE = new Element("DESIGN");
        experimentE.addContent(designE);
        Element designDescriptionE = new Element("DESIGN_DESCRIPTION");
        designDescriptionE.setText(description);
        designE.addContent(designDescriptionE);
        Element sampleDescriptorE = new Element("SAMPLE_DESCRIPTOR");
        if (manifest.getStudy() != null) {
            sampleDescriptorE.setAttribute("accession", manifest.getSample().getBioSampleId());
        }
        designE.addContent(sampleDescriptorE);
        Element libraryDescriptorE = new Element("LIBRARY_DESCRIPTOR");
        designE.addContent(libraryDescriptorE);
        if (null != libraryName) {
            Element libraryNameE = new Element("LIBRARY_NAME");
            libraryNameE.setText(libraryName);
            libraryDescriptorE.addContent(libraryNameE);
        }
        Element libraryStrategyE = new Element("LIBRARY_STRATEGY");
        libraryStrategyE.setText(libraryStrategy);
        libraryDescriptorE.addContent(libraryStrategyE);
        Element librarySourceE = new Element("LIBRARY_SOURCE");
        librarySourceE.setText(librarySource);
        libraryDescriptorE.addContent(librarySourceE);
        Element librarySelectionE = new Element("LIBRARY_SELECTION");
        librarySelectionE.setText(librarySelection);
        libraryDescriptorE.addContent(librarySelectionE);
        Element libraryLayoutE = new Element("LIBRARY_LAYOUT");
        if (!response.isPaired()) {
            libraryLayoutE.addContent(new Element("SINGLE"));
        } else {
            Element pairedE = new Element("PAIRED");
            libraryLayoutE.addContent(pairedE);
            if (null != insertSize) {
                pairedE.setAttribute("NOMINAL_LENGTH", String.valueOf(insertSize));
            }
        }
        libraryDescriptorE.addContent(libraryLayoutE);
        Element platformE = new Element("PLATFORM");
        experimentE.addContent(platformE);
        Element platformRefE = new Element(platform);
        platformE.addContent(platformRefE);
        Element instrumentModelE = new Element("INSTRUMENT_MODEL");
        instrumentModelE.setText(instrument);
        platformRefE.addContent(instrumentModelE);
        Element expAttributesE = new Element("EXPERIMENT_ATTRIBUTES");
        if (manifest.getSubmissionTool() != null && !manifest.getSubmissionTool().isEmpty()) {
            Element submissionToolExpAttributeTagE = new Element("TAG").setText("SUBMISSION_TOOL");
            Element submissionToolExpAttributeValueE = new Element("VALUE").setText(manifest.getSubmissionTool());
            Element submissionToolExpAttributeE = new Element("EXPERIMENT_ATTRIBUTE");
            submissionToolExpAttributeE.addContent(submissionToolExpAttributeTagE);
            submissionToolExpAttributeE.addContent(submissionToolExpAttributeValueE);
            expAttributesE.addContent(submissionToolExpAttributeE);
        }
        if (manifest.getSubmissionToolVersion() != null && !manifest.getSubmissionToolVersion().isEmpty()) {
            Element submissionToolVersionExpAttributeTagE = new Element("TAG").setText("SUBMISSION_TOOL_VERSION");
            Element submissionToolVersionExpAttributeValueE = new Element("VALUE").setText(manifest.getSubmissionToolVersion());
            Element submissionToolVersionExpAttributeE = new Element("EXPERIMENT_ATTRIBUTE");
            submissionToolVersionExpAttributeE.addContent(submissionToolVersionExpAttributeTagE);
            submissionToolVersionExpAttributeE.addContent(submissionToolVersionExpAttributeValueE);
            expAttributesE.addContent(submissionToolVersionExpAttributeE);
        }
        if (expAttributesE.getContentSize() > 0) {
            experimentE.addContent(expAttributesE);
        }
        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        StringWriter stringWriter = new StringWriter();
        xmlOutput.output(doc, stringWriter);
        return stringWriter.toString();
    } catch (IOException ex) {
        throw WebinCliException.systemError(ex);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) StringWriter(java.io.StringWriter) XmlWriterHelper.createFileElement(uk.ac.ebi.ena.webin.cli.xml.XmlWriterHelper.createFileElement) Element(org.jdom2.Element) IOException(java.io.IOException) Document(org.jdom2.Document)

Example 68 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project n2o-framework by i-novus-llc.

the class SelectiveUtil method readByPath.

@SuppressWarnings("unchecked")
public static <N> N readByPath(String uri, NamespaceReaderFactory readerFactory) {
    try (InputStream inputStream = FileSystemUtil.getContentAsStream(uri)) {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(inputStream);
        Element root = doc.getRootElement();
        return (N) readerFactory.produce(root).read(root);
    } catch (JDOMException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) InputStream(java.io.InputStream) Element(org.jdom2.Element) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 69 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project n2o-framework by i-novus-llc.

the class SelectiveUtil method read.

@SuppressWarnings("unchecked")
public static <N> N read(String source, ElementReaderFactory readerFactory) {
    try (Reader stringReader = new StringReader(source)) {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(stringReader);
        Element root = doc.getRootElement();
        return (N) readerFactory.produce(root).read(root);
    } catch (JDOMException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 70 with Document

use of com.axelor.apps.bankpayment.xsd.sepa.pain_001_001_03.Document in project plexus-containers by codehaus-plexus.

the class ComponentsXmlMergerTest method testMergeRoleComponents.

public void testMergeRoleComponents() throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    String source1 = "<component-set>\n" + "  <components>\n" + "    <component>\n" + "      <role>org.codehaus.plexus.metadata.component.DockerComposeConfigHandler</role>\n" + "      <implementation>org.codehaus.plexus.metadata.component.DominantComponent</implementation>\n" + "    </component>\n" + "    <component>\n" + "      <role>org.codehaus.plexus.metadata.component.PropertyConfigHandler</role>\n" + "      <implementation>org.codehaus.plexus.metadata.component.DominantComponent</implementation>\n" + "    </component>\n" + "  </components>\n" + "</component-set>";
    Document doc1 = saxBuilder.build(new StringReader(source1));
    String source2 = "<component-set>\n" + "  <components>\n" + "    <component>\n" + "      <role>org.codehaus.plexus.metadata.component.ExternalConfigHandler</role>\n" + "      <implementation>org.codehaus.plexus.metadata.component.DominantComponent</implementation>\n" + "    </component>\n" + "  </components>\n" + "</component-set>";
    Document doc2 = saxBuilder.build(new StringReader(source2));
    PlexusXmlMerger merger = new PlexusXmlMerger();
    Document mergedDoc = merger.merge(doc1, doc2);
    List<Element> components = mergedDoc.detachRootElement().getChild("components").getChildren();
    assertEquals(3, components.size());
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) ComponentsElement(org.codehaus.plexus.metadata.merge.support.ComponentsElement) RequirementsElement(org.codehaus.plexus.metadata.merge.support.RequirementsElement) ComponentElement(org.codehaus.plexus.metadata.merge.support.ComponentElement) AbstractMergeableElement(org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement) Element(org.jdom2.Element) StringReader(java.io.StringReader) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39