Search in sources :

Example 1 with ProtwordsFile

use of org.codelibs.fess.dict.protwords.ProtwordsFile in project fess by codelibs.

the class ApiAdminDictProtwordsAction method post$upload.

// POST /api/admin/dict/protwords/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
    form.dictId = dictId;
    validateApi(form, messages -> {
    });
    final ProtwordsFile file = protwordsService.getProtwordsFile(form.dictId).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
        return null;
    });
    try (InputStream inputStream = form.protwordsFile.getInputStream()) {
        file.update(inputStream);
    } catch (final IOException e) {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
    }
    return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
Also used : AdminDictProtwordsAction.createProtwordsItem(org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ProtwordsPager(org.codelibs.fess.app.pager.ProtwordsPager) Resource(javax.annotation.Resource) IOException(java.io.IOException) UploadForm(org.codelibs.fess.app.web.admin.dict.protwords.UploadForm) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) ProtwordsItem(org.codelibs.fess.dict.protwords.ProtwordsItem) ProtwordsService(org.codelibs.fess.app.service.ProtwordsService) Execute(org.lastaflute.web.Execute) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) InputStream(java.io.InputStream) ApiResult(org.codelibs.fess.app.web.api.ApiResult) InputStream(java.io.InputStream) IOException(java.io.IOException) ProtwordsFile(org.codelibs.fess.dict.protwords.ProtwordsFile) Execute(org.lastaflute.web.Execute)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 ProtwordsPager (org.codelibs.fess.app.pager.ProtwordsPager)1 ProtwordsService (org.codelibs.fess.app.service.ProtwordsService)1 CrudMode (org.codelibs.fess.app.web.CrudMode)1 AdminDictProtwordsAction.createProtwordsItem (org.codelibs.fess.app.web.admin.dict.protwords.AdminDictProtwordsAction.createProtwordsItem)1 UploadForm (org.codelibs.fess.app.web.admin.dict.protwords.UploadForm)1 ApiResult (org.codelibs.fess.app.web.api.ApiResult)1 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)1 ProtwordsFile (org.codelibs.fess.dict.protwords.ProtwordsFile)1 ProtwordsItem (org.codelibs.fess.dict.protwords.ProtwordsItem)1 Execute (org.lastaflute.web.Execute)1 JsonResponse (org.lastaflute.web.response.JsonResponse)1 StreamResponse (org.lastaflute.web.response.StreamResponse)1