Search in sources :

Example 1 with MCRFSNODES_

use of org.mycore.backend.hibernate.tables.MCRFSNODES_ 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)

Aggregations

BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 NotDirectoryException (java.nio.file.NotDirectoryException)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 FileTime (java.nio.file.attribute.FileTime)1 MessageFormat (java.text.MessageFormat)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1