use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminElevatewordAction method put$setting.
// PUT /api/admin/elevateword/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final ElevateWord entity = getElevateWord(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
});
return null;
});
try {
elevateWordService.store(entity);
suggestHelper.addElevateWord(entity.getSuggestWord(), entity.getReading(), entity.getLabelTypeValues(), entity.getPermissions(), entity.getBoost());
} 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());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminElevatewordAction method post$upload.
// POST /api/admin/elevateword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
validateApi(body, messages -> {
});
new Thread(() -> {
try (Reader reader = new BufferedReader(new InputStreamReader(body.elevateWordFile.getInputStream(), getCsvEncoding()))) {
elevateWordService.importCsv(reader);
suggestHelper.storeAllElevateWords();
} catch (final Exception e) {
throw new FessSystemException("Failed to import data.", e);
}
}).start();
return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminElevatewordAction method settings.
// GET /api/admin/elevateword
// POST /api/admin/elevateword
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {
});
final ElevateWordPager pager = copyBeanToNewBean(body, ElevateWordPager.class);
final List<ElevateWord> list = elevateWordService.getElevateWordList(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 ApiAdminElevatewordAction method get$setting.
// GET /api/admin/elevateword/{id}
@Execute
public JsonResponse<ApiResult> get$setting(final String id) {
final ElevateWord entity = elevateWordService.getElevateWord(id).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id));
return null;
});
final EditBody body = createEditBody(entity);
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
return asJson(new ApiResult.ApiConfigResponse().setting(body).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminFailureurlAction method logs.
// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/failureurl/logs
// POST /api/admin/failureurl/logs
@Execute
public JsonResponse<ApiResult> logs(final SearchBody body) {
validateApi(body, messages -> {
});
final FailureUrlPager pager = copyBeanToNewBean(body, FailureUrlPager.class);
final List<FailureUrl> list = failureUrlService.getFailureUrlList(pager);
return asJson(new ApiResult.ApiLogsResponse<EditBody>().logs(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Aggregations