Search in sources :

Example 11 with MCRObject

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

the class MCRMODSMetadataShareAgent method receiveMetadata.

/* (non-Javadoc)
     * @see org.mycore.datamodel.metadata.share.MCRMetadataShareAgent#inheritMetadata(org.mycore.datamodel.metadata.MCRObject, org.mycore.datamodel.metadata.MCRObject)
     */
@Override
public void receiveMetadata(MCRObject child) {
    MCRMODSWrapper childWrapper = new MCRMODSWrapper(child);
    MCRObjectID parentID = child.getStructure().getParentID();
    LOGGER.debug("Removing old inherited Metadata.");
    childWrapper.removeInheritedMetadata();
    if (parentID != null && MCRMODSWrapper.isSupported(parentID)) {
        MCRObject parent = MCRMetadataManager.retrieveMCRObject(parentID);
        MCRMODSWrapper parentWrapper = new MCRMODSWrapper(parent);
        inheritToChild(parentWrapper, childWrapper);
    }
    for (Element relatedItem : childWrapper.getLinkedRelatedItems()) {
        String type = relatedItem.getAttributeValue("type");
        String holderId = relatedItem.getAttributeValue("href", MCRConstants.XLINK_NAMESPACE);
        LOGGER.info("receive metadata from {} document {}", type, holderId);
        if ((holderId == null || parentID != null && parentID.toString().equals(holderId)) && MCRMODSRelationshipType.host.name().equals(type)) {
            // already received metadata from parent;
            continue;
        }
        MCRObjectID holderObjectID = MCRObjectID.getInstance(holderId);
        if (MCRMODSWrapper.isSupported(holderObjectID)) {
            MCRObject targetObject = MCRMetadataManager.retrieveMCRObject(holderObjectID);
            MCRMODSWrapper targetWrapper = new MCRMODSWrapper(targetObject);
            relatedItem.addContent(targetWrapper.getMODS().cloneContent());
        }
    }
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 12 with MCRObject

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

the class MCRMODSDOIPersistentIdentifierMetadataManager method getIdentifier.

@Override
public Optional<MCRPersistentIdentifier> getIdentifier(MCRBase base, String additional) throws MCRPersistentIdentifierException {
    MCRObject object = checkObject(base);
    MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
    Element element = wrapper.getElement("mods:identifier[@type='doi']");
    if (element == null) {
        return Optional.empty();
    }
    String doiText = element.getTextNormalize();
    return new MCRDOIParser().parse(doiText).filter(Objects::nonNull).map(MCRPersistentIdentifier.class::cast);
}
Also used : MCRDOIParser(org.mycore.pi.doi.MCRDOIParser) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRPersistentIdentifier(org.mycore.pi.MCRPersistentIdentifier)

Example 13 with MCRObject

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

the class MCRMODSPURLPersistentIdentifierMetadataManager 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_PURL);
    if (element == null) {
        return Optional.empty();
    }
    String purlString = element.getTextNormalize();
    try {
        return Optional.of(new MCRPersistentUniformResourceLocator(new URL(purlString)));
    } catch (MalformedURLException e) {
        return Optional.empty();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) MCRPersistentUniformResourceLocator(org.mycore.pi.purl.MCRPersistentUniformResourceLocator) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) URL(java.net.URL)

Example 14 with MCRObject

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

the class MCRMODSURNPersistentIdentifierMetadataManager method insertIdentifier.

@Override
public void insertIdentifier(MCRUniformResourceName identifier, MCRBase obj, String additional) throws MCRPersistentIdentifierException {
    MCRObject object = checkObject(obj);
    MCRMODSWrapper wrapper = new MCRMODSWrapper(object);
    wrapper.setElement("identifier", "type", "urn", identifier.asString()).orElseThrow(() -> new MCRException("Could not insert urn into mods document!"));
}
Also used : MCRException(org.mycore.common.MCRException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper)

Example 15 with MCRObject

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

the class MCRRestAPIObjectsHelper method retrieveMaindocURL.

/**
 * returns the URL of the main document of a derivate
 *
 * @param info - the Jersey UriInfo object
 * @param mcrObjID - the MyCoRe Object ID
 * @param mcrDerID - the MyCoRe Derivate ID
 *
 * @return the Resolving URL for the main document of the derivate
 * @throws IOException
 */
public static String retrieveMaindocURL(UriInfo info, String mcrObjID, String mcrDerID) throws IOException {
    try {
        MCRObject mcrObj = retrieveMCRObject(mcrObjID);
        MCRDerivate derObj = retrieveMCRDerivate(mcrObj, mcrDerID);
        String maindoc = derObj.getDerivate().getInternals().getMainDoc();
        String baseURL = MCRJerseyUtil.getBaseURL(info) + MCRConfiguration.instance().getString("MCR.RestAPI.v1.Files.URL.path");
        baseURL = baseURL.replace("${mcrid}", mcrObj.getId().toString()).replace("${derid}", derObj.getId().toString());
        return baseURL + maindoc;
    } catch (MCRRestAPIException rae) {
        return null;
    }
}
Also used : MCRRestAPIException(org.mycore.restapi.v1.errors.MCRRestAPIException) MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRDerivate(org.mycore.datamodel.metadata.MCRDerivate)

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