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);
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations