Search in sources :

Example 51 with ApiResult

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

the class ApiAdminWebauthAction method put$setting.

// PUT /api/admin/webauth/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    if (!isValidWebConfigId(body.webConfigId)) {
        return asJson(new ApiErrorResponse().message("invalid webConfigId").status(Status.BAD_REQUEST).result());
    }
    body.crudMode = CrudMode.CREATE;
    final WebAuthentication webAuth = getWebAuthentication(body).map(entity -> {
        try {
            webAuthService.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(webAuth.getId()).created(true).status(Status.OK).result());
}
Also used : WebAuthentication(org.codelibs.fess.es.config.exentity.WebAuthentication) WebAuthPager(org.codelibs.fess.app.pager.WebAuthPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) WebAuthenticationService(org.codelibs.fess.app.service.WebAuthenticationService) WebConfigService(org.codelibs.fess.app.service.WebConfigService) 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) AdminWebauthAction.getWebAuthentication(org.codelibs.fess.app.web.admin.webauth.AdminWebauthAction.getWebAuthentication) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) ApiErrorResponse(org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse) WebAuthentication(org.codelibs.fess.es.config.exentity.WebAuthentication) AdminWebauthAction.getWebAuthentication(org.codelibs.fess.app.web.admin.webauth.AdminWebauthAction.getWebAuthentication) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) ApiErrorResponse(org.codelibs.fess.app.web.api.ApiResult.ApiErrorResponse) Execute(org.lastaflute.web.Execute)

Example 52 with ApiResult

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

the class ApiAdminSchedulerAction method delete$setting.

// DELETE /api/admin/scheduler/setting/{id}
@Execute
public JsonResponse<ApiResult> delete$setting(final String id) {
    final ScheduledJob entity = scheduledJobService.getScheduledJob(id).orElseGet(() -> {
        throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
        return null;
    });
    try {
        scheduledJobService.delete(entity);
        saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
    } catch (final Exception e) {
        throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToDeleteCrudTable(GLOBAL, buildThrowableMessage(e)));
    }
    return asJson(new ApiResult.ApiUpdateResponse().id(id).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 53 with ApiResult

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

the class ApiAdminSchedulerAction method put$setting.

// PUT /api/admin/scheduler/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final ScheduledJob entity = getScheduledJob(body).orElseGet(() -> {
        throwValidationErrorApi(messages -> {
            messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
        });
        return null;
    });
    try {
        scheduledJobService.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 : 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 54 with ApiResult

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

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

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