Search in sources :

Example 1 with FailureUrl

use of org.codelibs.fess.es.config.exentity.FailureUrl in project fess by codelibs.

the class FailureUrlService method store.

public void store(final CrawlingConfig crawlingConfig, final String errorName, final String url, final Throwable e) {
    if (e instanceof ContainerNotAvailableException) {
        return;
    }
    final FailureUrlBhv bhv = ComponentUtil.getComponent(FailureUrlBhv.class);
    final FailureUrl failureUrl = bhv.selectEntity(cb -> {
        cb.query().setUrl_Equal(url);
        if (crawlingConfig != null) {
            cb.query().setConfigId_Equal(crawlingConfig.getConfigId());
        }
    }).map(entity -> {
        entity.setErrorCount(entity.getErrorCount() + 1);
        return entity;
    }).orElseGet(() -> {
        final FailureUrl entity = new FailureUrl();
        entity.setErrorCount(1);
        entity.setUrl(url);
        if (crawlingConfig != null) {
            entity.setConfigId(crawlingConfig.getConfigId());
        }
        return entity;
    });
    failureUrl.setErrorName(errorName);
    failureUrl.setErrorLog(StringUtils.abbreviate(getStackTrace(e), 4000));
    failureUrl.setLastAccessTime(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
    failureUrl.setThreadName(Thread.currentThread().getName());
    bhv.insertOrUpdate(failureUrl, op -> {
        op.setRefreshPolicy(Constants.TRUE);
    });
}
Also used : ContainerNotAvailableException(org.codelibs.fess.exception.ContainerNotAvailableException) PrintWriter(java.io.PrintWriter) BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) FailureUrlBhv(org.codelibs.fess.es.config.exbhv.FailureUrlBhv) ListResultBean(org.dbflute.cbean.result.ListResultBean) OptionalEntity(org.dbflute.optional.OptionalEntity) ContainerNotAvailableException(org.codelibs.fess.exception.ContainerNotAvailableException) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) StringUtils(org.apache.commons.lang3.StringUtils) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) ArrayList(java.util.ArrayList) List(java.util.List) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) FailureUrlCB(org.codelibs.fess.es.config.cbean.FailureUrlCB) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SystemHelper(org.codelibs.fess.helper.SystemHelper) StringBuilderWriter(org.apache.commons.io.output.StringBuilderWriter) FailureUrlPager(org.codelibs.fess.app.pager.FailureUrlPager) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl) FailureUrlBhv(org.codelibs.fess.es.config.exbhv.FailureUrlBhv) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl)

Example 2 with FailureUrl

use of org.codelibs.fess.es.config.exentity.FailureUrl in project fess by codelibs.

the class ApiAdminFailureurlAction method logs.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/failureurl/logs
// POST /api/admin/failureurl/logs
@Execute
public JsonResponse<ApiResult> logs(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final FailureUrlPager pager = copyBeanToNewBean(body, FailureUrlPager.class);
    final List<FailureUrl> list = failureUrlService.getFailureUrlList(pager);
    return asJson(new ApiResult.ApiLogsResponse<EditBody>().logs(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : FailureUrlPager(org.codelibs.fess.app.pager.FailureUrlPager) ApiResult(org.codelibs.fess.app.web.api.ApiResult) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl) Execute(org.lastaflute.web.Execute)

Example 3 with FailureUrl

use of org.codelibs.fess.es.config.exentity.FailureUrl in project fess by codelibs.

the class ApiAdminFailureurlAction method delete$all.

// DELETE /api/admin/failureurl/all
@Execute
public JsonResponse<ApiResult> delete$all() {
    try {
        failureUrlService.deleteAll(failureUrlPager);
        failureUrlPager.clear();
        saveInfo(messages -> messages.addSuccessFailureUrlDeleteAll(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResponse().status(Status.OK).result());
}
Also used : 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) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) Execute(org.lastaflute.web.Execute) FailureUrlPager(org.codelibs.fess.app.pager.FailureUrlPager) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) FailureUrlService(org.codelibs.fess.app.service.FailureUrlService) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) Execute(org.lastaflute.web.Execute)

Example 4 with FailureUrl

use of org.codelibs.fess.es.config.exentity.FailureUrl in project fess by codelibs.

the class FailureUrlService method getExcludedUrlList.

public List<String> getExcludedUrlList(final String configId) {
    final int failureCount = fessConfig.getFailureCountThreshold();
    final String ignoreFailureType = fessConfig.getIgnoreFailureType();
    if (failureCount < 0) {
        return Collections.emptyList();
    }
    final int count = failureCount;
    final ListResultBean<FailureUrl> list = failureUrlBhv.selectList(cb -> {
        cb.query().setConfigId_Equal(configId);
        cb.query().setErrorCount_GreaterEqual(count);
        cb.fetchFirst(fessConfig.getPageFailureUrlMaxFetchSizeAsInteger());
    });
    if (list.isEmpty()) {
        return Collections.emptyList();
    }
    Pattern pattern = null;
    if (StringUtil.isNotBlank(ignoreFailureType)) {
        pattern = Pattern.compile(ignoreFailureType);
    }
    final List<String> urlList = new ArrayList<>();
    for (final FailureUrl failureUrl : list) {
        if (pattern != null) {
            if (!pattern.matcher(failureUrl.getErrorName()).matches()) {
                urlList.add(failureUrl.getUrl());
            }
        } else {
            urlList.add(failureUrl.getUrl());
        }
    }
    return urlList;
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) FailureUrl(org.codelibs.fess.es.config.exentity.FailureUrl)

Aggregations

FailureUrl (org.codelibs.fess.es.config.exentity.FailureUrl)4 FailureUrlPager (org.codelibs.fess.app.pager.FailureUrlPager)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 Resource (javax.annotation.Resource)2 ApiResult (org.codelibs.fess.app.web.api.ApiResult)2 Execute (org.lastaflute.web.Execute)2 PrintWriter (java.io.PrintWriter)1 Collections (java.util.Collections)1 Collectors (java.util.stream.Collectors)1 StringBuilderWriter (org.apache.commons.io.output.StringBuilderWriter)1 StringUtils (org.apache.commons.lang3.StringUtils)1 BeanUtil (org.codelibs.core.beans.util.BeanUtil)1 StringUtil (org.codelibs.core.lang.StringUtil)1 Constants (org.codelibs.fess.Constants)1 FailureUrlService (org.codelibs.fess.app.service.FailureUrlService)1 ApiLogResponse (org.codelibs.fess.app.web.api.ApiResult.ApiLogResponse)1 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)1 Status (org.codelibs.fess.app.web.api.ApiResult.Status)1