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();
}
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());
}
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());
}
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());
}
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());
}
Aggregations