Search in sources :

Example 41 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminSchedulerAction method post$setting.

// POST /api/admin/scheduler/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.EDIT;
    final ScheduledJob entity = getScheduledJob(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
        });
        return null;
    });
    try {
        scheduledJobService.store(entity);
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) AdminSchedulerAction.getScheduledJob(org.codelibs.fess.app.web.admin.scheduler.AdminSchedulerAction.getScheduledJob) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) SchedulerPager(org.codelibs.fess.app.pager.SchedulerPager) ScheduledJobService(org.codelibs.fess.app.service.ScheduledJobService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) HtmlResponse(org.lastaflute.web.response.HtmlResponse) ScheduledJob(org.codelibs.fess.es.config.exentity.ScheduledJob) ApiResult(org.codelibs.fess.app.web.api.ApiResult) AdminSchedulerAction.getScheduledJob(org.codelibs.fess.app.web.admin.scheduler.AdminSchedulerAction.getScheduledJob) ScheduledJob(org.codelibs.fess.es.config.exentity.ScheduledJob) Execute(org.lastaflute.web.Execute)

Example 42 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminSearchlistAction method delete$doc.

// DELETE /api/admin/searchlist/doc/{id}
@Execute
public JsonResponse<ApiResult> delete$doc(final String id) {
    try {
        final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), id);
        fessEsClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), fessConfig.getIndexDocumentType(), query);
        saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL));
    }
    return asJson(new ApiResponse().status(Status.OK).result());
}
Also used : Constants(org.codelibs.fess.Constants) AdminSearchlistAction.validateUpdateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateUpdateFields) AdminSearchlistAction.getDoc(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.getDoc) LoggerFactory(org.slf4j.LoggerFactory) ApiDeleteResponse(org.codelibs.fess.app.web.api.ApiResult.ApiDeleteResponse) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) 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) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AdminSearchlistAction.validateCreateFields(org.codelibs.fess.app.web.admin.searchlist.AdminSearchlistAction.validateCreateFields) Logger(org.slf4j.Logger) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) FessEsClient(org.codelibs.fess.es.client.FessEsClient) 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) SearchService(org.codelibs.fess.app.service.SearchService) 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) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) Execute(org.lastaflute.web.Execute)

Example 43 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminGroupAction method put$setting.

// PUT /api/admin/group/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final Group entity = getGroup(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        groupService.store(entity);
        saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(true).status(ApiResult.Status.OK).result());
}
Also used : GroupService(org.codelibs.fess.app.service.GroupService) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) JsonResponse(org.lastaflute.web.response.JsonResponse) User(org.codelibs.fess.es.user.exentity.User) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) GroupPager(org.codelibs.fess.app.pager.GroupPager) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Execute(org.lastaflute.web.Execute) Group(org.codelibs.fess.es.user.exentity.Group) AdminGroupAction.getGroup(org.codelibs.fess.app.web.admin.group.AdminGroupAction.getGroup) Group(org.codelibs.fess.es.user.exentity.Group) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Execute(org.lastaflute.web.Execute)

Example 44 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminKeymatchAction method put$setting.

// PUT /api/admin/keymatch/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final KeyMatch keyMatch = getKeyMatch(body).map(entity -> {
        try {
            keyMatchService.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(keyMatch.getId()).created(true).status(Status.OK).result());
}
Also used : FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Execute(org.lastaflute.web.Execute)

Example 45 with JsonResponse

use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.

the class ApiAdminDuplicatehostAction method put$setting.

// PUT /api/admin/duplicatehost/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
        try {
            duplicateHostService.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(duplicateHost.getId()).created(true).status(Status.OK).result());
}
Also used : DuplicateHostPager(org.codelibs.fess.app.pager.DuplicateHostPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) 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) DuplicateHostService(org.codelibs.fess.app.service.DuplicateHostService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) Execute(org.lastaflute.web.Execute)

Aggregations

Resource (javax.annotation.Resource)65 ApiResult (org.codelibs.fess.app.web.api.ApiResult)65 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)65 Execute (org.lastaflute.web.Execute)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 WebConfigService (org.codelibs.fess.app.service.WebConfigService)6 ApiErrorResponse (org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse)6