Java tutorial
package subsets; import java.util.ArrayList; /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.awt.Label; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; //import org.neo4j.cypher.ExecutionEngine; import org.neo4j.cypher.javacompat.ExecutionEngine; import org.neo4j.cypher.javacompat.ExecutionResult; //import org.neo4j.cypher.ExecutionResult; //import org.neo4j.cypher.internal.compiler.v2_1.planDescription.PlanDescription.Arguments$; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.DynamicLabel; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.graphdb.index.Index; import org.neo4j.graphdb.index.IndexHits; import org.neo4j.graphdb.index.IndexManager; import org.neo4j.graphdb.index.RelationshipIndex; import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.graphdb.schema.Schema; import org.neo4j.helpers.collection.IteratorUtil; import version1.Neo4jTest.HTMLParser; public class GenerateGFKMatrix { private static final String DB_PATH = "C://Users//frisch//Desktop//Neo4j//test60"; public String greeting; // START SNIPPET: vars GraphDatabaseService graphDb; Node firstNode; Node secondNode; Node thirdNode; String version = "Version 1.2"; TreeMap<String, Node> string_node = new TreeMap(); String[] mc = { "sc", "MetaCube" }; String[] sc = { "sc", "name" }; String[] sca = { "sca", "name" }; String[] bca = { "bca", "name" }; Relationship relationship; // END SNIPPET: vars // START SNIPPET: createReltype private static enum RelTypes implements RelationshipType { MEMBER_OF, BEAVER, TEST//, HAS_ROLE, HAS_PERMISSION } public static void main(String args[]) { CollectionTools ct = new CollectionTools(); GenerateGFKMatrix gfk = new GenerateGFKMatrix(); TreeMap<String, HashSet> SmartCube_SCAttribut = gfk.get_AType_Relation_BType("SmartCube", "SCAttribut", "MEMBER_OF", 1); TreeMap<String, HashSet> SCAttribut_BCAttribut_part1 = gfk.get_AType_Relation_BType("SCAttribut", "BCAttribut", "TRANSITION", -1); TreeMap<String, HashSet> SCAttribut_SCAlgo = gfk.get_AType_Relation_BType("SCAttribut", "SCAlgorithmen", "DERIVED_BY", -1); TreeMap<String, HashSet> SCAlgo_BCAttribut = gfk.get_AType_Relation_BType("SCAlgorithmen", "BCAttribut", "USES", -1); gfk.get_AType_Relation_BType("Meldekonzept", "BCAttribut", "USES", -1); //MATCH (c:Codeliste)<-[:MEMBER_OF]-(cd:Code) WHERE c.Name = "Geschaeftsfallkategorie_CL" RETURN c,cd HashSet gfks = gfk.getGFKs(); TreeMap<String, String> Meldekonzepte_formbeschreibung = gfk.getMeldekonzepte_formbeschreibung(); TreeMap<String, HashSet> Meldekonzept_GFK = new TreeMap(); for (String mk : Meldekonzepte_formbeschreibung.keySet()) { String form_beschreibung = Meldekonzepte_formbeschreibung.get(mk); Iterator it = gfks.iterator(); while (it.hasNext()) { String gfkategorie = (String) it.next(); if (form_beschreibung.contains(gfkategorie)) { HashSet dummy = Meldekonzept_GFK.get(mk); if (dummy == null) { dummy = new HashSet(); dummy.add(gfkategorie); Meldekonzept_GFK.put(mk, dummy); } dummy.add(gfkategorie); } } } TreeMap<String, HashSet> SmartCube_BCAttribut = ct .join_string_hashset_and_string_hashset(SmartCube_SCAttribut, SCAttribut_BCAttribut_part1); TreeMap<String, HashSet> SmartCube_SCAlgo = ct.join_string_hashset_and_string_hashset(SmartCube_SCAttribut, SCAttribut_SCAlgo); TreeMap<String, HashSet> SCAttribut_BCAttribut_part2 = ct .join_string_hashset_and_string_hashset(SmartCube_SCAlgo, SCAlgo_BCAttribut); TreeMap<String, HashSet> SCAttribut_BCAttribut = new TreeMap(); SCAttribut_BCAttribut.putAll(SCAttribut_BCAttribut_part1); SCAttribut_BCAttribut.putAll(SCAttribut_BCAttribut_part2); //TreeMap<String,JSONObject> SC_BC_Dependency = gfk.get_SC_BC_Dependency(); //Achtung: in der Klasse GenerateSCSubset sind alle Subsets definiert GenerateSCSubset gensubset = new GenerateSCSubset(); //Erzeuge alle Smart Cube Matrizen // TreeMap<String,TreeMap<String, HashSet>> dependency_structure= new TreeMap(); // // // ArrayList<Cube> all_cubes = gensubset.getCubeDependency_ArrayList(); // // //get all relevant Dimensions // //GFK - MappingTabelle GFK : TreeMap<String (GFK), Set of BC Attribute > TreeMap<String, HashSet> GFK_BCAttribut = new TreeMap(); //Hier wird eigentlcihe Dependency Matrix aufgebaut for (int i = 0; i < all_cubes.size(); i++) { System.out.println(((Cube) all_cubes.get(i)).Bezeichnung); Cube cube = all_cubes.get(i); for (String mk : cube.Meldekonzept_SCDimensionen.keySet()) { HashSet scattribute_pro_meldekonzept = cube.Meldekonzept_SCDimensionen.get(mk); Iterator it = scattribute_pro_meldekonzept.iterator(); //Meldekonzept get BCAttribute = MK_Basic Cube Attribut HashSet geschaeftsfallkategorien = Meldekonzept_GFK.get(mk); HashSet Meldekonzept_BCDependency = new HashSet(); //schritt fr schritt durchgehen while (it.hasNext()) {//gehe Attribute pro Meldekonzept druch String SCAttribut = (String) it.next(); HashSet BasicCubeAttribute = SCAttribut_BCAttribut.get(SCAttribut); // // // Fehler - SCAttribut_BCAttribut : Diese Datenstruktur enthaelt auch Cubes anstatt NUR SCAttribute // // //BasicCubeAttribute kann null sein ? Meldekonzept_BCDependency.addAll(BasicCubeAttribute); } Iterator gfk_iterator = geschaeftsfallkategorien.iterator(); while (gfk_iterator.hasNext()) { String gfkategorie = (String) gfk_iterator.next(); HashSet dummy = new HashSet(); dummy.addAll(Meldekonzept_BCDependency); GFK_BCAttribut.put(gfkategorie, dummy); } } all_cubes.get(i).showMeldekonzept_SCDimensionen(); } System.out.println("Test1234"); } void addAttribute_to_Treemap(String key, String element, TreeMap<String, HashSet> y) { HashSet dummy = y.get(key); if (dummy == null) { dummy = new HashSet(); dummy.add(element); y.put(key, dummy); } else { dummy.add(element); } } public void part_tree(TreeMap<String, HashSet> treemap_hashset, TreeMap<String, JSONObject> treemap_previous_jsonobject, TreeMap<String, JSONObject> treemap_next_jsonobject, boolean atbottom) { try { for (String head : treemap_hashset.keySet()) { JSONObject json_head = new JSONObject(); json_head.append("name", head.toString()); HashSet hashset = treemap_hashset.get(head); Iterator it = hashset.iterator(); while (it.hasNext()) { String leave = (String) it.next(); JSONObject json_leave = new JSONObject(); if (atbottom) { json_leave.append("name", leave); json_head.append("children", json_leave); } else { JSONObject jsononject_leave = treemap_previous_jsonobject.get(leave); if (jsononject_leave != null) { json_head.append("children", jsononject_leave); } else { JSONObject dummy = new JSONObject(); dummy.append("name", leave); json_head.append("children", dummy); } } } treemap_next_jsonobject.put(head, json_head); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //TreeMap<String,JSONObject> getSCAttributDependency(){ // // TreeMap<String,JSONObject> SCDependency = new TreeMap(); // // graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); // registerShutdownHook(graphDb); // ExecutionEngine engine = new ExecutionEngine(graphDb); // ExecutionResult result; // // try ( Transaction ignored = graphDb.beginTx() ) // { // // result = (ExecutionResult) engine.execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca"); // // TreeMap<String,HashSet> SmartCube_SC_Attribut = new TreeMap(); // TreeMap<String,HashSet> MetaCube_SmartCube = new TreeMap(); // //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap(); // //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap(); // //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList(); // // for ( Map<String, Object> row : result ) // { // String SmartCube = null;String SC_Attribut = null; // String SC_Algorithumus = null;String BC_Attribut = null; // String MetaCube = null; // // for ( Entry<String, Object> column : row.entrySet()){ // Node x = (Node) column.getValue(); // if (column.getKey().equals("sca")) SC_Attribut = (String) x.getProperty("name"); // //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name"); // if (column.getKey().equals("sc")) SmartCube = (String) x.getProperty("name"); // //for (String y :x.getPropertyKeys()) System.out.println(y); // if (column.getKey().equals("sc")) MetaCube = (String) x.getProperty("MetaCube"); // } // // System.out.println("------------------------"); // // addAttribute_to_Treemap(MetaCube,SmartCube,MetaCube_SmartCube); // // addAttribute_to_Treemap(SmartCube,SC_Attribut,SmartCube_SC_Attribut); // // // }//ende quer // // // return null; // //} TreeMap<String, JSONObject> getDepTree(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, JSONObject> name_json = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute(query);//"MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca" ArrayList<TreeMap<String, HashSet>> head_tail = new ArrayList(); for (int j = 0; j < hirarchy.size() - 1; j++) { TreeMap<String, HashSet> dummy = new TreeMap(); head_tail.add(dummy); } //TreeMap<String,HashSet> O2_O3 = new TreeMap(); //TreeMap<String,HashSet> O1_O2 = new TreeMap(); for (Map<String, Object> row : result) { ArrayList<String> objects = new ArrayList(); for (int i = 0; i < hirarchy.size(); i++) objects.add(""); for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); for (int i = 0; i < hirarchy.size(); i++) { String[] object_property = hirarchy.get(i); if (column.getKey().equals(object_property[0])) { //System.out.println(x.getProperty(object_property[1])); objects.set(i, (String) x.getProperty(object_property[1])); } } } for (int j = 0; j < hirarchy.size() - 1; j++) addAttribute_to_Treemap(objects.get(j), objects.get(j + 1), head_tail.get(j)); // addAttribute_to_Treemap(objects.get(0),objects.get(1),O1_O2); // addAttribute_to_Treemap(objects.get(1),objects.get(2),O2_O3); } //ende query for (int j = 0; j < hirarchy.size() - 1; j++) { if (j == hirarchy.size() - 1) { part_tree(head_tail.get(j), name_json, name_json, false); } else { part_tree(head_tail.get(j), null, name_json, true); } } ignored.success(); } graphDb.shutdown(); return name_json; } // working TreeMap<String, JSONObject> getDepTree_old(String query, ArrayList<String[]> hirarchy) { //staring on top graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute(query);//"MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca" TreeMap<String, HashSet> O2_O3 = new TreeMap(); TreeMap<String, HashSet> O1_O2 = new TreeMap(); for (Map<String, Object> row : result) { ArrayList<String> objects = new ArrayList(); for (int i = 0; i < hirarchy.size(); i++) objects.add(""); for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); for (int i = 0; i < hirarchy.size(); i++) { String[] object_property = hirarchy.get(i); if (column.getKey().equals(object_property[0])) { //System.out.println(x.getProperty(object_property[1])); objects.set(i, (String) x.getProperty(object_property[1])); } } } addAttribute_to_Treemap(objects.get(0), objects.get(1), O1_O2); addAttribute_to_Treemap(objects.get(1), objects.get(2), O2_O3); } //ende query part_tree(O2_O3, null, name_json1, true); part_tree(O1_O2, name_json1, name_json2, false); ignored.success(); } graphDb.shutdown(); return name_json2; } void query3() { ArrayList<String[]> hirarchy = new ArrayList<String[]>(); String[] mc = { "sc", "MetaCube" }; hirarchy.add(mc); String[] sc = { "sc", "name" }; hirarchy.add(sc); String[] sca = { "sca", "name" }; hirarchy.add(sca); String[] bca = { "bca", "name" }; hirarchy.add(sca); TreeMap<String, JSONObject> SmartCube_SCAttribut = getDepTree( "MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca", hirarchy); hirarchy.clear(); //ArrayList<String[]> hirarchy = new ArrayList<String[]>(); hirarchy.add(sc); hirarchy.add(sca); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old( "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca", hirarchy); hirarchy.clear(); hirarchy.add(sc); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree( "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy); JSONObject MetaCube = new JSONObject(); try { MetaCube.append("name", "MetaCube"); for (String key : SmartCube_SCAttribut.keySet()) { JSONObject cube = SmartCube_SCAttribut.get(key); MetaCube.append("children", cube); } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String content = MetaCube.toString(); try { //String content = json_smartcube.toString(); File file = new File("C://Users//frisch//Desktop//d3//flare.json"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } } TreeMap<String, JSONObject> get_SC_BC_Dependency() { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, HashSet> SmartCube_SC_Attribut = new TreeMap(); TreeMap<String, HashSet> MetaCube_SmartCube = new TreeMap(); TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine .execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca"); //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap(); //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap(); //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList(); for (Map<String, Object> row : result) { String SmartCube = null; String SC_Attribut = null; String SC_Algorithumus = null; String BC_Attribut = null; String MetaCube = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); if (column.getKey().equals("sca")) SC_Attribut = (String) x.getProperty("name"); //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name"); if (column.getKey().equals("sc")) SmartCube = (String) x.getProperty("name"); //for (String y :x.getPropertyKeys()) System.out.println(y); if (column.getKey().equals("sc")) MetaCube = (String) x.getProperty("MetaCube"); } System.out.println("------------------------"); addAttribute_to_Treemap(MetaCube, SmartCube, MetaCube_SmartCube); addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SC_Attribut); } //ende query } graphDb.shutdown(); ArrayList<String[]> hirarchy = new ArrayList<String[]>(); hirarchy.add(sc); hirarchy.add(sca); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old( "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca", hirarchy); hirarchy.clear(); hirarchy.add(sc); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree( "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy); SCAttribut_SCAlgo_BCAttribut.putAll(SCAttribut_BCAttribut); return SCAttribut_SCAlgo_BCAttribut; //part_tree(SmartCube_SC_Attribut, SCAttribut_SCAlgo_BCAttribut,name_json1, false); //part_tree(MetaCube_SmartCube, name_json1,name_json2, false); } TreeMap<String, HashSet> get_AType_Relation_BType(String typeA, String typeB, String relation, int direction) { //MATCH (c:Codeliste)<-[:MEMBER_OF]-(cd:Code) WHERE c.Name = "Geschaeftsfallkategorie_CL" RETURN c,cd graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, HashSet> TypeA_TypeB = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { // result = (ExecutionResult) engine.execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca"); if (direction == 1) { result = (ExecutionResult) engine .execute("MATCH (a:" + typeA + ")<-[:" + relation + "]-(b:" + typeB + ") RETURN a,b"); } else { result = (ExecutionResult) engine .execute("MATCH (a:" + typeA + ")-[:" + relation + "]->(b:" + typeB + ") RETURN a,b"); } //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap(); //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap(); //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList(); for (Map<String, Object> row : result) { String a = null; String b = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); if (column.getKey().equals("a")) a = (String) x.getProperty("name"); if (column.getKey().equals("b")) b = (String) x.getProperty("name"); } System.out.println("------------------------"); addAttribute_to_Treemap(a, b, TypeA_TypeB); } //ende query } graphDb.shutdown(); return TypeA_TypeB; } HashSet getGFKs() { //MATCH (c:Codeliste)<-[:MEMBER_OF]-(cd:Code) WHERE c.Name = "Geschaeftsfallkategorie_CL" RETURN c,cd graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; HashSet gfks = new HashSet(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute( "MATCH (c:Codeliste)<-[:MEMBER_OF]-(cd:Code) WHERE c.Name = \"Geschaeftsfallkategorie_CL\" RETURN c,cd"); for (Map<String, Object> row : result) { String cd = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); if (column.getKey().equals("cd")) cd = (String) x.getProperty("Codebezeichnung"); } System.out.println("------------------------"); if (cd != null) gfks.add(cd); } //ende query } graphDb.shutdown(); return gfks; } TreeMap<String, String> getMeldekonzepte_formbeschreibung() { //MATCH (c:Codeliste)<-[:MEMBER_OF]-(cd:Code) WHERE c.Name = "Geschaeftsfallkategorie_CL" RETURN c,cd TreeMap<String, String> eldekonzepte_formalsprache = new TreeMap(); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; HashSet gfks = new HashSet(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute("MATCH (mk:Meldekonzept) RETURN mk "); for (Map<String, Object> row : result) { String code = null; String formbeschreibung = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); try { if (column.getKey().equals("mk")) code = (String) x.getProperty("name"); if (column.getKey().equals("mk")) formbeschreibung = (String) x.getProperty("Formale Beschreibung"); } catch (Exception e) { System.out.println(e.toString()); } } System.out.println("------------------------"); if (code != null && formbeschreibung != null) eldekonzepte_formalsprache.put(code, formbeschreibung); } //ende query } graphDb.shutdown(); return eldekonzepte_formalsprache; } void query2() { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, HashSet> SmartCube_SC_Attribut = new TreeMap(); TreeMap<String, HashSet> MetaCube_SmartCube = new TreeMap(); TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine .execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca"); //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap(); //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap(); //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList(); for (Map<String, Object> row : result) { String SmartCube = null; String SC_Attribut = null; String SC_Algorithumus = null; String BC_Attribut = null; String MetaCube = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); if (column.getKey().equals("sca")) SC_Attribut = (String) x.getProperty("name"); //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name"); if (column.getKey().equals("sc")) SmartCube = (String) x.getProperty("name"); //for (String y :x.getPropertyKeys()) System.out.println(y); if (column.getKey().equals("sc")) MetaCube = (String) x.getProperty("MetaCube"); } System.out.println("------------------------"); addAttribute_to_Treemap(MetaCube, SmartCube, MetaCube_SmartCube); addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SC_Attribut); } //ende query } graphDb.shutdown(); ArrayList<String[]> hirarchy = new ArrayList<String[]>(); hirarchy.add(sc); hirarchy.add(sca); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old( "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca", hirarchy); hirarchy.clear(); hirarchy.add(sc); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree( "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy); SCAttribut_SCAlgo_BCAttribut.putAll(SCAttribut_BCAttribut); part_tree(SmartCube_SC_Attribut, SCAttribut_SCAlgo_BCAttribut, name_json1, false); part_tree(MetaCube_SmartCube, name_json1, name_json2, false); //old and working // part_tree(SmartCube_SC_Attribut, null,name_json1, true); // part_tree(MetaCube_SmartCube, name_json1,name_json2, false); //part_tree(SmartCube_SCAttribut, name_json1, name_json2, false); JSONObject MetaCube = new JSONObject(); try { MetaCube.append("name", "MetaCube"); for (String key : name_json2.keySet()) { JSONObject cube = name_json2.get(key); MetaCube.append("children", cube); } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String content = MetaCube.toString(); try { //String content = json_smartcube.toString(); File file = new File("C://Users//frisch//Desktop//d3//flare.json"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } } void query() { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine.execute( "MATCH (sc:SmartCube)<-[:MEMBER_OF]-(b:SCAttribut) -[:DERIVED_BY]->(c:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) WHERE sc.name='Kredit-Cube V1' RETURN sc,b,c,bca LIMIT 2500"); TreeMap<String, HashSet> SmartCube_SCAttribut = new TreeMap(); TreeMap<String, HashSet> SCAttribut_SCAlgo = new TreeMap(); TreeMap<String, HashSet> SCAlgo_BCAttribut = new TreeMap(); ArrayList<TreeMap<String, HashSet>> treemaps = new ArrayList(); for (Map<String, Object> row : result) { // JSONObjectX b = new JSONObjectX();//sc Attribut // JSONObjectX c = new JSONObjectX();// sc algorithmus // JSONObjectX sc = new JSONObjectX();// smart Cube // JSONObjectX bca = new JSONObjectX();//basic cube attribut String SmartCube = null; String SC_Attribut = null; String SC_Algorithumus = null; String BC_Attribut = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); System.out.println(column.getKey() + ": " + column.getValue() + x.getProperty("name")); //in Zukunft in Nodes in Objekt laden if (column.getKey().equals("b")) SC_Attribut = (String) x.getProperty("name"); if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name"); if (column.getKey().equals("sc")) SmartCube = (String) x.getProperty("name"); if (column.getKey().equals("bca")) BC_Attribut = (String) x.getProperty("name"); // if (column.getKey().equals("b")) b.append("name", x.getProperty("name")); // if (column.getKey().equals("c")) c.append("name", x.getProperty("name")); // if (column.getKey().equals("sc")) sc.append("name", x.getProperty("name")); // if (column.getKey().equals("bca")) bca.append("name", x.getProperty("name")); } System.out.println("------------------------"); addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SCAttribut); addAttribute_to_Treemap(SC_Attribut, SC_Algorithumus, SCAttribut_SCAlgo); addAttribute_to_Treemap(SC_Algorithumus, BC_Attribut, SCAlgo_BCAttribut); } //ende query //Show dependency structure //top down structure JSONObject json_smartcube = new JSONObject();// smart Cube TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); TreeMap<String, JSONObject> name_json3 = new TreeMap(); part_tree(SCAlgo_BCAttribut, null, name_json1, true); part_tree(SCAttribut_SCAlgo, name_json1, name_json2, false); part_tree(SmartCube_SCAttribut, name_json2, name_json3, false); String content = (name_json3.get("Kredit-Cube V1")).toString(); try { //String content = json_smartcube.toString(); File file = new File("C://Users//frisch//Desktop//d3//flare.json"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } } } void removeData() { try (Transaction tx = graphDb.beginTx()) { // START SNIPPET: removingData // let's remove the data //firstNode.getSingleRelationship( RelTypes.KNOWS, Direction.OUTGOING ).delete(); //firstNode.delete(); //secondNode.delete(); // END SNIPPET: removingData tx.success(); } } void shutDown() { System.out.println(); System.out.println("Shutting down database ..."); // START SNIPPET: shutdownServer graphDb.shutdown(); // END SNIPPET: shutdownServer } // START SNIPPET: shutdownHook private static void registerShutdownHook(final GraphDatabaseService graphDb) { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you "Ctrl-C" the // running application). Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graphDb.shutdown(); } }); } // END SNIPPET: shutdownHook private static void deleteFileOrDirectory(File file) { if (file.exists()) { if (file.isDirectory()) { for (File child : file.listFiles()) { deleteFileOrDirectory(child); } } file.delete(); } } }