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