Search in sources :

Example 1 with Biotools14

use of org.edamontology.edammap.core.input.xml.Biotools14 in project edammap by edamontology.

the class Xml method load.

public static List<InputType> load(String queryPath, QueryType type, int timeout, String userAgent) throws IOException, ParseException {
    List<InputType> inputs = new ArrayList<>();
    if (type == QueryType.biotools14) {
        XMLStreamReader reader = null;
        try (InputStream is = Input.newInputStream(queryPath, true, timeout, userAgent)) {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            factory.setProperty("javax.xml.stream.isCoalescing", true);
            reader = factory.createXMLStreamReader(is, StandardCharsets.UTF_8.name());
            Biotools14 biotools = null;
            String text = null;
            while (reader.hasNext()) {
                switch(reader.next()) {
                    case XMLStreamConstants.START_ELEMENT:
                        String uri = reader.getAttributeValue(null, "uri");
                        switch(reader.getLocalName()) {
                            case "resource":
                                biotools = new Biotools14();
                                break;
                            case "topic":
                                if (uri != null)
                                    biotools.addTopic(uri);
                                break;
                            case "functionName":
                                if (uri != null)
                                    biotools.addFunctionName(uri);
                                break;
                            case "dataType":
                                if (uri != null)
                                    biotools.addDataType(uri);
                                break;
                            case "dataFormat":
                                if (uri != null)
                                    biotools.addDataFormat(uri);
                                break;
                        }
                        text = null;
                        break;
                    case XMLStreamConstants.CHARACTERS:
                        text = reader.getText();
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        switch(reader.getLocalName()) {
                            case "resource":
                                inputs.add(biotools);
                                biotools = null;
                                break;
                            case "name":
                                if (biotools.getName() == null)
                                    biotools.setName(text);
                                break;
                            case "homepage":
                                if (biotools.getHomepage() == null)
                                    biotools.setHomepage(text);
                                break;
                            case "mirror":
                                biotools.addMirror(text);
                                break;
                            case "description":
                                if (biotools.getDescription() == null)
                                    biotools.setDescription(text);
                                break;
                            case "docsHome":
                                if (biotools.getDocsHome() == null)
                                    biotools.setDocsHome(text);
                                break;
                            case "docsGithub":
                                if (biotools.getDocsGithub() == null)
                                    biotools.setDocsGithub(text);
                                break;
                            case "publicationsPrimaryID":
                                if (biotools.getPublicationsPrimaryID() == null)
                                    biotools.setPublicationsPrimaryID(text);
                                break;
                            case "publicationsOtherID":
                                biotools.addPublicationsOtherID(text);
                                break;
                        }
                        break;
                }
            }
        } catch (XMLStreamException e) {
            throw new ParseException(e.getLocalizedMessage(), e.getLocation().getLineNumber());
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (XMLStreamException e) {
                    throw new ParseException(e.getLocalizedMessage(), e.getLocation().getLineNumber());
                }
            }
        }
    }
    int i = 0;
    for (InputType inputType : inputs) {
        inputType.check(++i);
    }
    return inputs;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Biotools14(org.edamontology.edammap.core.input.xml.Biotools14) ParseException(java.text.ParseException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Example 2 with Biotools14

use of org.edamontology.edammap.core.input.xml.Biotools14 in project edammap by edamontology.

the class QueryLoader method get.

public static List<Query> get(String queryPath, QueryType type, Map<EdamUri, Concept> concepts, int timeout, String userAgent) throws IOException, ParseException {
    if (type == QueryType.server) {
        throw new IllegalArgumentException("Query of type \"" + QueryType.server.name() + "\" is not loadable from path, but has to be provided");
    }
    List<? extends InputType> inputs;
    if (type == QueryType.biotools) {
        inputs = Json.load(queryPath, type, timeout, userAgent);
    } else if (type == QueryType.biotools14) {
        inputs = Xml.load(queryPath, type, timeout, userAgent);
    } else {
        inputs = Csv.load(queryPath, type, timeout, userAgent);
    }
    Set<Query> queries = new LinkedHashSet<>();
    for (InputType input : inputs) {
        switch(type) {
            case generic:
                queries.add(getGeneric((Generic) input, concepts));
                break;
            case SEQwiki:
                queries.add(getSEQwiki((SEQwiki) input, concepts));
                break;
            case msutils:
                queries.add(getMsutils((Msutils) input, concepts));
                break;
            case Bioconductor:
                queries.add(getBioconductor((Bioconductor) input, concepts));
                break;
            case biotools14:
                queries.add(getBiotools14((Biotools14) input, concepts));
                break;
            case biotools:
                queries.add(getBiotools((ToolInput) input, concepts));
                break;
            case server:
                break;
        }
    }
    return new ArrayList<>(queries);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Bioconductor(org.edamontology.edammap.core.input.csv.Bioconductor) Generic(org.edamontology.edammap.core.input.csv.Generic) ArrayList(java.util.ArrayList) Msutils(org.edamontology.edammap.core.input.csv.Msutils) InputType(org.edamontology.edammap.core.input.InputType) Biotools14(org.edamontology.edammap.core.input.xml.Biotools14) ToolInput(org.edamontology.edammap.core.input.json.ToolInput) SEQwiki(org.edamontology.edammap.core.input.csv.SEQwiki)

Aggregations

ArrayList (java.util.ArrayList)2 Biotools14 (org.edamontology.edammap.core.input.xml.Biotools14)2 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 LinkedHashSet (java.util.LinkedHashSet)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 InputType (org.edamontology.edammap.core.input.InputType)1 Bioconductor (org.edamontology.edammap.core.input.csv.Bioconductor)1 Generic (org.edamontology.edammap.core.input.csv.Generic)1 Msutils (org.edamontology.edammap.core.input.csv.Msutils)1 SEQwiki (org.edamontology.edammap.core.input.csv.SEQwiki)1 ToolInput (org.edamontology.edammap.core.input.json.ToolInput)1