Search in sources :

Example 1 with MCRMODSWrapper

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;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Example 2 with MCRMODSWrapper

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);
}
Also used : MCRDOIParser(org.mycore.pi.doi.MCRDOIParser) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 3 with MCRMODSWrapper

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();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRPersistentUniformResourceLocator(org.mycore.pi.purl.MCRPersistentUniformResourceLocator) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) URL(java.net.URL)

Example 4 with MCRMODSWrapper

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!"));
}
Also used : MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper)

Example 5 with MCRMODSWrapper

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));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) Document(org.jdom2.Document) Test(org.junit.Test)

Aggregations

MCRObject (org.mycore.datamodel.metadata.MCRObject)9 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)9 Element (org.jdom2.Element)5 MCRException (org.mycore.common.MCRException)3 Document (org.jdom2.Document)2 MCRPersistentIdentifier (org.mycore.pi.MCRPersistentIdentifier)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AbstractMap (java.util.AbstractMap)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1