Search in sources :

Example 1 with BadWord

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

the class ApiAdminBadwordAction method put$setting.

// PUT /api/admin/badword/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final BadWord entity = getBadWord(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        badWordService.store(entity);
        suggestHelper.addBadWord(entity.getSuggestWord(), false);
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(true).status(ApiResult.Status.OK).result());
}
Also used : BadWordService(org.codelibs.fess.app.service.BadWordService) FessSystemException(org.codelibs.fess.exception.FessSystemException) UploadForm(org.codelibs.fess.app.web.admin.badword.UploadForm) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) BadWord(org.codelibs.fess.es.config.exentity.BadWord) CommonPoolUtil(org.codelibs.core.concurrent.CommonPoolUtil) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) OutputStreamWriter(java.io.OutputStreamWriter) Path(java.nio.file.Path) Files(java.nio.file.Files) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) BufferedWriter(java.io.BufferedWriter) Resource(javax.annotation.Resource) Reader(java.io.Reader) JsonResponse(org.lastaflute.web.response.JsonResponse) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) BufferedReader(java.io.BufferedReader) BadWordPager(org.codelibs.fess.app.pager.BadWordPager) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) BadWord(org.codelibs.fess.es.config.exentity.BadWord) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) FessSystemException(org.codelibs.fess.exception.FessSystemException) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 2 with BadWord

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

the class ApiAdminBadwordAction method post$setting.

// POST /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final BadWord badWord = getBadWord(body).map(entity -> {
        try {
            badWordService.store(entity);
            suggestHelper.storeAllBadWords(false);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(badWord.getId()).created(false).status(Status.OK).result());
}
Also used : BadWordService(org.codelibs.fess.app.service.BadWordService) FessSystemException(org.codelibs.fess.exception.FessSystemException) UploadForm(org.codelibs.fess.app.web.admin.badword.UploadForm) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) BadWord(org.codelibs.fess.es.config.exentity.BadWord) CommonPoolUtil(org.codelibs.core.concurrent.CommonPoolUtil) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) OutputStreamWriter(java.io.OutputStreamWriter) Path(java.nio.file.Path) Files(java.nio.file.Files) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) BufferedWriter(java.io.BufferedWriter) Resource(javax.annotation.Resource) Reader(java.io.Reader) JsonResponse(org.lastaflute.web.response.JsonResponse) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) BufferedReader(java.io.BufferedReader) BadWordPager(org.codelibs.fess.app.pager.BadWordPager) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) BadWord(org.codelibs.fess.es.config.exentity.BadWord) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute)

Example 3 with BadWord

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

the class ApiAdminBadwordAction method settings.

// GET /api/admin/badword/settings
// POST /api/admin/badword/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final BadWordPager pager = copyBeanToNewBean(body, BadWordPager.class);
    final List<BadWord> list = badWordService.getBadWordList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) BadWord(org.codelibs.fess.es.config.exentity.BadWord) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) BadWordPager(org.codelibs.fess.app.pager.BadWordPager) Execute(org.lastaflute.web.Execute)

Example 4 with BadWord

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

the class ApiAdminBadwordAction method get$setting.

// GET /api/admin/badword/{id}
@Execute
public JsonResponse<ApiResult> get$setting(final String id) {
    final BadWord entity = badWordService.getBadWord(id).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
        return null;
    });
    final EditBody body = createEditBody(entity);
    return asJson(new ApiResult.ApiConfigResponse().setting(body).status(ApiResult.Status.OK).result());
}
Also used : BadWord(org.codelibs.fess.es.config.exentity.BadWord) AdminBadwordAction.getBadWord(org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord) Execute(org.lastaflute.web.Execute)

Example 5 with BadWord

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

the class SuggestHelper method storeAllBadWords.

public void storeAllBadWords(final boolean apply) {
    deleteAllBadWords();
    final List<BadWord> list = ComponentUtil.getComponent(BadWordBhv.class).selectList(cb -> {
        cb.query().matchAll();
        cb.fetchFirst(ComponentUtil.getFessConfig().getPageBadWordMaxFetchSizeAsInteger());
    });
    for (final BadWord badWord : list) {
        final String word = badWord.getSuggestWord();
        suggester.indexer().addBadWord(word, apply);
    }
    refresh();
}
Also used : BadWord(org.codelibs.fess.es.config.exentity.BadWord) BadWordBhv(org.codelibs.fess.es.config.exbhv.BadWordBhv)

Aggregations

BadWord (org.codelibs.fess.es.config.exentity.BadWord)8 List (java.util.List)4 BadWordPager (org.codelibs.fess.app.pager.BadWordPager)4 AdminBadwordAction.getBadWord (org.codelibs.fess.app.web.admin.badword.AdminBadwordAction.getBadWord)4 Execute (org.lastaflute.web.Execute)4 Reader (java.io.Reader)3 Writer (java.io.Writer)3 Resource (javax.annotation.Resource)3 ApiResult (org.codelibs.fess.app.web.api.ApiResult)3 ComponentUtil (org.codelibs.fess.util.ComponentUtil)3 CsvConfig (com.orangesignal.csv.CsvConfig)2 CsvWriter (com.orangesignal.csv.CsvWriter)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2