use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRRSSFeedImporter method buildMCRObject.
private MCRObject buildMCRObject(Element publicationXML, String projectID) {
MCRObject obj = new MCRObject(new Document(publicationXML));
MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
wrapper.setServiceFlag("status", STATUS_FLAG);
MCRObjectID oid = MCRObjectID.getNextFreeId(projectID, "mods");
obj.setId(oid);
return obj;
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRMODSDOIPersistentIdentifierMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase base, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(base);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
Element element = wrapper.getElement("mods:identifier[@type='doi']");
if (element == null) {
return Optional.empty();
}
String doiText = element.getTextNormalize();
return new MCRDOIParser().parse(doiText).filter(Objects::nonNull).map(MCRPersistentIdentifier.class::cast);
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRMODSPURLPersistentIdentifierMetadataManager method getIdentifier.
@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(obj);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
Element element = wrapper.getElement(MODS_IDENTIFIER_TYPE_PURL);
if (element == null) {
return Optional.empty();
}
String purlString = element.getTextNormalize();
try {
return Optional.of(new MCRPersistentUniformResourceLocator(new URL(purlString)));
} catch (MalformedURLException e) {
return Optional.empty();
}
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRMODSURNPersistentIdentifierMetadataManager method insertIdentifier.
@Override
public void insertIdentifier(MCRUniformResourceName identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(obj);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
wrapper.setElement("identifier", "type", "urn", identifier.asString()).orElseThrow(() -> new MCRException("Could not insert urn into mods document!"));
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRClassificationMappingEventHandlerTest method testMapping.
@Test
public void testMapping() throws SAXParseException, IOException, JDOMException, URISyntaxException {
MCRSessionMgr.getCurrentSession().isTransactionActive();
ClassLoader classLoader = getClass().getClassLoader();
SAXBuilder saxBuilder = new SAXBuilder();
loadCategory("diniPublType.xml");
loadCategory("genre.xml");
Document document = saxBuilder.build(classLoader.getResourceAsStream(TEST_DIRECTORY + "testMods.xml"));
MCRObject mcro = new MCRObject();
MCRMODSWrapper mw = new MCRMODSWrapper(mcro);
mw.setMODS(document.getRootElement().detach());
mw.setID("junit", 1);
MCRClassificationMappingEventHandler mapper = new MCRClassificationMappingEventHandler();
mapper.handleObjectUpdated(null, mcro);
String expression = "//mods:classification[contains(@generator,'-mycore') and contains(@valueURI, 'StudyThesis')]";
XPathExpression<Element> expressionObject = XPathFactory.instance().compile(expression, Filters.element(), null, MCRConstants.MODS_NAMESPACE, MCRConstants.XLINK_NAMESPACE);
Document xml = mcro.createXML();
Assert.assertNotNull("The mapped classification should be in the MyCoReObject now!", expressionObject.evaluateFirst(xml));
expression = "//mods:classification[contains(@generator,'-mycore') and contains(@valueURI, 'masterThesis')]";
expressionObject = XPathFactory.instance().compile(expression, Filters.element(), null, MCRConstants.MODS_NAMESPACE, MCRConstants.XLINK_NAMESPACE);
Assert.assertNull("The mapped classification of the child should not be contained in the MyCoReObject now!", expressionObject.evaluateFirst(xml));
LOGGER.info(new XMLOutputter(Format.getPrettyFormat()).outputString(xml));
}
Aggregations