use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ViewHelper method getCachedFacetResponse.
public FacetResponse getCachedFacetResponse(final String query) {
final OptionalThing<FessUserBean> userBean = ComponentUtil.getComponent(FessLoginAssist.class).getSavedUserBean();
final String permissionKey = userBean.map(user -> StreamUtil.stream(user.getPermissions()).get(stream -> stream.sorted().distinct().collect(Collectors.joining("\n")))).orElse(StringUtil.EMPTY);
try {
return facetCache.get(query + "\n" + permissionKey, () -> {
final SearchHelper searchHelper = ComponentUtil.getSearchHelper();
final SearchForm params = new SearchForm() {
@Override
public int getPageSize() {
return 0;
}
@Override
public int getStartPosition() {
return 0;
}
};
params.q = query;
final SearchRenderData data = new SearchRenderData();
searchHelper.search(params, data, userBean);
if (logger.isDebugEnabled()) {
logger.debug("loaded facet data: {}", data);
}
return data.getFacetResponse();
});
} catch (final ExecutionException e) {
throw new FessSystemException("Cannot load facet from cache.", e);
}
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ViewHelper method writeContent.
protected StreamResponse writeContent(final String configId, final String url, final CrawlerClient client) {
final StreamResponse response = new StreamResponse(StringUtil.EMPTY);
final ResponseData responseData = client.execute(RequestDataBuilder.newRequestData().get().url(url).build());
if (responseData.getHttpStatusCode() == 404) {
response.httpStatus(responseData.getHttpStatusCode());
CloseableUtil.closeQuietly(responseData);
return response;
}
writeFileName(response, responseData);
writeContentType(response, responseData);
writeNoCache(response, responseData);
response.stream(out -> {
try (final InputStream is = new BufferedInputStream(responseData.getResponseBody())) {
out.write(is);
} catch (final IOException e) {
if (!(e.getCause() instanceof ClientAbortException)) {
throw new FessSystemException("Failed to write a content. configId: " + configId + ", url: " + url, e);
}
} finally {
CloseableUtil.closeQuietly(responseData);
}
if (logger.isDebugEnabled()) {
logger.debug("Finished to write {}", url);
}
});
return response;
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class CrawlingInfoHelper method store.
public synchronized void store(final String sessionId, final boolean create) {
CrawlingInfo crawlingInfo = create ? null : getCrawlingInfoService().getLast(sessionId);
if (crawlingInfo == null) {
crawlingInfo = new CrawlingInfo(sessionId);
try {
getCrawlingInfoService().store(crawlingInfo);
} catch (final Exception e) {
throw new FessSystemException("No crawling session.", e);
}
}
if (infoMap != null) {
final List<CrawlingInfoParam> crawlingInfoParamList = new ArrayList<>();
for (final Map.Entry<String, String> entry : infoMap.entrySet()) {
final CrawlingInfoParam crawlingInfoParam = new CrawlingInfoParam();
crawlingInfoParam.setCrawlingInfoId(crawlingInfo.getId());
crawlingInfoParam.setKey(entry.getKey());
crawlingInfoParam.setValue(entry.getValue());
crawlingInfoParamList.add(crawlingInfoParam);
}
getCrawlingInfoService().storeInfo(crawlingInfoParamList);
}
infoMap = null;
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ProcessHelper method startProcess.
public synchronized JobProcess startProcess(final String sessionId, final List<String> cmdList, final Consumer<ProcessBuilder> pbCall) {
final ProcessBuilder pb = new ProcessBuilder(cmdList);
pbCall.accept(pb);
destroyProcess(sessionId);
JobProcess jobProcess;
try {
jobProcess = new JobProcess(pb.start());
destroyProcess(sessionId, runningProcessMap.putIfAbsent(sessionId, jobProcess));
return jobProcess;
} catch (final IOException e) {
throw new FessSystemException("Crawler Process terminated.", e);
}
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class ViewHelper method asContentResponse.
public StreamResponse asContentResponse(final Map<String, Object> doc) {
if (logger.isDebugEnabled()) {
logger.debug("writing the content of: {}", doc);
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final CrawlingConfigHelper crawlingConfigHelper = ComponentUtil.getCrawlingConfigHelper();
final String configId = DocumentUtil.getValue(doc, fessConfig.getIndexFieldConfigId(), String.class);
if (configId == null) {
throw new FessSystemException("configId is null.");
}
if (configId.length() < 2) {
throw new FessSystemException("Invalid configId: " + configId);
}
final CrawlingConfig config = crawlingConfigHelper.getCrawlingConfig(configId);
if (config == null) {
throw new FessSystemException("No crawlingConfig: " + configId);
}
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
final CrawlerClientFactory crawlerClientFactory = config.initializeClientFactory(() -> ComponentUtil.getComponent(CrawlerClientFactory.class));
final CrawlerClient client = crawlerClientFactory.getClient(url);
if (client == null) {
throw new FessSystemException("No CrawlerClient: " + configId + ", url: " + url);
}
return writeContent(configId, url, client);
}
Aggregations