Search in sources :

Example 61 with JsonResponse

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

the class ApiAdminDataconfigAction method put$setting.

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

Example 62 with JsonResponse

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

the class ApiAdminDictKuromojiAction method get$settings.

// GET /api/admin/dict/kuromoji/settings/{dictId}
@Execute
public JsonResponse<ApiResult> get$settings(final String dictId, final SearchBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    final KuromojiPager pager = copyBeanToNewBean(body, KuromojiPager.class);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(kuromojiService.getKuromojiList(body.dictId, pager).stream().map(protwordsItem -> createEditBody(protwordsItem, dictId)).collect(Collectors.toList())).status(ApiResult.Status.OK).result());
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) KuromojiItem(org.codelibs.fess.dict.kuromoji.KuromojiItem) StreamResponse(org.lastaflute.web.response.StreamResponse) KuromojiPager(org.codelibs.fess.app.pager.KuromojiPager) CrudMode(org.codelibs.fess.app.web.CrudMode) KuromojiFile(org.codelibs.fess.dict.kuromoji.KuromojiFile) Execute(org.lastaflute.web.Execute) AdminDictKuromojiAction.createKuromojiItem(org.codelibs.fess.app.web.admin.dict.kuromoji.AdminDictKuromojiAction.createKuromojiItem) KuromojiService(org.codelibs.fess.app.service.KuromojiService) InputStream(java.io.InputStream) UploadForm(org.codelibs.fess.app.web.admin.dict.kuromoji.UploadForm) KuromojiPager(org.codelibs.fess.app.pager.KuromojiPager) Execute(org.lastaflute.web.Execute)

Example 63 with JsonResponse

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

the class ApiAdminDictKuromojiAction method post$upload.

// POST /api/admin/dict/kuromoji/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
    form.dictId = dictId;
    validateApi(form, messages -> {
    });
    final KuromojiFile file = kuromojiService.getKuromojiFile(form.dictId).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
        return null;
    });
    try (InputStream inputStream = form.kuromojiFile.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 : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) KuromojiItem(org.codelibs.fess.dict.kuromoji.KuromojiItem) StreamResponse(org.lastaflute.web.response.StreamResponse) KuromojiPager(org.codelibs.fess.app.pager.KuromojiPager) CrudMode(org.codelibs.fess.app.web.CrudMode) KuromojiFile(org.codelibs.fess.dict.kuromoji.KuromojiFile) Execute(org.lastaflute.web.Execute) AdminDictKuromojiAction.createKuromojiItem(org.codelibs.fess.app.web.admin.dict.kuromoji.AdminDictKuromojiAction.createKuromojiItem) KuromojiService(org.codelibs.fess.app.service.KuromojiService) InputStream(java.io.InputStream) UploadForm(org.codelibs.fess.app.web.admin.dict.kuromoji.UploadForm) ApiResult(org.codelibs.fess.app.web.api.ApiResult) KuromojiFile(org.codelibs.fess.dict.kuromoji.KuromojiFile) InputStream(java.io.InputStream) Execute(org.lastaflute.web.Execute)

Example 64 with JsonResponse

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

the class ApiAdminDictMappingAction method get$settings.

// GET /api/admin/dict/mapping/settings/{dictId}
@Execute
public JsonResponse<ApiResult> get$settings(final String dictId, final SearchBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    final CharMappingPager pager = copyBeanToNewBean(body, CharMappingPager.class);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(charMappingService.getCharMappingList(body.dictId, pager).stream().map(protwordsItem -> createEditBody(protwordsItem, dictId)).collect(Collectors.toList())).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) CharMappingPager(org.codelibs.fess.app.pager.CharMappingPager) Execute(org.lastaflute.web.Execute)

Example 65 with JsonResponse

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

the class ApiAdminDictMappingAction method post$setting.

// POST /api/admin/dict/mapping/setting/{dictId}
@Execute
public JsonResponse<ApiResult> post$setting(final String dictId, final EditBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final CharMappingItem entity = new AdminDictMappingAction().createCharMappingItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, String.valueOf(body.id)));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, String.valueOf(body.id)));
        return null;
    });
    charMappingService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(false).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)

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