use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRClassificationMappingEventHandler method createMapping.
private void createMapping(MCRObject obj) {
MCRMODSWrapper mcrmodsWrapper = new MCRMODSWrapper(obj);
if (mcrmodsWrapper.getMODS() == null) {
return;
}
// vorher alle mit generator *-mycore löschen
mcrmodsWrapper.getElements("mods:classification[contains(@generator, '" + GENERATOR_SUFFIX + "')]").stream().forEach(Element::detach);
LOGGER.info("check mappings {}", obj.getId());
mcrmodsWrapper.getMcrCategoryIDs().stream().map(categoryId -> DAO.getCategory(categoryId, 0)).filter(Objects::nonNull).map(MCRClassificationMappingEventHandler::getMappings).flatMap(Collection::stream).distinct().forEach(mapping -> {
String taskMessage = String.format(Locale.ROOT, "add mapping from '%s' to '%s'", mapping.getKey().toString(), mapping.getValue().toString());
LOGGER.info(taskMessage);
Element mappedClassification = mcrmodsWrapper.addElement("classification");
String generator = getGenerator(mapping.getKey(), mapping.getValue());
mappedClassification.setAttribute("generator", generator);
MCRClassMapper.assignCategory(mappedClassification, mapping.getValue());
});
LOGGER.debug("mapping complete.");
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRMODSDOIPersistentIdentifierMetadataManager method insertIdentifier.
@Override
public void insertIdentifier(MCRDigitalObjectIdentifier identifier, MCRBase base, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(base);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
wrapper.setElement("identifier", "type", "doi", identifier.asString()).orElseThrow(() -> new MCRException("Could not insert doi into mods document!"));
}
use of org.mycore.mods.MCRMODSWrapper in project mycore by MyCoRe-Org.
the class MCRMODSPURLPersistentIdentifierMetadataManager method insertIdentifier.
@Override
public void insertIdentifier(MCRPersistentUniformResourceLocator identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
MCRObject object = checkObject(obj);
MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
wrapper.setElement("identifier", "type", "purl", identifier.asString()).orElseThrow(() -> new MCRException("Could not insert purl into mods document!"));
}
use of org.mycore.mods.MCRMODSWrapper 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);
}
Aggregations