Search in sources :

Example 46 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRIView2Commands method deleteDerivateTiles.

/**
 * Deletes all image tiles of this derivate.
 * @param derivateID a derivate ID
 */
@MCRCommand(syntax = DEL_DERIVATE_TILES_COMMAND_SYNTAX, help = "removes tiles of a specific file identified by its derivate ID {0}", order = 100)
public static void deleteDerivateTiles(String derivateID) throws IOException {
    Path derivateDir = MCRImage.getTiledFile(MCRIView2Tools.getTileDir(), derivateID, null);
    Files.walkFileTree(derivateDir, MCRRecursiveDeleter.instance());
    MCRTilingQueue.getInstance().remove(derivateID);
}
Also used : Path(java.nio.file.Path) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 47 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRIView2Commands method tileImage.

/**
 * Tiles this image.
 * @param derivate derivate ID
 * @param absoluteImagePath absolute path to image file
 */
@MCRCommand(syntax = TILE_IMAGE_COMMAND_SYNTAX, help = "tiles a specific file identified by its derivate {0} and absolute path {1}", order = 70)
public static void tileImage(String derivate, String absoluteImagePath) {
    MCRTileJob job = new MCRTileJob();
    job.setDerivate(derivate);
    job.setPath(absoluteImagePath);
    MCRTilingQueue.getInstance().offer(job);
    startMasterTilingThread();
}
Also used : MCRTileJob(org.mycore.iview2.services.MCRTileJob) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 48 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRIView2Commands method fixDeadEntries.

@MCRCommand(syntax = "fix dead tile jobs", help = "Deletes entries for files which dont exist anymore!")
public static void fixDeadEntries() {
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    TypedQuery<MCRTileJob> allTileJobQuery = em.createNamedQuery("MCRTileJob.all", MCRTileJob.class);
    List<MCRTileJob> tiles = allTileJobQuery.getResultList();
    tiles.stream().filter(tj -> {
        MCRPath path = MCRPath.getPath(tj.getDerivate(), tj.getPath());
        return !Files.exists(path);
    }).peek(tj -> LOGGER.info("Delete TileJob {}:{}", tj.getDerivate(), tj.getPath())).forEach(em::remove);
}
Also used : MCRIView2Tools(org.mycore.iview2.services.MCRIView2Tools) Enumeration(java.util.Enumeration) TypedQuery(javax.persistence.TypedQuery) MCRException(org.mycore.common.MCRException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MCRRecursiveDeleter(org.mycore.datamodel.niofs.utils.MCRRecursiveDeleter) DirectoryStream(java.nio.file.DirectoryStream) JDOMException(org.jdom2.JDOMException) MCRImage(org.mycore.imagetiler.MCRImage) MCRTileJob(org.mycore.iview2.services.MCRTileJob) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRTiledPictureProps(org.mycore.imagetiler.MCRTiledPictureProps) ZipFile(java.util.zip.ZipFile) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) MCRMetadataManager(org.mycore.datamodel.metadata.MCRMetadataManager) MCRTilingQueue(org.mycore.iview2.services.MCRTilingQueue) ImageReader(javax.imageio.ImageReader) BufferedImage(java.awt.image.BufferedImage) Files(java.nio.file.Files) MCRAbstractCommands(org.mycore.frontend.cli.MCRAbstractCommands) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRImageTiler(org.mycore.iview2.services.MCRImageTiler) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) FileSystem(java.nio.file.FileSystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) CRC32(java.util.zip.CRC32) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) EntityManager(javax.persistence.EntityManager) FileSystem(java.nio.file.FileSystem) MCRTileJob(org.mycore.iview2.services.MCRTileJob) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 49 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRMetsCommands method validateSelectedMets.

@MCRCommand(syntax = "validate selected mets", help = "validates all mets.xml of selected derivates", order = 10)
public static void validateSelectedMets() {
    List<String> selectedObjectIDs = MCRObjectCommands.getSelectedObjectIDs();
    for (String objectID : selectedObjectIDs) {
        LOGGER.info("Validate mets.xml of {}", objectID);
        MCRPath metsFile = MCRPath.getPath(objectID, "/mets.xml");
        if (Files.exists(metsFile)) {
            try {
                MCRContent content = new MCRPathContent(metsFile);
                InputStream metsIS = content.getInputStream();
                METSValidator mv = new METSValidator(metsIS);
                List<ValidationException> validationExceptionList = mv.validate();
                if (validationExceptionList.size() > 0) {
                    invalidMetsQueue.add(objectID);
                }
                for (ValidationException validationException : validationExceptionList) {
                    LOGGER.error(validationException.getMessage());
                }
            } catch (IOException e) {
                LOGGER.error("Error while reading mets.xml of {}", objectID, e);
            } catch (JDOMException e) {
                LOGGER.error("Error while parsing mets.xml of {}", objectID, e);
            }
        }
    }
}
Also used : ValidationException(org.mycore.mets.validator.validators.ValidationException) InputStream(java.io.InputStream) MCRPathContent(org.mycore.common.content.MCRPathContent) METSValidator(org.mycore.mets.validator.METSValidator) IOException(java.io.IOException) MCRPath(org.mycore.datamodel.niofs.MCRPath) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 50 with MCRCommand

use of org.mycore.frontend.cli.annotation.MCRCommand in project mycore by MyCoRe-Org.

the class MCRMetsCommands method addMetsFileForProjectID.

@MCRCommand(syntax = "add mets files for project id {0}", order = 30)
public static void addMetsFileForProjectID(String projectID) {
    MCRXMLMetadataManager manager = MCRXMLMetadataManager.instance();
    List<String> dervate_list = manager.listIDsForBase(projectID + "_derivate");
    for (String derivateID : dervate_list) {
        addMetsFileForDerivate(derivateID);
    }
}
Also used : MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) 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