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