Search in sources :

Example 61 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult in project fess by codelibs.

the class ApiAdminDuplicatehostAction method put$setting.

// PUT /api/admin/duplicatehost/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
        try {
            duplicateHostService.store(entity);
        } catch (final Exception e) {
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(duplicateHost.getId()).created(true).status(Status.OK).result());
}
Also used : DuplicateHostPager(org.codelibs.fess.app.pager.DuplicateHostPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) DuplicateHostService(org.codelibs.fess.app.service.DuplicateHostService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) Execute(org.lastaflute.web.Execute)

Example 62 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult in project fess by codelibs.

the class ApiAdminElevatewordAction method put$setting.

// PUT /api/admin/elevateword/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final ElevateWord entity = getElevateWord(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        elevateWordService.store(entity);
        suggestHelper.addElevateWord(entity.getSuggestWord(), entity.getReading(), entity.getLabelTypeValues(), entity.getPermissions(), entity.getBoost());
    } 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 : FessSystemException(org.codelibs.fess.exception.FessSystemException) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ApiResult(org.codelibs.fess.app.web.api.ApiResult) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) OutputStreamWriter(java.io.OutputStreamWriter) Path(java.nio.file.Path) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ElevateWordService(org.codelibs.fess.app.service.ElevateWordService) Files(java.nio.file.Files) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) BufferedWriter(java.io.BufferedWriter) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Reader(java.io.Reader) JsonResponse(org.lastaflute.web.response.JsonResponse) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) UploadForm(org.codelibs.fess.app.web.admin.elevateword.UploadForm) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AdminElevatewordAction.getElevateWord(org.codelibs.fess.app.web.admin.elevateword.AdminElevatewordAction.getElevateWord) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BufferedReader(java.io.BufferedReader) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminElevatewordAction.getElevateWord(org.codelibs.fess.app.web.admin.elevateword.AdminElevatewordAction.getElevateWord) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute)

Example 63 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult in project fess by codelibs.

the class ApiAdminElevatewordAction method post$upload.

// POST /api/admin/elevateword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
    validateApi(body, messages -> {
    });
    new Thread(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(body.elevateWordFile.getInputStream(), getCsvEncoding()))) {
            elevateWordService.importCsv(reader);
            suggestHelper.storeAllElevateWords();
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    }).start();
    return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FessSystemException(org.codelibs.fess.exception.FessSystemException) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute)

Example 64 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult in project fess by codelibs.

the class ApiAdminElevatewordAction method settings.

// GET /api/admin/elevateword
// POST /api/admin/elevateword
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final ElevateWordPager pager = copyBeanToNewBean(body, ElevateWordPager.class);
    final List<ElevateWord> list = elevateWordService.getElevateWordList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminElevatewordAction.getElevateWord(org.codelibs.fess.app.web.admin.elevateword.AdminElevatewordAction.getElevateWord) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) Execute(org.lastaflute.web.Execute)

Example 65 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult in project fess by codelibs.

the class ApiAdminElevatewordAction method get$setting.

// GET /api/admin/elevateword/{id}
@Execute
public JsonResponse<ApiResult> get$setting(final String id) {
    final ElevateWord entity = elevateWordService.getElevateWord(id).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
        return null;
    });
    final EditBody body = createEditBody(entity);
    final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
    body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
    return asJson(new ApiResult.ApiConfigResponse().setting(body).status(ApiResult.Status.OK).result());
}
Also used : FessSystemException(org.codelibs.fess.exception.FessSystemException) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ApiResult(org.codelibs.fess.app.web.api.ApiResult) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) OutputStreamWriter(java.io.OutputStreamWriter) Path(java.nio.file.Path) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) ElevateWordService(org.codelibs.fess.app.service.ElevateWordService) Files(java.nio.file.Files) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) BufferedWriter(java.io.BufferedWriter) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Reader(java.io.Reader) JsonResponse(org.lastaflute.web.response.JsonResponse) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) UploadForm(org.codelibs.fess.app.web.admin.elevateword.UploadForm) List(java.util.List) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AdminElevatewordAction.getElevateWord(org.codelibs.fess.app.web.admin.elevateword.AdminElevatewordAction.getElevateWord) Writer(java.io.Writer) Execute(org.lastaflute.web.Execute) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) BufferedReader(java.io.BufferedReader) SuggestHelper(org.codelibs.fess.helper.SuggestHelper) InputStream(java.io.InputStream) AdminElevatewordAction.getElevateWord(org.codelibs.fess.app.web.admin.elevateword.AdminElevatewordAction.getElevateWord) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) StringUtil(org.codelibs.core.lang.StringUtil) Execute(org.lastaflute.web.Execute)

Aggregations

ApiResult (org.codelibs.fess.app.web.api.ApiResult)88 Execute (org.lastaflute.web.Execute)88 Resource (javax.annotation.Resource)65 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)65 JsonResponse (org.lastaflute.web.response.JsonResponse)65 CrudMode (org.codelibs.fess.app.web.CrudMode)63 Collectors (java.util.stream.Collectors)61 List (java.util.List)43 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)31 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 InputStream (java.io.InputStream)23 StreamResponse (org.lastaflute.web.response.StreamResponse)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 File (java.io.File)18 Constants (org.codelibs.fess.Constants)12 StringUtil (org.codelibs.core.lang.StringUtil)9 ComponentUtil (org.codelibs.fess.util.ComponentUtil)9 BufferedReader (java.io.BufferedReader)7 InputStreamReader (java.io.InputStreamReader)7