Search in sources :

Example 56 with ApiResult

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

the class ApiAdminGroupAction method put$setting.

// PUT /api/admin/group/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final Group entity = getGroup(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        groupService.store(entity);
        saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
    } 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 : GroupService(org.codelibs.fess.app.service.GroupService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) GroupPager(org.codelibs.fess.app.pager.GroupPager) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Execute(org.lastaflute.web.Execute) Group(org.codelibs.fess.es.user.exentity.Group) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Group(org.codelibs.fess.es.user.exentity.Group) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 57 with ApiResult

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

the class ApiAdminKeymatchAction method put$setting.

// PUT /api/admin/keymatch/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
        try {
            keyMatchService.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(keyMatch.getId()).created(true).status(Status.OK).result());
}
Also used : 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) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 58 with ApiResult

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

the class ApiAdminKeymatchAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/keymatch/settings
// POST /api/admin/keymatch/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final KeyMatchPager pager = copyBeanToNewBean(body, KeyMatchPager.class);
    final List<KeyMatch> list = keyMatchService.getKeyMatchList(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) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) Execute(org.lastaflute.web.Execute)

Example 59 with ApiResult

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

the class ApiAdminBadwordAction method post$upload.

// POST /api/admin/badword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
    validateApi(body, messages -> {
    });
    new Thread(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(body.badWordFile.getInputStream(), getCsvEncoding()))) {
            badWordService.importCsv(reader);
            suggestHelper.storeAllBadWords();
        } 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 60 with ApiResult

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

the class ApiAdminDuplicatehostAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/duplicatehost/settings
// POST /api/admin/duplicatehost/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final DuplicateHostPager pager = copyBeanToNewBean(body, DuplicateHostPager.class);
    final List<DuplicateHost> list = duplicateHostService.getDuplicateHostList(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) DuplicateHostPager(org.codelibs.fess.app.pager.DuplicateHostPager) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) 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