use of org.mycore.datamodel.metadata.MCRMetaLinkID in project mycore by MyCoRe-Org.
the class MCRTransferPackage method resolveChildrenAndLinks.
/**
* Fills the given objectMap with all children and links of the object. The object
* itself is also added.
*
* @param object the source object
* @param objectMap the map which will be created
*/
protected void resolveChildrenAndLinks(MCRObject object, LinkedHashMap<MCRObjectID, MCRObject> objectMap, Set<MCRCategoryID> categories) {
// add links
for (MCRObject entityLink : MCRObjectUtils.getLinkedObjects(object)) {
if (!objectMap.containsKey(entityLink.getId())) {
objectMap.put(entityLink.getId(), entityLink);
}
}
// add classifications
categories.addAll(MCRObjectUtils.getCategories(object));
// add the object to the objectMap
objectMap.put(object.getId(), object);
// resolve children
for (MCRMetaLinkID metaLinkId : object.getStructure().getChildren()) {
MCRObjectID childId = MCRObjectID.getInstance(metaLinkId.toString());
if (!MCRMetadataManager.exists(childId)) {
throw new MCRUsageException("Requested object '" + childId + "' does not exist. Thus a transfer package cannot be created.");
}
MCRObject child = MCRMetadataManager.retrieveMCRObject(childId);
resolveChildrenAndLinks(child, objectMap, categories);
}
}
use of org.mycore.datamodel.metadata.MCRMetaLinkID 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.MCRMetaLinkID in project mycore by MyCoRe-Org.
the class MCRIFSTest method createDerivate.
public static MCRDerivate createDerivate(MCRObjectID objectHrefId) {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(MCRObjectID.getNextFreeId("mycore_derivate"));
derivate.setSchema("datamodel-derivate.xsd");
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(null);
derivate.getDerivate().setInternals(ifs);
MCRMetaLinkID mcrMetaLinkID = new MCRMetaLinkID();
mcrMetaLinkID.setReference(objectHrefId.toString(), null, null);
derivate.getDerivate().setLinkMeta(mcrMetaLinkID);
return derivate;
}
use of org.mycore.datamodel.metadata.MCRMetaLinkID in project mycore by MyCoRe-Org.
the class MCRMODSCommands method createDerivate.
private static MCRDerivate createDerivate(MCRObjectID documentID, File fileDir) throws MCRPersistenceException, IOException, MCRAccessException {
MCRDerivate derivate = new MCRDerivate();
derivate.setId(MCRObjectID.getNextFreeId(documentID.getProjectId(), "derivate"));
derivate.setLabel("data object from " + documentID);
String schema = CONFIG.getString("MCR.Metadata.Config.derivate", "datamodel-derivate.xml").replaceAll(".xml", ".xsd");
derivate.setSchema(schema);
MCRMetaLinkID linkId = new MCRMetaLinkID();
linkId.setSubTag("linkmeta");
linkId.setReference(documentID, null, null);
derivate.getDerivate().setLinkMeta(linkId);
MCRMetaIFS ifs = new MCRMetaIFS();
ifs.setSubTag("internal");
ifs.setSourcePath(fileDir.getAbsolutePath());
derivate.getDerivate().setInternals(ifs);
LOGGER.debug("Creating new derivate with ID {}", derivate.getId());
MCRMetadataManager.create(derivate);
setDefaultPermissions(derivate.getId());
return derivate;
}
use of org.mycore.datamodel.metadata.MCRMetaLinkID in project mycore by MyCoRe-Org.
the class MCRMODSLinksEventHandler method handleObjectUpdated.
/* (non-Javadoc)
* @see org.mycore.common.events.MCREventHandlerBase#handleObjectUpdated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject)
*/
@Override
protected void handleObjectUpdated(final MCREvent evt, final MCRObject obj) {
if (!MCRMODSWrapper.isSupported(obj)) {
return;
}
handleObjectCreated(evt, obj);
// may have to reindex children, if they inherit any information
for (MCRMetaLinkID childLinkID : obj.getStructure().getChildren()) {
MCRObjectID childID = childLinkID.getXLinkHrefID();
if (MCRMetadataManager.exists(childID)) {
MCREvent childEvent = new MCREvent(childID.getTypeId(), MCREvent.INDEX_EVENT);
childEvent.put("object", MCRMetadataManager.retrieve(childID));
MCREventManager.instance().handleEvent(childEvent);
}
}
}
Aggregations