static void Main(string[] args) { var excel = Path.Combine(Directory.GetCurrentDirectory(), @"Excel\Cases_List_from_Apr_2019.xlsx"); var formatJSON = Path.Combine(Directory.GetCurrentDirectory(), @"format.json"); var seibelJSON = JsonReader.ParseJsonToProduct(formatJSON); var dictionary = AnalyzeSummary.Analyze( excel, seibelJSON, "Data From Siebel", new List <string>() { "SR#", "Summary", "Date Created", "Status", "Priority", "Group", "Product Name" } ); GraphQuery.InsertData("bolt://localhost:7687", "neo4j", "test", dictionary, seibelJSON); }
public static void InsertData( string boltConnection, string username, string password, Dictionary <string, List <CaseFormat> > dictionary, Product seibelJSON) { var areaCatQuery = new StringBuilder(); var query = new StringBuilder(); var areasDict = new Dictionary <string, string>() { }; var catsDict = new Dictionary <string, string>() { }; var caseDict = new Dictionary <string, string>() { }; var node_number = 0; using (var graph = new GraphQuery(boltConnection, username, password)) { areaCatQuery.AppendLine(MergeProductNode(seibelJSON.productName, "product")); foreach (var area in seibelJSON.areas) { var areaVariable = "area" + ++node_number; areasDict.Add(area.area.ToLower(), areaVariable); areaCatQuery.AppendLine(MergeAreaNode(area.area, areaVariable)); areaCatQuery.AppendLine(MergeRelationshipBetweenNodes(areaVariable, "product", "BELONGS_TO")); foreach (var cat in area.categories) { var aliases = string.Join(", ", cat.aliases.Select(alias => $"\"{alias}\"")); var catVariable = "cat" + ++node_number; catsDict.Add(cat.umbrellaterm.ToLower(), catVariable); areaCatQuery.AppendLine(MergeCategoryNode(cat.umbrellaterm, aliases, catVariable)); areaCatQuery.AppendLine(MergeRelationshipBetweenNodes(catVariable, areaVariable, "BELONGS_TO")); } } // dictionary = { // "SR#": [ // { // Category tags // "tags": ["ssp", "payment", "scheme"], // "categoryAndConnectionType": { // "sick": ["payroll", "setup"] // } // }, // { // Category tags // "tags": ["annual"], // "categoryAndConnectionType": { // "annual": ["DIRECT"] // } // } // ] // } // AnalyzeSummary.SeibelSummary = { // "SR#": "Summary" // } foreach (var item in dictionary) { // item.Key -> SR# // item.Value -> [{tags, categoryAndConnectionType}] var summary = AnalyzeSummary.SeibelSummary[item.Key]["summary"].Replace("\\", " "); var status = AnalyzeSummary.SeibelSummary[item.Key]["status"]; var priority = AnalyzeSummary.SeibelSummary[item.Key]["priority"]; var date_created = AnalyzeSummary.SeibelSummary[item.Key]["date created"]; var group = AnalyzeSummary.SeibelSummary[item.Key]["group"]; var product_name = AnalyzeSummary.SeibelSummary[item.Key]["product name"]; var original_product_name = AnalyzeSummary.SeibelSummary[item.Key]["original product name"]; var tags = item.Value.SelectMany(csf => csf.tags.Select(tag => $"\"{tag}\"")); // ["ssp", "payment", "scheme", "annual"] var catsWithConnectionType = item.Value.SelectMany(csf => csf.categoryAndConnectionType); // [ {"sick", ["payroll", "setup"]}, {"annual", ["DIRECT"]} ] var caseVariable = "case" + ++node_number; caseDict.Add(item.Key, caseVariable); query.AppendLine(CreateCaseNode(item.Key, summary, string.Join(", ", tags), status, priority, date_created, group, product_name, original_product_name, caseVariable)); foreach (var cat in catsWithConnectionType) { var catVariable = catsDict[cat.Key]; if (cat.Value[0] == "DIRECT") { query.AppendLine(CreateRelationshipBetweenNodes( caseVariable, catVariable, "BELONGS_TO" )); } else { query.AppendLine(CreateRelationshipBetweenNodesWithProps( caseVariable, catVariable, "BELONGS_TO", "subCategories:[" + string.Join(", ", cat.Value.Select(subcat => $"\"{subcat}\"")) + "]" )); } } } Console.WriteLine(areaCatQuery.ToString() + query.ToString()); // graph.RunQuery(areaCatQuery.ToString() + query.ToString()); } }