私はRazor with .net mvc 4.5を使用しています。フロントエンドは角度jsです。私はTitan 1.0用にAws ec2サーバーを使用していますが、Rml API経由でgremlinサーバーを使用しています。 私はRest APIを使ってサーバーを呼び出そうとしましたが、構文エラーが常に出ます。 gremlinサーバーのエッジと頂点の両方に対してCRUD操作を記述する正しい方法は何でしょうか?グレムリンサーバーを使用して更新するエッジをC#でgremlinサーバーのエッジと頂点を作成、更新、削除する方法は?
0
A
答えて
1
あなたは、次の質問スレッド
How to Create and Delete edge properties (Titan 1.0) using c# in .net mvc?
とグレムリンサーバで頂点を作成、更新、削除のためにあなたが変更いくつかのパラメータの後に、次のクラスを使用することができますを確認することができます。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Newtonsoft.Json;
using RestSharp;
using urNotice.Common.Infrastructure.Common.Config;
using urNotice.Common.Infrastructure.Common.Constants;
using urNotice.Common.Infrastructure.Common.Enum;
using urNotice.Common.Infrastructure.Model.urNoticeModel.DynamoDb;
using urNotice.Services.NoSqlDb.DynamoDb;
namespace urNotice.Services.GraphDb
{
public class GremlinServerGraphVertexDb : IGraphVertexDb
{
public Dictionary<string, string> AddVertex(string email, string graphName, Dictionary<string, string> properties, HashSet<string> canEdit, HashSet<string> canDelete,
HashSet<string> sendNotificationToUsers)
{
string url = TitanGraphConfig.Server;
var response = CreateVertex(graphName, properties, url);
if (!response.ContainsKey(TitanGraphConstants.Id))
return null;
var orbitPageVertexDetail = new OrbitPageVertexDetail
{
url = url,
vertexId = response[TitanGraphConstants.Id],
graphName = graphName,
properties = properties
};
IDynamoDb dynamoDbModel = new DynamoDb();
dynamoDbModel.UpsertOrbitPageVertexDetail(orbitPageVertexDetail, email, canEdit, canDelete, sendNotificationToUsers);
return response;
}
public Dictionary<string, string> UpdateVertex(string vertexId, string email, string graphName, Dictionary<string, string> properties)
{
string url = TitanGraphConfig.Server;
var orbitPageCompanyUserWorkgraphyTable = GetVertexDetailsFromDynamoDb(vertexId);
var response = UpdateGraphVertex(vertexId, graphName, properties, url, orbitPageCompanyUserWorkgraphyTable);
var orbitPageVertexDetail = new OrbitPageVertexDetail
{
url = url,
vertexId = vertexId,
graphName = graphName,
properties = response
};
orbitPageCompanyUserWorkgraphyTable.OrbitPageVertexDetail = orbitPageVertexDetail;
IDynamoDb dynamoDbModel = new DynamoDb();
dynamoDbModel.CreateOrUpdateOrbitPageCompanyUserWorkgraphyTable(orbitPageCompanyUserWorkgraphyTable);
return response;
}
private Dictionary<String, String> UpdateGraphVertex(string vertexId, string graphName, Dictionary<string, string> properties, string url, OrbitPageCompanyUserWorkgraphyTable orbitPageCompanyUserWorkgraphyTable)
{
var uri = new StringBuilder("/?gremlin=");
var oldProperties = new Dictionary<string, string>();
if (orbitPageCompanyUserWorkgraphyTable != null && orbitPageCompanyUserWorkgraphyTable.OrbitPageVertexDetail != null)
oldProperties = orbitPageCompanyUserWorkgraphyTable.OrbitPageVertexDetail.properties;
var newProperties = new Dictionary<String, String>();
if (oldProperties == null)
{
return null;
}
foreach (KeyValuePair<string, string> property in oldProperties)
{
newProperties[property.Key] = property.Value;
}
foreach (KeyValuePair<string, string> property in oldProperties)
{
//merge updated values in dictionary..
if (properties.ContainsKey(property.Key))
{
newProperties[property.Key] = properties[property.Key];
}
}
//new properties that is not available in old properties
foreach (KeyValuePair<string, string> property in properties)
{
//merge updated values in dictionary..
if (!newProperties.ContainsKey(property.Key))
{
newProperties[property.Key] = properties[property.Key];
}
}
//if user want to delete previous uploaded image.
if (oldProperties.ContainsKey(VertexPropertyEnum.CoverImageUrl.ToString()) &&
!properties.ContainsKey(VertexPropertyEnum.CoverImageUrl.ToString()))
{
newProperties.Remove(VertexPropertyEnum.CoverImageUrl.ToString());
}
if (newProperties.ContainsKey(VertexPropertyEnum.CoverImageUrl.ToString()) && string.IsNullOrEmpty(newProperties[VertexPropertyEnum.CoverImageUrl.ToString()]))
newProperties[VertexPropertyEnum.CoverImageUrl.ToString()] = CommonConstants.CompanySquareLogoNotAvailableImage;
string graphProperties = string.Empty;
//g.V(4192).property('name','William2').property('age',30)
foreach (KeyValuePair<string, string> property in properties)
{
if (property.Key == VertexPropertyEnum.CreatedTimeLong.ToString() || property.Key == VertexPropertyEnum.PostedTimeLong.ToString())
graphProperties += ".property('" + property.Key + "'," + property.Value + ")";
else
graphProperties += ".property('" + property.Key + "','" + property.Value + "')";
}
url = url + uri.ToString() + "g.V(" + vertexId + ")" + graphProperties;
var client = new RestClient(url);
var request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", "", ParameterType.RequestBody);
var res = client.Execute(request);
var content = res.Content; // raw content as string
//dynamic jsonResponse = JsonConvert.DeserializeObject(content);
//var response = new Dictionary<String, String>();
//TODO:To check if failed.
//dynamic jsonResponse = JsonConvert.DeserializeObject(content);
return newProperties;
}
private OrbitPageCompanyUserWorkgraphyTable GetVertexDetailsFromDynamoDb(string vertexId)
{
IDynamoDb dynamoDbModel = new DynamoDb();
var orbitPageCompanyUserWorkgraphyTable = dynamoDbModel.GetOrbitPageCompanyUserWorkgraphyTable(DynamoDbHashKeyDataType.VertexDetail.ToString(),
vertexId, null);
//if (orbitPageCompanyUserWorkgraphyTable != null && orbitPageCompanyUserWorkgraphyTable.OrbitPageVertexDetail != null)
// return orbitPageCompanyUserWorkgraphyTable.OrbitPageVertexDetail.properties;
return orbitPageCompanyUserWorkgraphyTable;
}
private Dictionary<String, String> CreateVertex(string graphName, Dictionary<string, string> properties, string url)
{
var uri = new StringBuilder("/?gremlin=");
//graph.addVertex(label, "person", "name", "marko", "age", 29);
var response = new Dictionary<String, String>();
string graphProperties = string.Empty;
foreach (KeyValuePair<string, string> property in properties)
{
if (property.Key == VertexPropertyEnum.Type.ToString())
{
if (string.IsNullOrEmpty(property.Value))
{
response["status"] = "404";
return response;
}
graphProperties += "label, '" + property.Value + "' ,";
}
else
{
if (property.Key == VertexPropertyEnum.CreatedTimeLong.ToString() ||
property.Key == VertexPropertyEnum.PostedTimeLong.ToString())
graphProperties += "'" + property.Key + "', " + property.Value + " ,";
else
{
graphProperties += "'" + property.Key + "', '" + property.Value + "' ,";
}
}
}
if (!string.IsNullOrEmpty(graphProperties))
{
graphProperties = graphProperties.Substring(0, graphProperties.Length - 2);
}
url = url + uri.ToString() + "graph.addVertex(" + graphProperties + ");";
var client = new RestClient(url);
var request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", "", ParameterType.RequestBody);
var res = client.Execute(request);
var content = res.Content; // raw content as string
dynamic jsonResponse = JsonConvert.DeserializeObject(content);
response["status"] = "200";
response[TitanGraphConstants.Id] = jsonResponse.result.data[0].id;
response[TitanGraphConstants.RexsterUri] = url;
return response;
}
public string ExecuteGremlinQuery(string gremlinQuery)
{
string url = TitanGraphConfig.Server;
var uri = new StringBuilder("/?gremlin=");
url = url + uri.ToString() + gremlinQuery;
var client = new RestClient(url);
var request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", "", ParameterType.RequestBody);
var res = client.Execute(request);
var content = res.Content; // raw content as string
return content;
}
public string GetVertexDetail(string gremlinQuery, string vertexId, string graphName, Dictionary<string, string> properties)
{
var uri = new StringBuilder("/graphs/" + graphName + "/vertices/" + vertexId);
string url = TitanGraphConfig.Server;
if (gremlinQuery != null)
{
uri.Append("/tp/gremlin?");
uri.Append("script=" + gremlinQuery);
}
else if (properties.Count > 0)
{
uri.Append("?");
foreach (KeyValuePair<string, string> property in properties)
{
uri.Append(property.Key + "=" + property.Value + "&");
}
}
var client = new RestClient(url + uri.ToString());
var request = new RestRequest();
request.Method = Method.GET;
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", "", ParameterType.RequestBody);
var res = client.Execute(request);
var content = res.Content; // raw content as string
return content;
}
public Dictionary<string, string> DeleteVertex(string vertexId, string userVertexId, string label)
{
string url = TitanGraphConfig.Server;
IDynamoDb dynamoDbModel = new DynamoDb();
var vertexInfo = dynamoDbModel.GetOrbitPageCompanyUserWorkgraphyTable(DynamoDbHashKeyDataType.VertexDetail.ToString(), vertexId, null);
if (vertexInfo == null)
return null;
//Get all inEdges to delete
var allInEdgesInfo = dynamoDbModel.GetOrbitPageCompanyUserWorkgraphyTableUsingInEdges(vertexId);
//Get all outEdges to delete
var allOutEdgesInfo = dynamoDbModel.GetOrbitPageCompanyUserWorkgraphyTableUsingOutEdges(vertexId);
var response = DeleteVertexNative(TitanGraphConfig.Graph, vertexId, url);
dynamoDbModel.DeleteOrbitPageCompanyUserWorkgraphyTable(vertexInfo);
dynamoDbModel.DeleteOrbitPageCompanyUserWorkgraphyTable(allInEdgesInfo);
dynamoDbModel.DeleteOrbitPageCompanyUserWorkgraphyTable(allOutEdgesInfo);
return response;
}
private Dictionary<String, String> DeleteVertexNative(string graphName, string vertexId, string url)
{
var uri = new StringBuilder(url + "/graphs/" + graphName + "/vertices/" + vertexId);
//graphs/<graph>/edges/3
var client = new RestClient(uri.ToString());
var request = new RestRequest();
request.Method = Method.DELETE;
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", "", ParameterType.RequestBody);
var res = client.Execute(request);
var content = res.Content; // raw content as string
//dynamic jsonResponse = JsonConvert.DeserializeObject(content);
var response = new Dictionary<String, String>();
response["status"] = "200";
return response;
}
}
}
ちょうどあなたには関係ありません、あなたは、更新を作成し、REST API呼び出しを使用してグレムリンサーバで頂点を削除するには、次のクラスを使用することができますいくつかのコードを削除します。
+0
私はこれだけを探していた。 –
関連する問題
- 1. OrientDBで頂点を作成してエッジを作成する方法
- 2. Orientdbで頂点を取得してエッジを作成する方法
- 3. gremlinサーバーでエッジを追加するクエリ
- 4. ローカルDynamodbのgremlinグラフ内に複数の頂点を作成
- 5. ポリゴンカーブの鋭いエッジ(頂点)を作る
- 6. JUNG - MouseOverで頂点とエッジの太さを変更する方法
- 7. データスタックスグラフの同じcsvファイルからエッジと頂点を作成
- 8. OrientDB ETL:重複した頂点をスキップしてエッジを作成する方法
- 9. 頂点とエッジのセットからASCIIグラフを作成するツールですか?
- 10. 移動する頂点でポリゴンを作成する方法は?
- 11. Gremlin Server Titan 1.0の頂点を削除するにはどうすればいいですか
- 12. PHPのGoogleコンタクトAPIを削除/更新/作成する方法
- 13. 頂点から全ての出て行く辺の頂点を得る方法scala gremlin
- 14. jung新しい位置に新しい頂点を作成する方法
- 15. Gremlin-特定のプロパティを持つ頂点のパーセンテージを計算する方法
- 16. DecalGeometry頂点、UVの更新
- 17. ASPNETDB.MDF 'vw_aspnet_MembershipUsers'の更新/削除方法は?更新する方法
- 18. 頂点シェーダとフラグメントシェーダから法線を削除します
- 19. 頂点クラスでTaskRouterワーカー能力トークンを作成する方法
- 20. b2PolygonShape頂点で静的なボディを作成する方法
- 21. ArangoDBでエッジと頂点を同時に作成することは可能ですか?
- 22. ポリゴン座標/頂点/ノード(GoogleマップV3)の削除方法
- 23. CのiGraphグラフの最大次数の頂点を削除
- 24. 更新/削除クエリでASPNETDB.MDFのテーブルレコードを更新/削除する方法
- 25. gremlinクエリでorientdb頂点/エッジクラスを修飾できますか?
- 26. 頂点とエッジを持つグラフを作成するための良いツールは何ですか?
- 27. Gremlinが複数の頂点値を結合する
- 28. AWS上のタイタン - エッジと頂点のドロップを防止する
- 29. グラフ内の2つの頂点を切断するエッジの最小数を削除する
- 30. グラフデータストア:200k頂点とエッジを持つグラフデータ構造をキャッシュする
既に試したことのある投稿にいくつかのコードを追加できますか?ありがとうございます。 – deltaskelta