use of org.codelibs.fess.app.web.api.ApiResult.Status 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.codelibs.fess.app.web.api.ApiResult.Status in project fess by codelibs.
the class ApiAdminLabeltypeAction method post$setting.
// POST /api/admin/labeltype/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final LabelType labelType = getLabelType(body).map(entity -> {
try {
labelTypeService.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(labelType.getId()).created(false).status(Status.OK).result());
}
use of org.codelibs.fess.app.web.api.ApiResult.Status 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.app.web.api.ApiResult.Status 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.app.web.api.ApiResult.Status 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 -> {
});
if (body.doc == null) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, "doc is required"));
}
validateFields(body, this::throwValidationErrorApi);
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();
searchEngineClient.store(index, 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