use of org.codelibs.fess.es.config.exentity.CrawlingInfo in project fess by codelibs.
the class CrawlingInfoService method exportCsv.
public void exportCsv(final Writer writer) {
final CsvConfig cfg = new CsvConfig(',', '"', '"');
cfg.setEscapeDisabled(false);
cfg.setQuoteDisabled(false);
@SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
try {
final List<String> list = new ArrayList<>();
list.add("SessionId");
list.add("SessionCreatedTime");
list.add("Key");
list.add("Value");
list.add("CreatedTime");
csvWriter.writeValues(list);
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
crawlingInfoParamBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<CrawlingInfoParam>() {
@Override
public void handle(final CrawlingInfoParam entity) {
final List<String> list = new ArrayList<>();
entity.getCrawlingInfo().ifPresent(crawlingInfo -> {
addToList(list, crawlingInfo.getSessionId());
addToList(list, crawlingInfo.getCreatedTime());
});
// TODO
if (!entity.getCrawlingInfo().isPresent()) {
addToList(list, "");
addToList(list, "");
}
addToList(list, entity.getKey());
addToList(list, entity.getValue());
addToList(list, entity.getCreatedTime());
try {
csvWriter.writeValues(list);
} catch (final IOException e) {
logger.warn("Failed to write a crawling session info: {}", entity, e);
}
}
private void addToList(final List<String> list, final Object value) {
if (value == null) {
list.add(StringUtil.EMPTY);
} else if (value instanceof LocalDateTime) {
list.add(((LocalDateTime) value).format(formatter));
} else {
list.add(value.toString());
}
}
});
csvWriter.flush();
} catch (final IOException e) {
logger.warn("Failed to write a crawling session info.", e);
}
}
use of org.codelibs.fess.es.config.exentity.CrawlingInfo in project fess by codelibs.
the class ApiAdminCrawlinginfoAction method logs.
// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/crawlinginfo/logs
// POST /api/admin/crawlinginfo/logs
@Execute
public JsonResponse<ApiResult> logs(final SearchBody body) {
validateApi(body, messages -> {
});
final CrawlingInfoPager pager = copyBeanToNewBean(body, CrawlingInfoPager.class);
final List<CrawlingInfo> list = crawlingInfoService.getCrawlingInfoList(pager);
return asJson(new ApiResult.ApiLogsResponse<EditBody>().logs(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
use of org.codelibs.fess.es.config.exentity.CrawlingInfo in project fess by codelibs.
the class ApiAdminCrawlinginfoAction method delete$all.
// DELETE /api/admin/crawlinginfo/all
@Execute
public JsonResponse<ApiResult> delete$all() {
try {
crawlingInfoService.deleteOldSessions(processHelper.getRunningSessionIdSet());
saveInfo(messages -> messages.addSuccessCrawlingInfoDeleteAll(GLOBAL));
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResponse().status(Status.OK).result());
}
Aggregations