Search in sources :

Example 36 with MCRCommand

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

the class MCRIFSCommands method checkDerivatesWithProjectIDInMCRFSNODES.

@MCRCommand(syntax = "check mcrfsnodes of derivates with project id {0}", help = "check the entries of MCRFSNODES with project ID {0} that the derivate exists")
public static void checkDerivatesWithProjectIDInMCRFSNODES(String project_id) {
    LOGGER.info("Start check of MCRFSNODES for derivates with project ID {}", project_id);
    if (project_id == null || project_id.length() == 0) {
        LOGGER.error("Project ID missed for check MCRFSNODES entries of derivates with project ID {0}");
        return;
    }
    MCRXMLMetadataManager mgr = MCRXMLMetadataManager.instance();
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<String> query = cb.createQuery(String.class);
    Root<MCRFSNODES> nodes = query.from(MCRFSNODES.class);
    AtomicInteger counter = new AtomicInteger();
    em.createQuery(query.distinct(true).select(nodes.get(MCRFSNODES_.owner)).where(cb.like(nodes.get(MCRFSNODES_.owner), project_id + "\\_%"))).getResultList().stream().peek(ignore -> counter.incrementAndGet()).map(MCRObjectID::getInstance).filter(derID -> {
        try {
            return !mgr.exists(derID);
        } catch (IOException e) {
            LOGGER.error("Error while checking existence of {}", derID, e);
            return true;
        }
    }).forEach(missingDerivate -> LOGGER.error("   !!!! Can't find MCRFSNODES entry {} as existing derivate", missingDerivate));
    LOGGER.info("Check done for {} entries", counter.get());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Transformer(javax.xml.transform.Transformer) Arrays(java.util.Arrays) Date(java.util.Date) StreamResult(javax.xml.transform.stream.StreamResult) FileTime(java.nio.file.attribute.FileTime) MCRStreamQuery(org.mycore.backend.jpa.MCRStreamQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRFSNODES(org.mycore.backend.hibernate.tables.MCRFSNODES) URI(java.net.URI) Method(java.lang.reflect.Method) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) ParameterExpression(javax.persistence.criteria.ParameterExpression) GregorianCalendar(java.util.GregorianCalendar) TimeZone(java.util.TimeZone) StandardOpenOption(java.nio.file.StandardOpenOption) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) MCREntityManagerProvider(org.mycore.backend.jpa.MCREntityManagerProvider) MCRUtils(org.mycore.common.MCRUtils) List(java.util.List) Attributes2Impl(org.xml.sax.ext.Attributes2Impl) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRFilesystemNode(org.mycore.datamodel.ifs.MCRFilesystemNode) SAXException(org.xml.sax.SAXException) MCRContentStoreFactory(org.mycore.datamodel.ifs.MCRContentStoreFactory) Session(org.hibernate.Session) MCRConfiguration(org.mycore.common.config.MCRConfiguration) TypedQuery(javax.persistence.TypedQuery) MCRException(org.mycore.common.MCRException) MessageFormat(java.text.MessageFormat) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) MCRFSNODES_(org.mycore.backend.hibernate.tables.MCRFSNODES_) Charset(java.nio.charset.Charset) MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRContentStore(org.mycore.datamodel.ifs.MCRContentStore) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) MCRCommandGroup(org.mycore.frontend.cli.annotation.MCRCommandGroup) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) Root(javax.persistence.criteria.Root) MCRFile(org.mycore.datamodel.ifs.MCRFile) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) NotDirectoryException(java.nio.file.NotDirectoryException) MCRHIBConnection(org.mycore.backend.hibernate.MCRHIBConnection) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) EntityManager(javax.persistence.EntityManager) OutputKeys(javax.xml.transform.OutputKeys) Field(java.lang.reflect.Field) File(java.io.File) NameFileComparator(org.apache.commons.io.comparator.NameFileComparator) TransformerHandler(javax.xml.transform.sax.TransformerHandler) LogManager(org.apache.logging.log4j.LogManager) EntityManager(javax.persistence.EntityManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRFSNODES(org.mycore.backend.hibernate.tables.MCRFSNODES) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 37 with MCRCommand

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

the class MCRIFSCommands method writeMissingFileReport.

@MCRCommand(syntax = "generate missing file report in directory {0}", help = "generates XML a report over all content stores about missing files and write it in directory {0}")
public static void writeMissingFileReport(String targetDirectory) throws IOException, SAXException, TransformerConfigurationException {
    File targetDir = getDirectory(targetDirectory);
    FSNodeChecker checker = new LocalFileExistChecker();
    writeReport(targetDir, checker);
}
Also used : MCRFile(org.mycore.datamodel.ifs.MCRFile) File(java.io.File) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 38 with MCRCommand

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

the class MCRIFSCommands method fixDirectorysOfDerivate.

@MCRCommand(syntax = "repair directory sizes of derivate {0}", help = "Fixes the directory sizes of a derivate.")
public static void fixDirectorysOfDerivate(String id) {
    MCRDirectory mcrDirectory = (MCRDirectory) MCRFilesystemNode.getRootNode(id);
    if (mcrDirectory == null) {
        throw new IllegalArgumentException(MessageFormat.format("Could not get root node for {0}", id));
    }
    fixDirectorySize(mcrDirectory);
}
Also used : MCRDirectory(org.mycore.datamodel.ifs.MCRDirectory) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 39 with MCRCommand

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

the class MCRTransferPackageCommands method _untar.

@MCRCommand(syntax = "_import transfer package untar {0}")
public static void _untar(String pathToTar) throws Exception {
    Path tar = Paths.get(pathToTar);
    Path targetDirectory = MCRTransferPackageUtil.getTargetDirectory(tar);
    LOGGER.info("Untar {} to {}...", pathToTar, targetDirectory);
    MCRUtils.untar(tar, targetDirectory);
}
Also used : Path(java.nio.file.Path) MCRCommand(org.mycore.frontend.cli.annotation.MCRCommand)

Example 40 with MCRCommand

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

the class MCRTransferPackageCommands method _importDerivate.

@MCRCommand(syntax = "_import transfer package derivate {0} from {1}")
public static void _importDerivate(String derivateId, String targetDirectoryPath) throws Exception {
    Path targetDirectory = Paths.get(targetDirectoryPath);
    MCRTransferPackageUtil.importDerivate(targetDirectory, derivateId);
}
Also used : Path(java.nio.file.Path) 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