Search in sources :

Example 6 with MCRPersistentIdentifier

use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.

the class MCRMODSURNPersistentIdentifierMetadataManager 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_URN);
    if (element == null) {
        return Optional.empty();
    }
    String urnText = element.getTextNormalize();
    return new MCRDNBURNParser().parse(urnText).filter(Objects::nonNull).map(MCRPersistentIdentifier.class::cast);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRDNBURNParser(org.mycore.pi.urn.MCRDNBURNParser) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 7 with MCRPersistentIdentifier

use of org.mycore.pi.MCRPersistentIdentifier in project mycore by MyCoRe-Org.

the class MCRURNObjectXPathMetadataManager method getIdentifier.

@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase obj, String additional) throws MCRPersistentIdentifierException {
    String xpath = getProperties().get("Xpath");
    Document xml = obj.createXML();
    XPathFactory xpfac = XPathFactory.instance();
    XPathExpression<Text> xp = xpfac.compile(xpath, Filters.text());
    List<Text> evaluate = xp.evaluate(xml);
    if (evaluate.size() > 1) {
        throw new MCRPersistentIdentifierException("Got " + evaluate.size() + " matches for " + obj.getId() + " with xpath " + xpath + "");
    }
    if (evaluate.size() == 0) {
        return Optional.empty();
    }
    Text identifierText = evaluate.listIterator().next();
    String identifierString = identifierText.getTextNormalize();
    Optional<MCRDNBURN> parsedIdentifierOptional = PARSER.parse(identifierString);
    return parsedIdentifierOptional.map(MCRPersistentIdentifier.class::cast);
}
Also used : XPathFactory(org.jdom2.xpath.XPathFactory) Text(org.jdom2.Text) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Aggregations

MCRPersistentIdentifier (org.mycore.pi.MCRPersistentIdentifier)7 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)3 Element (org.jdom2.Element)2 MCRBase (org.mycore.datamodel.metadata.MCRBase)2 MCRObject (org.mycore.datamodel.metadata.MCRObject)2 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)2 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)2 Date (java.util.Date)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Document (org.jdom2.Document)1 Text (org.jdom2.Text)1 XPathFactory (org.jdom2.xpath.XPathFactory)1 MCRAccessException (org.mycore.access.MCRAccessException)1 MCRException (org.mycore.common.MCRException)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)1 MCRISO8601Date (org.mycore.datamodel.common.MCRISO8601Date)1 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)1