Search in sources :

Example 6 with CrawlingInfo

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);
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) CrawlingInfoBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoBhv) ListResultBean(org.dbflute.cbean.result.ListResultBean) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) DateFormat(java.text.DateFormat) CrawlingInfoPager(org.codelibs.fess.app.pager.CrawlingInfoPager) OptionalEntity(org.dbflute.optional.OptionalEntity) CrawlingInfoParamBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoParamBhv) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) CoreLibConstants(org.codelibs.core.CoreLibConstants) Collectors(java.util.stream.Collectors) CrawlingInfoCB(org.codelibs.fess.es.config.cbean.CrawlingInfoCB) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) Writer(java.io.Writer) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CsvReader(com.orangesignal.csv.CsvReader) LocalDateTime(java.time.LocalDateTime) CsvWriter(com.orangesignal.csv.CsvWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig) DateTimeFormatter(java.time.format.DateTimeFormatter) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam)

Example 7 with CrawlingInfo

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());
}
Also used : CrawlingInfoPager(org.codelibs.fess.app.pager.CrawlingInfoPager) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 8 with CrawlingInfo

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());
}
Also used : CrawlingInfoPager(org.codelibs.fess.app.pager.CrawlingInfoPager) ProcessHelper(org.codelibs.fess.helper.ProcessHelper) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiLogResponse(org.codelibs.fess.app.web.api.ApiResult.ApiLogResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) CrawlingInfoService(org.codelibs.fess.app.service.CrawlingInfoService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) Execute(org.lastaflute.web.Execute)

Aggregations

CrawlingInfo (org.codelibs.fess.es.config.exentity.CrawlingInfo)8 ArrayList (java.util.ArrayList)4 CrawlingInfoPager (org.codelibs.fess.app.pager.CrawlingInfoPager)4 FessSystemException (org.codelibs.fess.exception.FessSystemException)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 CrawlingInfoParam (org.codelibs.fess.es.config.exentity.CrawlingInfoParam)3 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)3 CsvConfig (com.orangesignal.csv.CsvConfig)2 CsvReader (com.orangesignal.csv.CsvReader)2 CsvWriter (com.orangesignal.csv.CsvWriter)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Writer (java.io.Writer)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2