Search in sources :

Example 1 with ThumbnailQueueBhv

use of org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv in project fess by codelibs.

the class ThumbnailManager method generate.

public int generate() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final List<String> idList = new ArrayList<>();
    final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
    thumbnailQueueBhv.selectList(cb -> {
        if (StringUtil.isBlank(fessConfig.getSchedulerTargetName())) {
            cb.query().setTarget_Equal(Constants.DEFAULT_JOB_TARGET);
        } else {
            cb.query().setTarget_InScope(Lists.newArrayList(Constants.DEFAULT_JOB_TARGET, fessConfig.getSchedulerTargetName()));
        }
        cb.query().addOrderBy_CreatedTime_Asc();
        cb.fetchFirst(fessConfig.getPageThumbnailQueueMaxFetchSizeAsInteger());
    }).forEach(entity -> {
        idList.add(entity.getId());
        final String generatorName = entity.getGenerator();
        try {
            final ThumbnailGenerator generator = ComponentUtil.getComponent(generatorName);
            final File outputFile = new File(baseDir, entity.getPath());
            final File noImageFile = new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX);
            if (!noImageFile.isFile() || System.currentTimeMillis() - noImageFile.lastModified() > noImageExpired) {
                if (noImageFile.isFile() && !noImageFile.delete()) {
                    logger.warn("Failed to delete " + noImageFile.getAbsolutePath());
                }
                if (!generator.generate(entity.getThumbnailId(), entity.getUrl(), outputFile)) {
                    new File(outputFile.getAbsolutePath() + NOIMAGE_FILE_SUFFIX).setLastModified(System.currentTimeMillis());
                } else {
                    long interval = fessConfig.getThumbnailGeneratorIntervalAsInteger().longValue();
                    if (interval > 0) {
                        Thread.sleep(interval);
                    }
                }
            } else if (logger.isDebugEnabled()) {
                logger.debug("No image file exists: " + noImageFile.getAbsolutePath());
            }
        } catch (final Exception e) {
            logger.warn("Failed to create thumbnail for " + entity, e);
        }
    });
    if (!idList.isEmpty()) {
        thumbnailQueueBhv.queryDelete(cb -> {
            cb.query().setId_InScope(idList);
        });
        thumbnailQueueBhv.refresh();
    }
    return idList.size();
}
Also used : ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) PreDestroy(javax.annotation.PreDestroy) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) Path(java.nio.file.Path) HttpSession(javax.servlet.http.HttpSession) Tuple4(org.codelibs.core.misc.Tuple4) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) IOException(java.io.IOException)

Example 2 with ThumbnailQueueBhv

use of org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv in project fess by codelibs.

the class ThumbnailManager method storeQueue.

protected void storeQueue(final List<Tuple4<String, String, String, String>> taskList) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String[] targets = fessConfig.getThumbnailGeneratorTargetsAsArray();
    final List<ThumbnailQueue> list = new ArrayList<>();
    taskList.stream().filter(entity -> entity != null).forEach(task -> {
        for (final String target : targets) {
            final ThumbnailQueue entity = new ThumbnailQueue();
            entity.setGenerator(task.getValue1());
            entity.setThumbnailId(task.getValue2());
            entity.setUrl(task.getValue3());
            entity.setPath(task.getValue4());
            entity.setTarget(target);
            entity.setCreatedBy(Constants.SYSTEM_USER);
            entity.setCreatedTime(systemHelper.getCurrentTimeAsLong());
            list.add(entity);
        }
    });
    taskList.clear();
    final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
    thumbnailQueueBhv.batchInsert(list);
}
Also used : ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LruHashMap(org.codelibs.core.collection.LruHashMap) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) PreDestroy(javax.annotation.PreDestroy) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) Path(java.nio.file.Path) HttpSession(javax.servlet.http.HttpSession) Tuple4(org.codelibs.core.misc.Tuple4) Logger(org.slf4j.Logger) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) SystemHelper(org.codelibs.fess.helper.SystemHelper) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 3 with ThumbnailQueueBhv

use of org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv in project fess by codelibs.

the class ThumbnailManager method generate.

public int generate(final ExecutorService executorService, final boolean cleanup) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final List<String> idList = new ArrayList<>();
    final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
    thumbnailQueueBhv.selectList(cb -> {
        if (StringUtil.isBlank(fessConfig.getSchedulerTargetName())) {
            cb.query().setTarget_Equal(Constants.DEFAULT_JOB_TARGET);
        } else {
            cb.query().setTarget_InScope(Lists.newArrayList(Constants.DEFAULT_JOB_TARGET, fessConfig.getSchedulerTargetName()));
        }
        cb.query().addOrderBy_CreatedTime_Asc();
        cb.fetchFirst(fessConfig.getPageThumbnailQueueMaxFetchSizeAsInteger());
    }).stream().map(entity -> {
        idList.add(entity.getId());
        if (!cleanup) {
            return executorService.submit(() -> process(fessConfig, entity));
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Removing thumbnail queue: {}", entity);
        }
        return null;
    }).filter(f -> f != null).forEach(f -> {
        try {
            f.get();
        } catch (final Exception e) {
            logger.warn("Failed to process a thumbnail generation.", e);
        }
    });
    if (!idList.isEmpty()) {
        thumbnailQueueBhv.queryDelete(cb -> {
            cb.query().setId_InScope(idList);
        });
        thumbnailQueueBhv.refresh();
    }
    return idList.size();
}
Also used : ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) ThreadUtil(org.codelibs.core.lang.ThreadUtil) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) PreDestroy(javax.annotation.PreDestroy) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) QueryBuilders(org.opensearch.index.query.QueryBuilders) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Tuple3(org.codelibs.core.misc.Tuple3) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) LogManager(org.apache.logging.log4j.LogManager) ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) FessSystemException(org.codelibs.fess.exception.FessSystemException) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 4 with ThumbnailQueueBhv

use of org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv in project fess by codelibs.

the class ThumbnailManager method storeQueue.

protected void storeQueue(final List<Tuple3<String, String, String>> taskList) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String[] targets = fessConfig.getThumbnailGeneratorTargetsAsArray();
    final List<ThumbnailQueue> list = new ArrayList<>();
    taskList.stream().filter(entity -> entity != null).forEach(task -> {
        for (final String target : targets) {
            final ThumbnailQueue entity = new ThumbnailQueue();
            entity.setGenerator(task.getValue1());
            entity.setThumbnailId(task.getValue2());
            entity.setPath(task.getValue3());
            entity.setTarget(target);
            entity.setCreatedBy(Constants.SYSTEM_USER);
            entity.setCreatedTime(systemHelper.getCurrentTimeAsLong());
            list.add(entity);
        }
    });
    taskList.clear();
    if (logger.isDebugEnabled()) {
        logger.debug("Storing {} thumbnail tasks.", list.size());
    }
    final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
    thumbnailQueueBhv.batchInsert(list);
}
Also used : ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) ThreadUtil(org.codelibs.core.lang.ThreadUtil) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) PreDestroy(javax.annotation.PreDestroy) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Lists(com.google.common.collect.Lists) Map(java.util.Map) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) QueryBuilders(org.opensearch.index.query.QueryBuilders) FileVisitor(java.nio.file.FileVisitor) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Tuple3(org.codelibs.core.misc.Tuple3) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) PostConstruct(javax.annotation.PostConstruct) LogManager(org.apache.logging.log4j.LogManager) ThumbnailQueueBhv(org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv) SystemHelper(org.codelibs.fess.helper.SystemHelper) ArrayList(java.util.ArrayList) ThumbnailQueue(org.codelibs.fess.es.config.exentity.ThumbnailQueue) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Aggregations

Lists (com.google.common.collect.Lists)4 File (java.io.File)4 IOException (java.io.IOException)4 FileVisitResult (java.nio.file.FileVisitResult)4 FileVisitor (java.nio.file.FileVisitor)4 Files (java.nio.file.Files)4 Path (java.nio.file.Path)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 BlockingQueue (java.util.concurrent.BlockingQueue)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 TimeUnit (java.util.concurrent.TimeUnit)4 PostConstruct (javax.annotation.PostConstruct)4 PreDestroy (javax.annotation.PreDestroy)4 StringUtil (org.codelibs.core.lang.StringUtil)4 Constants (org.codelibs.fess.Constants)4 ThumbnailQueueBhv (org.codelibs.fess.es.config.exbhv.ThumbnailQueueBhv)4