Search in sources :

Example 1 with SynonymFile

use of org.codelibs.fess.dict.synonym.SynonymFile in project fess by codelibs.

the class ApiAdminDictSynonymAction method post$upload.

// POST /api/admin/dict/synonym/upload/{dictId}
@Execute
public JsonResponse<ApiResult> post$upload(final String dictId, final UploadForm form) {
    form.dictId = dictId;
    validateApi(form, messages -> {
    });
    final SynonymFile file = synonymService.getSynonymFile(form.dictId).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToUploadProtwordsFile(GLOBAL));
        return null;
    });
    try (InputStream inputStream = form.synonymFile.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) SynonymItem(org.codelibs.fess.dict.synonym.SynonymItem) JsonResponse(org.lastaflute.web.response.JsonResponse) SynonymFile(org.codelibs.fess.dict.synonym.SynonymFile) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) File(java.io.File) UploadForm(org.codelibs.fess.app.web.admin.dict.synonym.UploadForm) SynonymPager(org.codelibs.fess.app.pager.SynonymPager) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) Execute(org.lastaflute.web.Execute) SynonymService(org.codelibs.fess.app.service.SynonymService) InputStream(java.io.InputStream) AdminDictSynonymAction(org.codelibs.fess.app.web.admin.dict.synonym.AdminDictSynonymAction) ApiResult(org.codelibs.fess.app.web.api.ApiResult) InputStream(java.io.InputStream) SynonymFile(org.codelibs.fess.dict.synonym.SynonymFile) Execute(org.lastaflute.web.Execute)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 SynonymPager (org.codelibs.fess.app.pager.SynonymPager)1 SynonymService (org.codelibs.fess.app.service.SynonymService)1 CrudMode (org.codelibs.fess.app.web.CrudMode)1 AdminDictSynonymAction (org.codelibs.fess.app.web.admin.dict.synonym.AdminDictSynonymAction)1 UploadForm (org.codelibs.fess.app.web.admin.dict.synonym.UploadForm)1 ApiResult (org.codelibs.fess.app.web.api.ApiResult)1 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)1 SynonymFile (org.codelibs.fess.dict.synonym.SynonymFile)1 SynonymItem (org.codelibs.fess.dict.synonym.SynonymItem)1 Execute (org.lastaflute.web.Execute)1 JsonResponse (org.lastaflute.web.response.JsonResponse)1 StreamResponse (org.lastaflute.web.response.StreamResponse)1