Search in sources :

Example 61 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method newLogicalStructMap.

/**
 * Creates the logical structure recursive.
 *
 * @param parentObject mycore object
 * @param parentLogicalDiv parent div
 */
protected void newLogicalStructMap(MCRObject parentObject, LogicalDiv parentLogicalDiv) {
    // run through all children
    List<MCRObject> children = getChildren(parentObject);
    children.forEach(childObject -> {
        // create new logical sub div
        String id = childObject.getId().toString();
        LogicalDiv logicalChildDiv = new LogicalDiv(id, getType(childObject), getLabel(childObject));
        // add to parent
        parentLogicalDiv.add(logicalChildDiv);
        // check if a derivate link exists and get the linked file
        updateStructLinkMapUsingDerivateLinks(logicalChildDiv, childObject);
        // do recursive call for children
        newLogicalStructMap(childObject, logicalChildDiv);
    });
}
Also used : LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRObject(org.mycore.datamodel.metadata.MCRObject)

Example 62 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRIView2XSLFunctions method getSupportedMainFileByOwner.

/**
 * Get the full path of the main file of the first derivate.
 *
 * @return the mainfile of the first derivate related to the given mcrid or
 *         null if there are no derivates related to the given mcrid
 */
public static String getSupportedMainFileByOwner(String mcrID) {
    MCRObjectID objectID = null;
    try {
        objectID = MCRObjectID.getInstance(mcrID);
    } catch (Exception e) {
        return null;
    }
    MCRObject obj = MCRMetadataManager.retrieveMCRObject(objectID);
    List<MCRMetaLinkID> derivates = obj.getStructure().getDerivates();
    if (derivates.size() > 0)
        return derivates.get(0) + "/" + adapter.getSupportedMainFile(derivates.get(0).toString());
    return null;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 63 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRMODSMetadataShareAgent method distributeMetadata.

/* (non-Javadoc)
     * @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject)
     */
@Override
public void distributeMetadata(MCRObject holder) throws MCRPersistenceException, MCRAccessException {
    MCRMODSWrapper holderWrapper = new MCRMODSWrapper(holder);
    List<MCRMetaLinkID> children = holder.getStructure().getChildren();
    if (!children.isEmpty()) {
        LOGGER.info("Update inherited metadata");
        for (MCRMetaLinkID childIdRef : children) {
            MCRObjectID childId = childIdRef.getXLinkHrefID();
            if (MCRMODSWrapper.isSupported(childId)) {
                LOGGER.info("Update: {}", childIdRef);
                MCRObject child = MCRMetadataManager.retrieveMCRObject(childId);
                MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
                inheritToChild(holderWrapper, childWrapper);
                LOGGER.info("Saving: {}", childIdRef);
                try {
                    MCRMetadataManager.update(child);
                } catch (MCRPersistenceException | MCRAccessException e) {
                    throw new MCRPersistenceException("Error while updating inherited metadata", e);
                }
            }
        }
    }
    Collection<String> recipientIds = MCRLinkTableManager.instance().getSourceOf(holder.getId(), MCRLinkTableManager.ENTRY_TYPE_REFERENCE);
    for (String rId : recipientIds) {
        MCRObjectID recipientId = MCRObjectID.getInstance(rId);
        if (MCRMODSWrapper.isSupported(recipientId)) {
            LOGGER.info("distribute metadata to {}", rId);
            MCRObject recipient = MCRMetadataManager.retrieveMCRObject(recipientId);
            MCRMODSWrapper recipientWrapper = new MCRMODSWrapper(recipient);
            for (Element relatedItem : recipientWrapper.getLinkedRelatedItems()) {
                String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
                if (holder.getId().toString().equals(holderId)) {
                    @SuppressWarnings("unchecked") Filter<Content> sharedMetadata = (Filter<Content>) Filters.element("part", MCRConstants.MODS_NAMESPACE).negate();
                    relatedItem.removeContent(sharedMetadata);
                    relatedItem.addContent(holderWrapper.getMODS().cloneContent());
                    LOGGER.info("Saving: {}", recipientId);
                    try {
                        MCRMetadataManager.update(recipient);
                    } catch (MCRPersistenceException | MCRAccessException e) {
                        throw new MCRPersistenceException("Error while updating shared metadata", e);
                    }
                }
            }
        }
    }
}
Also used : Element(org.jdom2.Element) MCRAccessException(org.mycore.access.MCRAccessException) MCRObject(org.mycore.datamodel.metadata.MCRObject) Filter(org.jdom2.filter.Filter) Content(org.jdom2.Content) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Example 64 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject 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 65 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject 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)

Aggregations

MCRObject (org.mycore.datamodel.metadata.MCRObject)71 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)33 Document (org.jdom2.Document)18 Element (org.jdom2.Element)17 MCRException (org.mycore.common.MCRException)16 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)14 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)14 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)12 IOException (java.io.IOException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)9 MCRPersistenceException (org.mycore.common.MCRPersistenceException)7 Date (java.util.Date)6 JDOMException (org.jdom2.JDOMException)6 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)6 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)6 SAXException (org.xml.sax.SAXException)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5