Search in sources :

Example 1 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminAccesstokenAction method post$setting.

// POST /api/admin/accesstoken/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final AccessToken accessToken = getAccessToken(body).map(entity -> {
        try {
            accessTokenService.store(entity);
        } 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(accessToken.getId()).created(false).status(Status.OK).result());
}
Also used : AccessTokenPager(org.codelibs.fess.app.pager.AccessTokenPager) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) AccessTokenService(org.codelibs.fess.app.service.AccessTokenService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) 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) AdminAccesstokenAction(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) ApiConfigsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigsResponse) AdminAccesstokenAction.getAccessToken(org.codelibs.fess.app.web.admin.accesstoken.AdminAccesstokenAction.getAccessToken) AccessToken(org.codelibs.fess.es.config.exentity.AccessToken) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 2 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDuplicatehostAction method post$setting.

// POST /api/admin/duplicatehost/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
        try {
            duplicateHostService.store(entity);
        } 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(duplicateHost.getId()).created(false).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 3 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminElevatewordAction method post$setting.

// POST /api/admin/elevateword/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final ElevateWord entity = getElevateWord(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
        });
        return null;
    });
    try {
        elevateWordService.store(entity);
        suggestHelper.deleteAllElevateWord();
        suggestHelper.storeAllElevateWords();
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).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 4 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDictMappingAction method put$setting.

// PUT /api/admin/dict/mapping/setting/{dictId}
@Execute
public JsonResponse<ApiResult> put$setting(final String dictId, final CreateBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final CharMappingItem entity = new AdminDictMappingAction().createCharMappingItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    charMappingService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(true).status(ApiResult.Status.OK).result());
}
Also used : CharMappingItem(org.codelibs.fess.dict.mapping.CharMappingItem) UploadForm(org.codelibs.fess.app.web.admin.dict.mapping.UploadForm) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) CharMappingPager(org.codelibs.fess.app.pager.CharMappingPager) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) CharMappingItem(org.codelibs.fess.dict.mapping.CharMappingItem) File(java.io.File) CharMappingFile(org.codelibs.fess.dict.mapping.CharMappingFile) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) CharMappingService(org.codelibs.fess.app.service.CharMappingService) AdminDictMappingAction(org.codelibs.fess.app.web.admin.dict.mapping.AdminDictMappingAction) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminDictMappingAction(org.codelibs.fess.app.web.admin.dict.mapping.AdminDictMappingAction) Execute(org.lastaflute.web.Execute)

Example 5 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDictMappingAction method post$upload.

// POST /api/admin/dict/mapping/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
    form.dictId = dictId;
    validateApi(form, messages -> {
    });
    final CharMappingFile file = charMappingService.getCharMappingFile(form.dictId).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
        return null;
    });
    try (InputStream inputStream = form.charMappingFile.getInputStream()) {
        file.update(inputStream);
    } catch (final Throwable e) {
        e.printStackTrace();
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
    }
    return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
Also used : UploadForm(org.codelibs.fess.app.web.admin.dict.mapping.UploadForm) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) CharMappingPager(org.codelibs.fess.app.pager.CharMappingPager) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) CharMappingItem(org.codelibs.fess.dict.mapping.CharMappingItem) File(java.io.File) CharMappingFile(org.codelibs.fess.dict.mapping.CharMappingFile) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) CharMappingService(org.codelibs.fess.app.service.CharMappingService) AdminDictMappingAction(org.codelibs.fess.app.web.admin.dict.mapping.AdminDictMappingAction) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) InputStream(java.io.InputStream) CharMappingFile(org.codelibs.fess.dict.mapping.CharMappingFile) Execute(org.lastaflute.web.Execute)

Aggregations

Resource (javax.annotation.Resource)65 ApiResult (org.codelibs.fess.app.web.api.ApiResult)65 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)65 Execute (org.lastaflute.web.Execute)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 WebConfigService (org.codelibs.fess.app.service.WebConfigService)6 ApiErrorResponse (org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse)6