Search in sources :

Example 71 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminLogAction method get$file.

// GET /api/admin/log/file/{id}
@Execute
public StreamResponse get$file(final String id) {
    final String filename = new String(Base64.getDecoder().decode(id), StandardCharsets.UTF_8).replace("..", "").replaceAll("\\s", "");
    final String logFilePath = systemHelper.getLogFilePath();
    if (StringUtil.isNotBlank(logFilePath)) {
        final Path path = Paths.get(logFilePath, filename);
        return asStream(filename).contentTypeOctetStream().stream(out -> {
            try (InputStream in = Files.newInputStream(path)) {
                out.write(in);
            }
        });
    }
    return StreamResponse.asEmptyBody();
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Execute(org.lastaflute.web.Execute)

Example 72 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminWebauthAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/webauth/settings
// POST /api/admin/webauth/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final WebAuthPager pager = copyBeanToNewBean(body, WebAuthPager.class);
    final List<WebAuthentication> list = webAuthService.getWebAuthenticationList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) WebAuthPager(org.codelibs.fess.app.pager.WebAuthPager) WebAuthentication(org.codelibs.fess.es.config.exentity.WebAuthentication) AdminWebauthAction.getWebAuthentication(org.codelibs.fess.app.web.admin.webauth.AdminWebauthAction.getWebAuthentication) Execute(org.lastaflute.web.Execute)

Example 73 with Execute

use of org.lastaflute.web.Execute 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 74 with Execute

use of org.lastaflute.web.Execute 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 75 with Execute

use of org.lastaflute.web.Execute 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)

Aggregations

Execute (org.lastaflute.web.Execute)125 ApiResult (org.codelibs.fess.app.web.api.ApiResult)94 Resource (javax.annotation.Resource)83 CrudMode (org.codelibs.fess.app.web.CrudMode)77 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)71 JsonResponse (org.lastaflute.web.response.JsonResponse)71 Collectors (java.util.stream.Collectors)70 List (java.util.List)51 InputStream (java.io.InputStream)39 File (java.io.File)35 StreamResponse (org.lastaflute.web.response.StreamResponse)34 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)32 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 Constants (org.codelibs.fess.Constants)26 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 StringUtil (org.codelibs.core.lang.StringUtil)24 ComponentUtil (org.codelibs.fess.util.ComponentUtil)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 HtmlResponse (org.lastaflute.web.response.HtmlResponse)20 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14