use of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter in project orientdb by orientechnologies.
the class OServerCommandGetGephi method sendRecordsContent.
protected void sendRecordsContent(final OHttpRequest iRequest, final OHttpResponse iResponse, Iterable<OrientElement> iRecords, String iFetchPlan) throws IOException {
final StringWriter buffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(buffer, OHttpResponse.JSON_FORMAT);
json.setPrettyPrint(true);
generateGraphDbOutput(iRecords, json);
iResponse.send(OHttpUtils.STATUS_OK_CODE, OHttpUtils.STATUS_OK_DESCRIPTION, OHttpUtils.CONTENT_JSON, buffer.toString(), null);
}
use of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter in project orientdb by orientechnologies.
the class OServerInfo method getServerInfo.
public static String getServerInfo(final OServer server) throws IOException {
final StringWriter jsonBuffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(jsonBuffer);
json.beginObject();
getConnections(server, json, null);
getDatabases(server, json);
getStorages(server, json);
getProperties(server, json);
getGlobalProperties(server, json);
json.endObject();
return jsonBuffer.toString();
}
use of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter in project orientdb by orientechnologies.
the class OServerCommandPostDatabase method sendDatabaseInfo.
protected void sendDatabaseInfo(final OHttpRequest iRequest, final OHttpResponse iResponse, final ODatabaseDocumentInternal db) throws IOException {
final StringWriter buffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(buffer);
json.beginObject();
if (db.getMetadata().getSchema().getClasses() != null) {
json.beginCollection(1, false, "classes");
Set<String> exportedNames = new HashSet<String>();
for (OClass cls : db.getMetadata().getSchema().getClasses()) {
if (!exportedNames.contains(cls.getName()))
try {
exportClass(db, json, cls);
exportedNames.add(cls.getName());
} catch (Exception e) {
OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
}
}
json.endCollection(1, true);
}
if (db.getClusterNames() != null) {
json.beginCollection(1, false, "clusters");
OCluster cluster;
for (String clusterName : db.getClusterNames()) {
cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));
try {
json.beginObject(2, true, null);
json.writeAttribute(3, false, "id", cluster.getId());
json.writeAttribute(3, false, "name", clusterName);
json.writeAttribute(3, false, "records", cluster.getEntries() - cluster.getTombstonesCount());
json.writeAttribute(3, false, "size", "-");
json.writeAttribute(3, false, "filled", "-");
json.writeAttribute(3, false, "maxSize", "-");
json.writeAttribute(3, false, "files", "-");
} catch (Exception e) {
json.writeAttribute(3, false, "records", "? (Unauthorized)");
}
json.endObject(2, false);
}
json.endCollection(1, true);
}
if (db.getUser() != null)
json.writeAttribute(1, false, "currentUser", db.getUser().getName());
json.beginCollection(1, false, "users");
OUser user;
for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
user = new OUser(doc);
json.beginObject(2, true, null);
json.writeAttribute(3, false, "name", user.getName());
json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
json.endObject(2, false);
}
json.endCollection(1, true);
json.beginCollection(1, true, "roles");
ORole role;
for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
role = new ORole(doc);
json.beginObject(2, true, null);
json.writeAttribute(3, false, "name", role.getName());
json.writeAttribute(3, false, "mode", role.getMode().toString());
json.beginCollection(3, true, "rules");
for (Map.Entry<String, Byte> rule : role.getRules().entrySet()) {
json.beginObject(4);
json.writeAttribute(4, true, "name", rule.getKey());
json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
json.endObject(4, true);
}
json.endCollection(3, false);
json.endObject(2, true);
}
json.endCollection(1, true);
json.beginObject(1, true, "config");
json.beginCollection(2, true, "values");
json.writeObjects(3, true, null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat }, new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] { "name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name", "localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name", "definitionVersion", "value", db.getStorage().getConfiguration().version });
json.endCollection(2, true);
json.beginCollection(2, true, "properties");
if (db.getStorage().getConfiguration().getProperties() != null)
for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().getProperties()) {
if (entry != null) {
json.beginObject(3, true, null);
json.writeAttribute(4, false, "name", entry.name);
json.writeAttribute(4, false, "value", entry.value);
json.endObject(3, true);
}
}
json.endCollection(2, true);
json.endObject(1, true);
json.endObject();
json.flush();
iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
}
use of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter in project orientdb by orientechnologies.
the class OServerCommandGetSSO method getJSON.
private void getJSON(final OHttpResponse iResponse) {
try {
final StringWriter buffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(buffer, OHttpResponse.JSON_FORMAT);
json.beginObject();
json.writeAttribute("enabled", getServer().getSecurity().isSingleSignOnSupported());
json.endObject();
iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
} catch (Exception ex) {
OLogManager.instance().error(this, "OServerCommandGetSSO.getJSON() Exception: %s", ex);
}
}
use of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter in project orientdb by orientechnologies.
the class OServerCommandGetConnections method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
final String[] args = checkSyntax(iRequest.url, 1, "Syntax error: connections[/<database>]");
iRequest.data.commandInfo = "Server status";
try {
final StringWriter jsonBuffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(jsonBuffer);
json.beginObject();
final String databaseName = args.length > 1 && args[1].length() > 0 ? args[1] : null;
OServerInfo.getConnections(server, json, databaseName);
json.endObject();
iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, jsonBuffer.toString(), null);
} finally {
}
return false;
}
Aggregations