use of net.yacy.grid.io.index.IndexFactory in project yacy_grid_mcp by yacy.
the class AddService method serviceImpl.
@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
// String indexName, String typeName, final String id, JSONObject object
String indexName = call.get("index", "");
String typeName = call.get("type", "");
String id = call.get("id", "");
// this contains the JSON object
byte[] object = call.get("object", EMPTY_OBJECT);
JSONObject json = new JSONObject(true);
if (indexName.length() > 0 && typeName.length() > 0 && id.length() > 0 && object.length > 0) {
try {
Index index = Data.gridIndex.getElasticIndex();
JSONObject payload = new JSONObject(new JSONTokener(new String(object, StandardCharsets.UTF_8)));
IndexFactory factory = index.add(indexName, typeName, id, payload);
String url = factory.getConnectionURL();
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
if (url != null)
json.put(ObjectAPIHandler.SERVICE_KEY, url);
} catch (IOException | JSONException e) {
json.put(ObjectAPIHandler.SUCCESS_KEY, false);
json.put(ObjectAPIHandler.COMMENT_KEY, e.getMessage());
}
} else {
json.put(ObjectAPIHandler.SUCCESS_KEY, false);
json.put(ObjectAPIHandler.COMMENT_KEY, "the request must contain an index, type, id and json object");
}
return new ServiceResponse(json);
}
use of net.yacy.grid.io.index.IndexFactory in project yacy_grid_mcp by yacy.
the class CheckService method serviceImpl.
@Override
public ServiceResponse serviceImpl(Query call, HttpServletResponse response) {
JSONObject json = new JSONObject(true);
try {
Index index = Data.gridIndex.getElasticIndex();
IndexFactory factory = index.checkConnection();
String url = factory.getConnectionURL();
json.put(ObjectAPIHandler.SUCCESS_KEY, true);
if (url != null)
json.put(ObjectAPIHandler.SERVICE_KEY, url);
} catch (IOException e) {
json.put(ObjectAPIHandler.SUCCESS_KEY, false);
json.put(ObjectAPIHandler.COMMENT_KEY, e.getMessage());
}
return new ServiceResponse(json);
}
Aggregations