Search in sources :

Example 6 with MCRMODSWrapper

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.");
}
Also used : Collection(java.util.Collection) MCREvent(org.mycore.common.events.MCREvent) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) Collectors(java.util.stream.Collectors) MCREventHandlerBase(org.mycore.common.events.MCREventHandlerBase) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) Objects(java.util.Objects) AbstractMap(java.util.AbstractMap) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) Locale(java.util.Locale) Map(java.util.Map) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRCategoryDAOFactory(org.mycore.datamodel.classifications2.MCRCategoryDAOFactory) Optional(java.util.Optional) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRLabel(org.mycore.datamodel.classifications2.MCRLabel) Element(org.jdom2.Element) Element(org.jdom2.Element) Objects(java.util.Objects) Collection(java.util.Collection) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper)

Example 7 with MCRMODSWrapper

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

Example 8 with MCRMODSWrapper

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

Example 9 with MCRMODSWrapper

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

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