Search in sources :

Example 1 with Status

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

the class ApiAdminFileconfigAction method put$setting.

// PUT /api/admin/fileconfig/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final FileConfig fileConfig = getFileConfig(body).map(entity -> {
        try {
            fileConfigService.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(fileConfig.getId()).created(true).status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) AdminFileconfigAction.getFileConfig(org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig) 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) FileConfigPager(org.codelibs.fess.app.pager.FileConfigPager) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FileConfigService(org.codelibs.fess.app.service.FileConfigService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) AdminFileconfigAction.getFileConfig(org.codelibs.fess.app.web.admin.fileconfig.AdminFileconfigAction.getFileConfig) FileConfig(org.codelibs.fess.es.config.exentity.FileConfig) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 2 with Status

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

the class ApiAdminLabeltypeAction method post$setting.

// POST /api/admin/labeltype/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final LabelType labelType = getLabelType(body).map(entity -> {
        try {
            labelTypeService.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(labelType.getId()).created(false).status(Status.OK).result());
}
Also used : AdminLabeltypeAction.getLabelType(org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType) Constants(org.codelibs.fess.Constants) LabelTypePager(org.codelibs.fess.app.pager.LabelTypePager) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) 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) LabelType(org.codelibs.fess.es.config.exentity.LabelType) LabelTypeService(org.codelibs.fess.app.service.LabelTypeService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminLabeltypeAction.getLabelType(org.codelibs.fess.app.web.admin.labeltype.AdminLabeltypeAction.getLabelType) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 3 with Status

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

the class ApiAdminRelatedqueryAction method put$setting.

// PUT /api/admin/relatedquery/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final RelatedQuery relatedQuery = getRelatedQuery(body).map(entity -> {
        try {
            relatedQueryService.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(relatedQuery.getId()).created(true).status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) RelatedQueryPager(org.codelibs.fess.app.pager.RelatedQueryPager) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) AdminRelatedqueryAction.getRelatedQuery(org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) RelatedQueryService(org.codelibs.fess.app.service.RelatedQueryService) 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) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminRelatedqueryAction.getRelatedQuery(org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 4 with Status

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

the class ApiAdminRelatedqueryAction method post$setting.

// POST /api/admin/relatedquery/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final RelatedQuery relatedQuery = getRelatedQuery(body).map(entity -> {
        try {
            relatedQueryService.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(relatedQuery.getId()).created(false).status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) RelatedQueryPager(org.codelibs.fess.app.pager.RelatedQueryPager) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) AdminRelatedqueryAction.getRelatedQuery(org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) RelatedQueryService(org.codelibs.fess.app.service.RelatedQueryService) 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) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminRelatedqueryAction.getRelatedQuery(org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 5 with Status

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

the class ApiAdminSearchlistAction method put$doc.

// PUT /api/admin/searchlist/doc
@Execute
public JsonResponse<ApiResult> put$doc(final CreateBody body) {
    validateApi(body, messages -> {
    });
    if (body.doc == null) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, "doc is required"));
    }
    validateFields(body, this::throwValidationErrorApi);
    body.crudMode = CrudMode.CREATE;
    final Map<String, Object> doc = getDoc(body).map(entity -> {
        try {
            entity.putAll(fessConfig.convertToStorableDoc(body.doc));
            final String newId = ComponentUtil.getCrawlingInfoHelper().generateId(entity);
            entity.put(fessConfig.getIndexFieldId(), newId);
            final String index = fessConfig.getIndexDocumentUpdateIndex();
            searchEngineClient.store(index, entity);
            saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
        } catch (final Exception e) {
            logger.error("Failed to add {}", entity, e);
            throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
        }
        return entity;
    }).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
        return null;
    });
    return asJson(new ApiUpdateResponse().id(doc.get(fessConfig.getIndexFieldDocId()).toString()).created(true).status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) AdminSearchlistAction.getDoc(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.getDoc) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) ApiDeleteResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDeleteResponse) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) AdminSearchlistAction.validateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateFields) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) CrudMode(org.codelibs.fess.app.web.CrudMode) Map(java.util.Map) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) SearchHelper(org.codelibs.fess.helper.SearchHelper) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilders(org.opensearch.index.query.QueryBuilders) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) ApiDocResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocResponse) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) JsonResponse(org.lastaflute.web.response.JsonResponse) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ApiDocsResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDocsResponse) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) LogManager(org.apache.logging.log4j.LogManager) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Execute(org.lastaflute.web.Execute)

Aggregations

ApiResult (org.codelibs.fess.app.web.api.ApiResult)40 Status (org.codelibs.fess.app.web.api.ApiResult.Status)40 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)40 Execute (org.lastaflute.web.Execute)40 JsonResponse (org.lastaflute.web.response.JsonResponse)40 Resource (javax.annotation.Resource)38 CrudMode (org.codelibs.fess.app.web.CrudMode)38 List (java.util.List)36 Collectors (java.util.stream.Collectors)36 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)35 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)35 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)26 Constants (org.codelibs.fess.Constants)22 StringUtil (org.codelibs.core.lang.StringUtil)19 ComponentUtil (org.codelibs.fess.util.ComponentUtil)19 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)15 PermissionHelper (org.codelibs.fess.helper.PermissionHelper)13 WebConfigService (org.codelibs.fess.app.service.WebConfigService)6 ApiErrorResponse (org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse)6 BufferedReader (java.io.BufferedReader)5