use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRPICommands method addFlagsToObjects.
@MCRCommand(syntax = "add PI Flags to objects", help = "Should only be used if you used mycore-pi pre 2016 lts!")
public static void addFlagsToObjects() {
MCRPersistentIdentifierManager.getInstance().getList().forEach(registrationInfo -> {
if (registrationInfo.getMcrRevision() <= 35726) {
String mycoreID = registrationInfo.getMycoreID();
MCRObjectID objectID = MCRObjectID.getInstance(mycoreID);
MCRBase base = MCRMetadataManager.retrieve(objectID);
LOGGER.info("Add PI-Flag to {}", mycoreID);
MCRPIRegistrationService.addFlagToObject(base, (MCRPI) registrationInfo);
try {
MCRMetadataManager.update(base);
} catch (Exception e) {
throw new MCRException(e);
}
}
});
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRTransferPackageCommands method _importObject.
@MCRCommand(syntax = "_import transfer package object {0} from {1}")
public static List<String> _importObject(String objectId, String targetDirectoryPath) throws Exception {
Path targetDirectory = Paths.get(targetDirectoryPath);
List<String> derivates = MCRTransferPackageUtil.importObjectCLI(targetDirectory, objectId);
return derivates.stream().map(derId -> "_import transfer package derivate " + derId + " from " + targetDirectoryPath).collect(Collectors.toList());
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRTransferPackageCommands method importTransferPackageFromTar.
@MCRCommand(help = "Imports a transfer package located at {0}. Where {0} is the absolute path to the tar file.", syntax = "import transfer package from tar {0}")
public static List<String> importTransferPackageFromTar(String pathToTar) throws Exception {
Path tar = Paths.get(pathToTar);
if (!Files.exists(tar)) {
throw new FileNotFoundException(tar.toAbsolutePath() + " does not exist.");
}
Path targetDirectory = MCRTransferPackageUtil.getTargetDirectory(tar);
List<String> commands = new ArrayList<>();
commands.add("_import transfer package untar " + pathToTar);
commands.add("_import transfer package from directory " + targetDirectory);
commands.add("_import transfer package clean up " + targetDirectory);
return commands;
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRTransferPackageCommands method _cleanUp.
@MCRCommand(syntax = "_import transfer package clean up {0}")
public static void _cleanUp(String targetDirectoryPath) throws Exception {
Path targetDirectory = Paths.get(targetDirectoryPath);
// delete mark of imported object
List<String> mcrObjects = MCRTransferPackageUtil.getMCRObjects(targetDirectory);
MCRMarkManager markManager = MCRMarkManager.instance();
for (String id : mcrObjects) {
markManager.remove(MCRObjectID.getInstance(id));
}
// index all objects
MCRSolrIndexer.rebuildMetadataIndex(mcrObjects);
// deleting expanded directory
LOGGER.info("Deleting expanded tar in {}...", targetDirectoryPath);
Files.walkFileTree(Paths.get(targetDirectoryPath), MCRRecursiveDeleter.instance());
}
use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.
the class MCRTransferPackageCommands method _fromDirectory.
@MCRCommand(syntax = "_import transfer package from directory {0}")
public static List<String> _fromDirectory(String targetDirectoryPath) throws Exception {
LOGGER.info("Import transfer package from {}...", targetDirectoryPath);
Path targetDirectory = Paths.get(targetDirectoryPath);
List<String> commands = new ArrayList<>();
// load classifications
List<Path> classificationPaths = MCRTransferPackageUtil.getClassifications(targetDirectory);
for (Path pathToClassification : classificationPaths) {
commands.add("_import transfer package classification from " + pathToClassification.toAbsolutePath());
}
// import objects
List<String> mcrObjects = MCRTransferPackageUtil.getMCRObjects(targetDirectory);
MCRMarkManager markManager = MCRMarkManager.instance();
for (String id : mcrObjects) {
markManager.mark(MCRObjectID.getInstance(id), Operation.IMPORT);
commands.add("_import transfer package object " + id + " from " + targetDirectoryPath);
}
return commands;
}
Aggregations