Search in sources :

Example 91 with MCRCommand

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);
            }
        }
    });
}
Also used : MCRException(org.mycore.common.MCRException) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRException(org.mycore.common.MCRException) MCRAccessException(org.mycore.access.MCRAccessException) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) IOException(java.io.IOException) MCRActiveLinkException(org.mycore.datamodel.common.MCRActiveLinkException) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 92 with MCRCommand

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());
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) MCRMarkManager(org.mycore.datamodel.common.MCRMarkManager) MCRPackerManager(org.mycore.services.packaging.MCRPackerManager) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MCRRecursiveDeleter(org.mycore.datamodel.niofs.utils.MCRRecursiveDeleter) MCRSolrIndexer(org.mycore.solr.index.MCRSolrIndexer) Map(java.util.Map) Operation(org.mycore.datamodel.common.MCRMarkManager.Operation) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) MCRClassificationUtils(org.mycore.datamodel.classifications2.utils.MCRClassificationUtils) Files(java.nio.file.Files) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MCRUtils(org.mycore.common.MCRUtils) MCRSolrSearchUtils(org.mycore.solr.search.MCRSolrSearchUtils) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRSolrClientFactory(org.mycore.solr.MCRSolrClientFactory) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) Paths(java.nio.file.Paths) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) LogManager(org.apache.logging.log4j.LogManager) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 93 with MCRCommand

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;
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 94 with MCRCommand

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());
}
Also used : Path(java.nio.file.Path) MCRMarkManager(org.mycore.datamodel.common.MCRMarkManager) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 95 with MCRCommand

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;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) MCRMarkManager(org.mycore.datamodel.common.MCRMarkManager) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Aggregations

MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)106 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)37 MCRException (org.mycore.common.MCRException)34 IOException (java.io.IOException)30 File (java.io.File)22 ArrayList (java.util.ArrayList)18 Document (org.jdom2.Document)17 JDOMException (org.jdom2.JDOMException)17 MCRObject (org.mycore.datamodel.metadata.MCRObject)17 Path (java.nio.file.Path)16 SAXException (org.xml.sax.SAXException)16 EntityManager (javax.persistence.EntityManager)15 MCRAccessException (org.mycore.access.MCRAccessException)15 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)15 MCRPath (org.mycore.datamodel.niofs.MCRPath)15 FileNotFoundException (java.io.FileNotFoundException)13 SAXParseException (org.xml.sax.SAXParseException)12 List (java.util.List)11 Element (org.jdom2.Element)11 MCRPersistenceException (org.mycore.common.MCRPersistenceException)11