use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.
the class ApiAdminRelatedqueryAction method settings.
// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/relatedquery/settings
// POST /api/admin/relatedquery/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
validateApi(body, messages -> {
});
final RelatedQueryPager pager = copyBeanToNewBean(body, RelatedQueryPager.class);
final List<RelatedQuery> list = relatedQueryService.getRelatedQueryList(pager);
return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(this::createEditBody).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.
the class ApiAdminRelatedqueryAction method put$setting.
// PUT /api/admin/relatedquery/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final RelatedQuery relatedQuery = getRelatedQuery(body).map(entity -> {
try {
relatedQueryService.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(relatedQuery.getId()).created(true).status(Status.OK).result());
}
use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.
the class ApiAdminRelatedqueryAction method post$setting.
// POST /api/admin/relatedquery/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final RelatedQuery relatedQuery = getRelatedQuery(body).map(entity -> {
try {
relatedQueryService.store(entity);
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
return null;
});
return asJson(new ApiUpdateResponse().id(relatedQuery.getId()).created(false).status(Status.OK).result());
}
use of org.codelibs.fess.es.config.exentity.RelatedQuery in project fess by codelibs.
the class AdminRelatedqueryAction method getRelatedQuery.
public static OptionalEntity<RelatedQuery> getRelatedQuery(final CreateForm form) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
return getEntity(form, username, currentTime).map(entity -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
BeanUtil.copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.QUERIES)).toArray(n -> new String[n])));
entity.setQueries(split(form.queries, "\n").get(stream -> stream.filter(StringUtil::isNotBlank).toArray(n -> new String[n])));
return entity;
});
}
Aggregations