use of org.mycore.datamodel.common.MCRActiveLinkException in project mycore by MyCoRe-Org.
the class MCRClassification2Commands method processFromDirectory.
/**
* Loads or updates MCRClassification from all XML files in a directory.
*
* @param directory
* the directory containing the XML files
* @param update
* if true, classification will be updated, else Classification
* is created
* @throws MCRActiveLinkException
*/
private static List<String> processFromDirectory(String directory, boolean update) throws MCRActiveLinkException {
File dir = new File(directory);
if (!dir.isDirectory()) {
LOGGER.warn("{} ignored, is not a directory.", directory);
return null;
}
String[] list = dir.list();
if (list.length == 0) {
LOGGER.warn("No files found in directory {}", directory);
return null;
}
return Arrays.stream(list).filter(file -> file.endsWith(".xml")).map(file -> (update ? "update" : "load") + " classification from file " + new File(dir, file).getAbsolutePath()).collect(Collectors.toList());
}
use of org.mycore.datamodel.common.MCRActiveLinkException in project mycore by MyCoRe-Org.
the class MCRObjectCommands method replaceParent.
/**
* Moves object to new parent.
*
* @param sourceId
* object that should be attached to new parent
* @param newParentId
* the ID of the new parent
* @throws MCRAccessException see {@link MCRMetadataManager#update(MCRObject)}
*/
@MCRCommand(syntax = "set parent of {0} to {1}", help = "replaces a parent of an object (first parameter) to the given new one (second parameter)", order = 300)
public static void replaceParent(String sourceId, String newParentId) throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException {
// child
MCRObject sourceMCRObject = MCRMetadataManager.retrieveMCRObject(MCRObjectID.getInstance(sourceId));
// old parent
MCRObjectID oldParentId = sourceMCRObject.getStructure().getParentID();
MCRObjectID newParentObjectID = MCRObjectID.getInstance(newParentId);
if (newParentObjectID.equals(oldParentId)) {
LOGGER.info("Object {} is already child of {}", sourceId, newParentId);
return;
}
MCRObject oldParentMCRObject = null;
if (oldParentId != null) {
try {
oldParentMCRObject = MCRMetadataManager.retrieveMCRObject(oldParentId);
} catch (Exception exc) {
LOGGER.error("Unable to get old parent object {}, its probably deleted.", oldParentId, exc);
}
}
// change href to new parent
LOGGER.info("Setting link in \"{}\" to parent \"{}\"", sourceId, newParentObjectID);
MCRMetaLinkID parentLinkId = new MCRMetaLinkID("parent", 0);
parentLinkId.setReference(newParentObjectID, null, null);
sourceMCRObject.getStructure().setParent(parentLinkId);
if (oldParentMCRObject != null) {
// remove Child in old parent
LOGGER.info("Remove child \"{}\" in old parent \"{}\"", sourceId, oldParentId);
oldParentMCRObject.getStructure().removeChild(sourceMCRObject.getId());
LOGGER.info("Update old parent \"{}\n", oldParentId);
MCRMetadataManager.update(oldParentMCRObject);
}
LOGGER.info("Update \"{}\" in datastore (saving new link)", sourceId);
MCRMetadataManager.update(sourceMCRObject);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Structure: {}", sourceMCRObject.getStructure().isValid());
LOGGER.debug("Object: {}", sourceMCRObject.isValid());
}
}
use of org.mycore.datamodel.common.MCRActiveLinkException in project mycore by MyCoRe-Org.
the class MCRURNGranularOAIRegistrationService method register.
@Override
public MCRDNBURN register(MCRBase obj, String additional, boolean updateObject) throws MCRAccessException, MCRActiveLinkException, MCRPersistentIdentifierException {
this.validateRegistration(obj, additional);
MCRObjectDerivate derivate = ((MCRDerivate) obj).getDerivate();
MCRDNBURN newURN;
if (additional.equals("")) {
/* Multiple URN for entire Derivate... */
newURN = registerURNsDerivate(obj, additional, derivate);
} else {
/* Single URN to one File... */
newURN = registerSingleURN(obj, additional, derivate);
}
try {
MCRMetadataManager.update(obj);
} catch (Exception e) {
throw new MCRPersistentIdentifierException("Error while updating derivate " + obj.getId(), e);
}
return newURN;
}
Aggregations