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