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