use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminFileconfigAction method put$setting.
// PUT /api/admin/fileconfig/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final FileConfig fileConfig = getFileConfig(body).map(entity -> {
try {
fileConfigService.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(fileConfig.getId()).created(true).status(Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminBadwordAction method put$setting.
// PUT /api/admin/badword/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final BadWord entity = getBadWord(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
});
return null;
});
try {
badWordService.store(entity);
suggestHelper.addBadWord(entity.getSuggestWord());
} 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.response.JsonResponse in project fess by codelibs.
the class ApiAdminBadwordAction method post$setting.
// POST /api/admin/user/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final BadWord entity = getBadWord(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id);
});
return null;
});
try {
badWordService.store(entity);
suggestHelper.storeAllBadWords();
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(false).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminSearchlistAction method docs.
// ===================================================================================
// Search Execute
// ==============
// GET /api/admin/searchlist
// POST /api/admin/searchlist
@Execute
public JsonResponse<ApiResult> docs(final SearchBody body) {
validateApi(body, messages -> {
});
if (StringUtil.isBlank(body.q)) {
// query matches on all documents.
body.q = Constants.MATCHES_ALL_QUERY;
}
final SearchRenderData renderData = new SearchRenderData();
body.initialize();
try {
searchService.search(body, renderData, getUserBean());
return asJson(new ApiDocsResponse().renderData(renderData).status(Status.OK).result());
} catch (final InvalidQueryException e) {
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
throwValidationErrorApi(e.getMessageCode());
} catch (final ResultOffsetExceededException e) {
if (logger.isDebugEnabled()) {
logger.debug(e.getMessage(), e);
}
throwValidationErrorApi(messages -> messages.addErrorsResultSizeExceeded(GLOBAL));
}
throwValidationErrorApi(messages -> messages.addErrorsInvalidQueryUnknown(GLOBAL));
// ignore
return null;
}
use of org.lastaflute.web.response.JsonResponse in project fess by codelibs.
the class ApiAdminSearchlistAction method put$doc.
// PUT /api/admin/searchlist/doc
@Execute
public JsonResponse<ApiResult> put$doc(final CreateBody body) {
validateApi(body, messages -> {
});
validateCreateFields(body, v -> throwValidationErrorApi(v));
body.crudMode = CrudMode.CREATE;
final Map<String, Object> doc = getDoc(body).map(entity -> {
try {
entity.putAll(fessConfig.convertToStorableDoc(body.doc));
final String newId = ComponentUtil.getCrawlingInfoHelper().generateId(entity);
entity.put(fessConfig.getIndexFieldId(), newId);
final String index = fessConfig.getIndexDocumentUpdateIndex();
final String type = fessConfig.getIndexDocumentType();
fessEsClient.store(index, type, entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
logger.error("Failed to add " + entity, e);
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
return null;
});
return asJson(new ApiUpdateResponse().id(doc.get(fessConfig.getIndexFieldDocId()).toString()).created(true).status(Status.OK).result());
}
Aggregations