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());
}
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());
}
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());
}
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());
}
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();
}
Aggregations