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();
}
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);
}
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();
}
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);
}
Aggregations