Search in sources :

Example 76 with ApiResult

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

the class ApiAdminDictSeunjeonAction method put$setting.

// PUT /api/admin/dict/seunjeon/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 SeunjeonItem entity = new AdminDictSeunjeonAction().createSeunjeonItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    seunjeonService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(true).status(ApiResult.Status.OK).result());
}
Also used : SeunjeonItem(org.codelibs.fess.dict.seunjeon.SeunjeonItem) SeunjeonItem(org.codelibs.fess.dict.seunjeon.SeunjeonItem) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) SeunjeonService(org.codelibs.fess.app.service.SeunjeonService) 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) UploadForm(org.codelibs.fess.app.web.admin.dict.seunjeon.UploadForm) StreamResponse(org.lastaflute.web.response.StreamResponse) CrudMode(org.codelibs.fess.app.web.CrudMode) SeunjeonFile(org.codelibs.fess.dict.seunjeon.SeunjeonFile) AdminDictSeunjeonAction(org.codelibs.fess.app.web.admin.dict.seunjeon.AdminDictSeunjeonAction) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) SeunjeonPager(org.codelibs.fess.app.pager.SeunjeonPager) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminDictSeunjeonAction(org.codelibs.fess.app.web.admin.dict.seunjeon.AdminDictSeunjeonAction) Execute(org.lastaflute.web.Execute)

Example 77 with ApiResult

use of org.codelibs.fess.app.web.api.ApiResult 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)

Example 78 with ApiResult

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

the class ApiAdminDictSynonymAction method get$settings.

// GET /api/admin/dict/synonym/settings/{dictId}
@Execute
public JsonResponse<ApiResult> get$settings(final String dictId, final SearchBody body) {
    body.dictId = dictId;
    validateApi(body, messages -> {
    });
    final SynonymPager pager = copyBeanToNewBean(body, SynonymPager.class);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(synonymService.getSynonymList(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) 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) SynonymPager(org.codelibs.fess.app.pager.SynonymPager) Execute(org.lastaflute.web.Execute)

Example 79 with ApiResult

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

the class ApiAdminDictSynonymAction method put$setting.

// PUT /api/admin/dict/synonym/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 SynonymItem entity = new AdminDictSynonymAction().createSynonymItem(body, () -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    synonymService.store(body.dictId, entity);
    return asJson(new ApiResult.ApiUpdateResponse().id(String.valueOf(entity.getId())).created(true).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) AdminDictSynonymAction(org.codelibs.fess.app.web.admin.dict.synonym.AdminDictSynonymAction) SynonymItem(org.codelibs.fess.dict.synonym.SynonymItem) Execute(org.lastaflute.web.Execute)

Example 80 with ApiResult

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

the class ApiAdminBoostdocAction method post$setting.

// POST /api/admin/boostdoc/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final BoostDocumentRule boostDoc = getBoostDocumentRule(body).map(entity -> {
        try {
            boostDocumentRuleService.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(boostDoc.getId()).created(false).status(Status.OK).result());
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) BoostDocumentRule(org.codelibs.fess.es.config.exentity.BoostDocumentRule) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) AdminBoostdocAction.getBoostDocumentRule(org.codelibs.fess.app.web.admin.boostdoc.AdminBoostdocAction.getBoostDocumentRule) 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) BoostDocumentRuleService(org.codelibs.fess.app.service.BoostDocumentRuleService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) BoostDocPager(org.codelibs.fess.app.pager.BoostDocPager) ApiConfigsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigsResponse) BoostDocumentRule(org.codelibs.fess.es.config.exentity.BoostDocumentRule) AdminBoostdocAction.getBoostDocumentRule(org.codelibs.fess.app.web.admin.boostdoc.AdminBoostdocAction.getBoostDocumentRule) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) 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