Java Code Examples for org.neo4j.driver.v1.StatementResult#forEachRemaining()

The following examples show how to use org.neo4j.driver.v1.StatementResult#forEachRemaining() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RD2RD.java    From Getaviz with Apache License 2.0 6 votes vote down vote up
private ArrayList<SubDisk> createSubDisksList() {
    ArrayList<SubDisk> list = new ArrayList<>();
    StatementResult result =  connector.executeRead("MATCH (p)-[:CONTAINS]->(d:SubDisk)-[:VISUALIZES]->(element) "
            + "RETURN d.ringWidth AS ringWidth, d.height as height," +
            " d.size AS size, ID(d) AS id, ID(p) AS parentID, ID(element) AS visualizedID ORDER BY element.hash");
    result.forEachRemaining(d -> {
        long visualizedID = d.get("visualizedID").asLong();
        long parentID = d.get("parentID").asLong();
        long id = d.get("id").asLong();
        double ringWidth = d.get("ringWidth").asDouble();
        double height = d.get("height").asDouble();
        SubDisk disk = new SubDisk(visualizedID, parentID, id, ringWidth, height);
        list.add(disk);
        setPositionToPackages(disk);
    });
    return list;
}
 
Example 2
Source File: C2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addVariables() {
	try {
		String query = "MATCH (t:TranslationUnit)-[:DECLARES]->(v:Variable) WHERE EXISTS(v.hash) RETURN v as node, ID(t) as tID";
		StatementResult translationUnits = connector.executeRead(query);
		translationUnits.forEachRemaining((result) -> {
			RDElement element = factory.createFromVariable(result, height, ringWidthAD, dataTransparency, dataColor);
			model.addRDElement(element);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 3
Source File: C2JSON.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private String toMetaDataOr(Node orNode) {
	ArrayList<String> connectedConditions = new ArrayList<>();
	StatementResult connections = connector.executeRead(
			"MATCH (orNode:And)-[:CONNECTS]->(condition) WHERE ID(orNode) = " + orNode.id() + " RETURN condition.hash");
	connections.forEachRemaining(condition -> connectedConditions.add(condition.get("hash").asString()));

	return formatLine("id", orNode.get("hash").asString()) +
			formatLine("type", "Or") +
			formatEndline("connected", removeBrackets(connectedConditions));
}
 
Example 4
Source File: C2JSON.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private String toMetaDataAnd(Node andNode) {
	ArrayList<String> connectedConditions = new ArrayList<>();
	StatementResult connections = connector.executeRead(
			"MATCH (andNode:And)-[:CONNECTS]->(condition) WHERE ID(andNode) = " + andNode.id() + " RETURN condition.hash");
	connections.forEachRemaining(condition -> connectedConditions.add(condition.get("hash").asString()));

	return formatLine("id", andNode.get("hash").asString()) +
			formatLine("type", "And") +
			formatEndline("connected", removeBrackets(connectedConditions));
}
 
Example 5
Source File: JQA2City.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void namespaceToDistrict(Long namespace, Long parent) {
	long district = connector.addNode(cypherCreateNode(parent,namespace,Labels.District.name()),"n").id();
	StatementResult subPackages = connector.executeRead("MATCH (n)-[:CONTAINS]->(p:Package) WHERE ID(n) = " + namespace +
		" RETURN p");
	StatementResult subTypes = connector.executeRead("MATCH (n)-[:CONTAINS]->(t:Type) WHERE ID(n) = " + namespace +
		" AND EXISTS(t.hash) AND (t:Class OR t:Interface) AND NOT t:Inner RETURN t");
	subPackages.forEachRemaining((result) -> namespaceToDistrict(result.get("p").asNode().id(), district));
	subTypes.forEachRemaining((result) -> structureToBuilding(result.get("t").asNode().id(), district));
}
 
Example 6
Source File: RD2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private ArrayList<MainDisk> getMainDisks(StatementResult result) {
    ArrayList<MainDisk> list = new ArrayList<>();
    result.forEachRemaining(d -> {
        long visualizedID = d.get("visualizedID").asLong();
        long parentID = d.get("parentID").asLong();
        long id = d.get("id").asLong();
        double ringWidth = d.get("ringWidth").asDouble();
        double height = d.get("height").asDouble();
        MainDisk disk = new MainDisk(visualizedID, parentID, id, ringWidth, height);
        list.add(disk);
        setPositionToPackages(disk);
    });
    return list;
}
 
Example 7
Source File: RD2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private ArrayList<DiskSegment> getDiskSegments(StatementResult result) {
    ArrayList<DiskSegment> list = new ArrayList<>();
    result.forEachRemaining(f -> {
        long parentID = f.get("parentID").asLong();
        long id = f.get("id").asLong();
        double size = f.get("size").asDouble();
        String name = f.get("name").asString();
        DiskSegment innerSegment = new DiskSegment(parentID, id, size, dataFactor);
        innerSegment.setFqn(name);
        list.add(innerSegment);
    });
    return list;
}
 
Example 8
Source File: C2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addStructs() {
	try {
		String query = "MATCH (p)-[:DECLARES]->(el) WHERE EXISTS(el.hash) " +
				"AND (el:Union OR el:Struct OR el:Enum) RETURN el as node, ID(p) as tID";
		StatementResult translationUnits = connector.executeRead(query);
		translationUnits.forEachRemaining((result) -> {
			RDElement element = factory.createFromVariable(result, height, ringWidthAD, dataTransparency, dataColor);
			model.addRDElement(element);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 9
Source File: JQA2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addPackagesNoRoot() {
	try {
		StatementResult packagesNoRoot = connector.executeRead(
				"MATCH (n:Package) WHERE NOT (n)<-[:CONTAINS]-(:Package) RETURN ID(n) AS id");
		packagesNoRoot.forEachRemaining((node) -> {
			MainDisk disk = new MainDisk(node.get("id").asLong(), -1, ringWidth, height,
					namespaceTransparency);
			model.addRDElement(disk);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 10
Source File: C2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addFunctions() {
	try {
		String query = "MATCH (t:TranslationUnit)-[:DECLARES]->(f:Function) WHERE EXISTS(f.hash) RETURN f as node, ID(t) as tID";
		StatementResult translationUnits = connector.executeRead(query);
		translationUnits.forEachRemaining((result) -> {
			RDElement element = factory.createFromFunction(result, height, ringWidthAD, methodTransparency, minArea, methodColor);
			model.addRDElement(element);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 11
Source File: C2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addTranslationUnits() {
//	MainDisk root = new MainDisk(-1, -1, ringWidth, height, namespaceTransparency);
//	model.addRDElement(root);
	try {
		StatementResult translationUnits = connector.executeRead("MATCH (f:File)-[:CONTAINS]->(n:TranslationUnit) RETURN ID(n) as id, ID(f) as pId");
		translationUnits.forEachRemaining((node) -> {
			SubDisk disk = new SubDisk(node.get("id").asLong(), node.get("pId").asLong(), ringWidth, height, classTransparency, classColor);
			model.addRDElement(disk);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 12
Source File: C2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addFiles() {
	try {
		StatementResult translationUnits = connector.executeRead("MATCH (n:File) RETURN ID(n) as id");
		translationUnits.forEachRemaining((node) -> {
			MainDisk disk = new MainDisk(node.get("id").asLong(), -1, ringWidth, height, namespaceTransparency);
			model.addRDElement(disk);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 13
Source File: JQA2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addFields() {
	try {
		StatementResult fields = connector.executeRead("MATCH (n:Package)-[:CONTAINS]->(t:Type)-[:DECLARES]->(f:Field)" +
				" WHERE EXISTS(t.hash) AND (t:Class OR t:Interface OR t:Annotation OR t:Enum) AND NOT t:Inner AND EXISTS(f.hash)" +
				" RETURN f AS node, ID(t) AS tID");
		fields.forEachRemaining(result -> {
			RDElement element = factory.createFromField(result, ringWidthAD, height, dataTransparency, dataColor);
			model.addRDElement(element);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 14
Source File: JQA2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addMethods() {
	try {
		StatementResult methods = connector.executeRead("MATCH (n:Package)-[:CONTAINS]->(t:Type)-[:DECLARES]->(m:Method)" +
				" WHERE EXISTS(t.hash) AND (t:Class OR t:Interface OR t:Annotation OR t:Enum) AND NOT t:Inner AND EXISTS(m.hash)" +
				" RETURN m AS node, m.effectiveLineCount AS line, ID(t) AS tID");
		methods.forEachRemaining(result -> {
			RDElement element = factory.createFromMethod(result, height, ringWidth, ringWidthAD, methodTransparency, minArea, methodColor);
			model.addRDElement(element);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 15
Source File: JQA2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addTypes() {
	try {
		StatementResult result = connector.executeRead(
				"MATCH (n:Package)-[:CONTAINS]->(t:Type) WHERE EXISTS(t.hash) AND (t:Class OR t:Interface " +
						"OR t:Annotation OR t:Enum) AND NOT t:Inner RETURN ID(t) AS tID, ID(n) AS nID");
		result.forEachRemaining(node -> {
			SubDisk disk = new SubDisk(node.get("tID").asLong(), node.get("nID").asLong(),
					ringWidth, height, classTransparency, classColor);
			model.addRDElement(disk);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 16
Source File: JQA2RD.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void addPackagesWithRoot() {
	try {
		StatementResult packagesRoot = connector.executeRead(
				"MATCH (n:Package)-[:CONTAINS]->(p:Package) WHERE EXISTS (p.hash) RETURN ID(p) AS pID, ID(n) AS nID");
		packagesRoot.forEachRemaining(node -> {
			MainDisk disk = new MainDisk(node.get("pID").asLong(), node.get("nID").asLong(),
					ringWidth, height, namespaceTransparency);
			model.addRDElement(disk);
		});
	} catch (Exception e) {
		log.error(e);
	}
}
 
Example 17
Source File: JQA2City.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private void structureToBuilding(Long structure, Long parent) {
	long building = connector.addNode(cypherCreateNode(parent, structure, Labels.Building.name()),"n").id();
	StatementResult methods = connector.executeRead("MATCH (n)-[:DECLARES]->(m:Method) WHERE ID(n) = " + structure +
		" AND EXISTS(m.hash) RETURN m");
	StatementResult attributes = connector.executeRead("MATCH (n)-[:DECLARES]->(a:Field) WHERE ID(n) = " + structure +
		" AND EXISTS(a.hash) RETURN a");
	if (buildingType == BuildingType.CITY_FLOOR && methods != null) {
		methods.forEachRemaining((result) -> methodToFloor(result.get("m").asNode().id(), building));
		attributes.forEachRemaining((result) -> attributeToChimney(result.get("a").asNode().id(), building));
	} else {
		if (originalBuildingMetric == BuildingMetric.NOS) {
			int numberOfStatements = 0;
			if (methods != null) {
				for(Record record : methods.list()) {
					Node method = record.get("m").asNode();
					int effectiveLineCount = 0;
					if (method.containsKey("effectiveLineCount")) {
						effectiveLineCount = method.get("effectiveLineCount").asInt();
					}
					numberOfStatements += effectiveLineCount;
				}
			}
			connector.executeWrite("MATCH(n) WHERE ID(n) = " + building + " SET n.numberOfStatements = " +
				numberOfStatements);
		}

		if ((classElementsMode == ClassElementsModes.METHODS_AND_ATTRIBUTES ||
			classElementsMode == ClassElementsModes.METHODS_ONLY)) {
			if (methods != null) {
				methods.forEachRemaining((result) -> methodToBuildingSegment(result.get("m").asNode().id(), building));
			}
		}

		if (classElementsMode == ClassElementsModes.METHODS_AND_ATTRIBUTES ||
			classElementsMode == ClassElementsModes.ATTRIBUTES_ONLY) {
			attributes.forEachRemaining((result) -> attributeToBuildingSegment(result.get("a").asNode().id(), building));
		}
	}
	StatementResult subStructures = connector.executeRead("MATCH (n)-[:DECLARES]->(t:Type:Inner) WHERE ID(n) = " + structure +
		" AND EXISTS(t.hash) RETURN t");
	subStructures.forEachRemaining((result) -> structureToBuilding(result.get("t").asNode().id(), parent));
}