Search in sources :

Example 1 with RelatedQuery

use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.

the class ApiAdminRelatedqueryAction method settings.

// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/relatedquery/settings
// POST /api/admin/relatedquery/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final RelatedQueryPager pager = copyBeanToNewBean(body, RelatedQueryPager.class);
    final List<RelatedQuery> list = relatedQueryService.getRelatedQueryList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminRelatedqueryAction.getRelatedQuery(org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) RelatedQueryPager(org.codelibs.fess.app.pager.RelatedQueryPager) Execute(org.lastaflute.web.Execute)

Example 2 with RelatedQuery

use of org.codelibs.fess.es.config.exentity.RelatedQuery 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 3 with RelatedQuery

use of org.codelibs.fess.es.config.exentity.RelatedQuery 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 4 with RelatedQuery

use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.

the class AdminRelatedqueryAction method getRelatedQuery.

public static OptionalEntity<RelatedQuery> getRelatedQuery(final CreateForm form) {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final String username = systemHelper.getUsername();
    final long currentTime = systemHelper.getCurrentTimeAsLong();
    return getEntity(form, username, currentTime).map(entity -> {
        entity.setUpdatedBy(username);
        entity.setUpdatedTime(currentTime);
        BeanUtil.copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.QUERIES)).toArray(n -> new String[n])));
        entity.setQueries(split(form.queries, "\n").get(stream -> stream.filter(StringUtil::isNotBlank).toArray(n -> new String[n])));
        return entity;
    });
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) Constants(org.codelibs.fess.Constants) Secured(org.codelibs.fess.annotation.Secured) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) RelatedQueryPager(org.codelibs.fess.app.pager.RelatedQueryPager) OptionalEntity(org.dbflute.optional.OptionalEntity) OptionalThing(org.dbflute.optional.OptionalThing) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) RelatedQuery(org.codelibs.fess.es.config.exentity.RelatedQuery) Collectors(java.util.stream.Collectors) RelatedQueryService(org.codelibs.fess.app.service.RelatedQueryService) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Stream(java.util.stream.Stream) CrudMode(org.codelibs.fess.app.web.CrudMode) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Execute(org.lastaflute.web.Execute) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) SystemHelper(org.codelibs.fess.helper.SystemHelper)

Aggregations

RelatedQueryPager (org.codelibs.fess.app.pager.RelatedQueryPager)4 RelatedQuery (org.codelibs.fess.es.config.exentity.RelatedQuery)4 Execute (org.lastaflute.web.Execute)4 Collectors (java.util.stream.Collectors)3 Resource (javax.annotation.Resource)3 StringUtil (org.codelibs.core.lang.StringUtil)3 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)3 Constants (org.codelibs.fess.Constants)3 RelatedQueryService (org.codelibs.fess.app.service.RelatedQueryService)3 CrudMode (org.codelibs.fess.app.web.CrudMode)3 AdminRelatedqueryAction.getRelatedQuery (org.codelibs.fess.app.web.admin.relatedquery.AdminRelatedqueryAction.getRelatedQuery)3 ApiResult (org.codelibs.fess.app.web.api.ApiResult)3 List (java.util.List)2 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)2 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)2 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)2 Status (org.codelibs.fess.app.web.api.ApiResult.Status)2 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)2 JsonResponse (org.lastaflute.web.response.JsonResponse)2 Stream (java.util.stream.Stream)1