Search in sources :

Example 91 with JDOMException

use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.

the class MCRDNBPIDefProvider method get.

public static Document get(String identifier) throws MCRIdentifierUnresolvableException {
    HttpGet get = new HttpGet(RESOLVING_URL_TEMPLATE.replaceAll("\\{urn\\}", identifier));
    try (CloseableHttpClient httpClient = MCRHttpUtils.getHttpClient()) {
        CloseableHttpResponse response = httpClient.execute(get);
        HttpEntity entity = response.getEntity();
        return new SAXBuilder().build(entity.getContent());
    } catch (IOException | JDOMException e) {
        String message = "The identifier " + identifier + " is not resolvable!";
        throw new MCRIdentifierUnresolvableException(identifier, message, e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SAXBuilder(org.jdom2.input.SAXBuilder) HttpEntity(org.apache.http.HttpEntity) MCRIdentifierUnresolvableException(org.mycore.pi.exceptions.MCRIdentifierUnresolvableException) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException)

Example 92 with JDOMException

use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.

the class MCRDOIRegistrationService method transformToDatacite.

protected Document transformToDatacite(MCRDigitalObjectIdentifier doi, MCRBase mcrBase) throws MCRPersistentIdentifierException {
    MCRObjectID id = mcrBase.getId();
    MCRBaseContent content = new MCRBaseContent(mcrBase);
    try {
        MCRContent transform = MCRContentTransformerFactory.getTransformer(this.transformer).transform(content);
        Document dataciteDocument = transform.asXML();
        insertDOI(dataciteDocument, doi);
        Schema dataciteSchema = loadDataciteSchema();
        try {
            dataciteSchema.newValidator().validate(new JDOMSource(dataciteDocument));
        } catch (SAXException e) {
            String translatedInformation = MCRTranslation.translate(TRANSLATE_PREFIX + ERR_CODE_1_2);
            throw new MCRPersistentIdentifierException("The document " + id + " does not generate well formed Datacite!", translatedInformation, ERR_CODE_1_2, e);
        }
        return dataciteDocument;
    } catch (IOException | JDOMException | SAXException e) {
        throw new MCRPersistentIdentifierException("Could not transform the content of " + id + " with the transformer " + transformer, e);
    }
}
Also used : Schema(javax.xml.validation.Schema) MCRBaseContent(org.mycore.common.content.MCRBaseContent) JDOMSource(org.jdom2.transform.JDOMSource) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) SAXException(org.xml.sax.SAXException)

Example 93 with JDOMException

use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.

the class MCRWorksFetcher method fetchDetails.

void fetchDetails(MCRWork work) throws JDOMException, IOException, SAXException {
    WebTarget target = orcid.getWebTarget().path("work").path(work.getPutCode());
    Element workXML = fetchWorksXML(target);
    setFromWorkXML(work, workXML);
}
Also used : Element(org.jdom2.Element) WebTarget(javax.ws.rs.client.WebTarget)

Example 94 with JDOMException

use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.

the class MCRWorksFetcher method fetchGroups.

List<MCRGroupOfWorks> fetchGroups(MCRWorksSection worksSection) throws JDOMException, IOException, SAXException {
    WebTarget target = orcid.getWebTarget().path("works");
    Element worksXML = fetchWorksXML(target);
    List<MCRGroupOfWorks> groups = new ArrayList<>();
    for (Element groupXML : worksXML.getChildren("group", MCRORCIDConstants.NS_ACTIVITIES)) {
        MCRGroupOfWorks group = new MCRGroupOfWorks();
        groups.add(group);
        for (Element workSummary : groupXML.getChildren("work-summary", MCRORCIDConstants.NS_WORK)) {
            String putCode = workSummary.getAttributeValue("put-code");
            MCRWork work = worksSection.getWork(putCode);
            if (work == null) {
                work = new MCRWork(orcid, putCode);
                setFromWorkXML(work, workSummary);
            }
            group.add(work);
        }
    }
    return groups;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget)

Example 95 with JDOMException

use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.

the class MCRWorksPublisher method createWorkFrom.

/**
 * Publishes the object (its MODS) as a new "work" in the ORCID profile
 */
MCRWork createWorkFrom(MCRObjectID objectID) throws IOException, JDOMException, SAXException {
    WebTarget target = orcid.getWebTarget().path("work");
    Builder builder = buildInvocation(target);
    Document workXML = buildWorkXMLFrom(objectID);
    Entity<InputStream> input = buildRequestEntity(workXML);
    LOGGER.info("post (create){} at {}", objectID, target.getUri());
    Response response = builder.post(input);
    expect(response, Response.Status.CREATED);
    String putCode = getPutCode(response);
    MCRWork work = new MCRWork(orcid, putCode);
    work.fetchDetails();
    return work;
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) Document(org.jdom2.Document)

Aggregations

Element (org.jdom2.Element)157 Document (org.jdom2.Document)116 JDOMException (org.jdom2.JDOMException)91 IOException (java.io.IOException)76 SAXBuilder (org.jdom2.input.SAXBuilder)70 Test (org.junit.Test)36 File (java.io.File)33 ArrayList (java.util.ArrayList)22 InputStream (java.io.InputStream)17 StringReader (java.io.StringReader)16 Attribute (org.jdom2.Attribute)16 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)14 SAXException (org.xml.sax.SAXException)14 HashMap (java.util.HashMap)13 XMLOutputter (org.jdom2.output.XMLOutputter)13 URL (java.net.URL)12 XmlFile (jmri.jmrit.XmlFile)12 List (java.util.List)11 MCRObject (org.mycore.datamodel.metadata.MCRObject)11 MCRException (org.mycore.common.MCRException)10