Java Code Examples for org.neo4j.driver.v1.types.Node#hasLabel()

The following examples show how to use org.neo4j.driver.v1.types.Node#hasLabel() . 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: CityUtils.java    From Getaviz with Apache License 2.0 6 votes vote down vote up
private static String setMethodColor(Node relatedEntity) {
	String color;
	boolean isStatic = relatedEntity.get("static").asBoolean(false);
	boolean isAbstract = relatedEntity.get("abstract").asBoolean(false);

	if (relatedEntity.hasLabel(Labels.Constructor.name())) {
		color = config.getCityColor("red");
	} else if (relatedEntity.hasLabel(Labels.Getter.name())) {
		color = config.getCityColor("light_green");
	} else if (relatedEntity.hasLabel(Labels.Setter.name())) {
		color = config.getCityColor("dark_green");
	} else if (isStatic) {
		color = config.getCityColor("yellow");
	} else if (isAbstract) {
		color = config.getCityColor("orange");
	} else {
		// Default
		color = config.getCityColor("violet");
	}
	return color;
}
 
Example 2
Source File: CityUtils.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public static String setBuildingSegmentColor(Node relatedEntity) {
	String color;
	String visibility = relatedEntity.get("visibility").asString("");
	switch (config.getScheme()) {
		case VISIBILITY:
			switch (visibility) {
				case "public":
					color = config.getCityColor("dark_green");
					break;
				case "protected":
					color = config.getCityColor("yellow");
					break;
				case "private":
					color = config.getCityColor("red");
					break;
				default:
					// Package visibility or default
					color = config.getCityColor("blue");
					break;
			}
			break;
		case TYPES:
			if(relatedEntity.hasLabel(Labels.Field.name())) {
				color = setAttributeColor(relatedEntity.id());
			} else if(relatedEntity.hasLabel(Labels.Method.name())) {
				color = setMethodColor(relatedEntity);
			} else {
				color =  config.getCityColor("blue");
			}
			break;
		default:
			color = config.getCityColor("blue");
	}

	return color;
}
 
Example 3
Source File: BuildingSegmentComparator.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static int getCompValue_Type(final Node relatedEntity) {
	if (relatedEntity.hasLabel(Labels.Field.name())) {
		boolean isPrimitive = false;
		StatementResult result = connector.executeRead("MATCH (n)-[OF_TYPE]->(t:Primitive) WHERE ID(n) = " + relatedEntity.id() + " RETURN t");
		if(result.hasNext()) {
			isPrimitive = true;
		}
		if (isPrimitive) {
			return Attributes.SortPriorities_Types.PRIMITVE;
		} else {
			return Attributes.SortPriorities_Types.COMPLEX;
		}
	} else {
		boolean isStatic = relatedEntity.get("static").asBoolean(false);
		boolean isAbstract = relatedEntity.get("abstract").asBoolean(false);
		if (relatedEntity.hasLabel(Labels.Constructor.name())) {
			return Methods.SortPriorities_Types.CONSTRUCTOR;
		} else if (relatedEntity.hasLabel(Labels.Getter.name())) {
			return Methods.SortPriorities_Types.GETTER;
		} else if (relatedEntity.hasLabel(Labels.Setter.name())) {
			return Methods.SortPriorities_Types.SETTER;
		} else if (isStatic) {
			return Methods.SortPriorities_Types.STATIC;
		} else if (isAbstract) {
			return Methods.SortPriorities_Types.ABSTRACT;
		} else {
			return Methods.SortPriorities_Types.LEFTOVER;
		}
	}
}
 
Example 4
Source File: CityLayout.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static Rectangle calculateMaxAreaRoot(Long model) {
		double sum_width = 0;
		double sum_length = 0;
		for (Node child : getChildren(model)) {
			Node entity = connector.getVisualizedEntity(child.id());
//			Map<String, Double> properties = null;
			if (entity.hasLabel(Labels.Package.name())) {
				arrangeChildren(child.id());
			}
			sum_width += properties.get(child.id())[0] + config.getBuildingHorizontalGap();
			sum_length += properties.get(child.id())[1] + config.getBuildingHorizontalGap();
		}
		return new Rectangle(0, 0, sum_width, sum_length, 1);
	}
 
Example 5
Source File: CityLayout.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static Rectangle calculateMaxArea(Long entity) {
	double sum_width = 0;
	double sum_length = 0;
	for (Node child : getChildren(entity)) {
		Node element = connector.getVisualizedEntity(child.id());
		if (element.hasLabel(Labels.Package.name())) {
			arrangeChildren(child.id());
		}
		sum_width += properties.get(child.id())[0] + config.getBuildingHorizontalGap();
		sum_length += properties.get(child.id())[1] + config.getBuildingHorizontalGap();
	}
	return new Rectangle(0, 0, sum_width, sum_length, 1);
}
 
Example 6
Source File: CityLayout.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static void adjustPositions(List<Node> children, double parentX, double parentY, double parentZ) {
	for (Node child : children) {
		Record record = connector.executeRead(
				"MATCH (p:Position)<-[:HAS]-(n)-[:VISUALIZES]->(e) WHERE ID(n) = " + child.id() + " RETURN e, p")
				.single();
		Node entity = record.get("e").asNode();
		Node position = record.get("p").asNode();
		double centerX = position.get("x").asDouble();
		double centerZ = position.get("z").asDouble();
		double centerY = position.get("y").asDouble();
		double setX = centerX + parentX + config.getBuildingHorizontalMargin();
		double setZ = centerZ + parentZ + config.getBuildingHorizontalMargin();
		double setY = centerY + parentY + config.getBuildingVerticalMargin();
		double width = properties.get(child.id())[0];
		double length = properties.get(child.id())[1];
		connector.executeWrite(String.format(
				"MATCH (c),(p) WHERE ID(c) = %d AND ID(p) = %d SET c.width = %f, c.length = %f, p.x = %f, p.y = %f, p.z = %f",
				child.id(), position.id(), width, length, setX, setY, setZ));
		double height = child.get("height").asDouble();
		if (entity.hasLabel(Labels.Package.name())) {
			double newUpperLeftX = setX - width / 2;
			double newUpperLeftZ = setZ - length / 2;
			double newUpperLeftY = setY - height / 2;
			adjustPositions(getChildren(child.id()), newUpperLeftX, newUpperLeftY, newUpperLeftZ);
		}
	}
}
 
Example 7
Source File: CEnhancement.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void enhanceNode(Record record) {
	Node node = record.get("e").asNode();
	Node declaringParent = record.get("p").asNode();

	fileNameTranslationUnit = connector.executeRead("MATCH (t:TranslationUnit)-[:DECLARES*]->(e) WHERE ID(e) = " + node.id() + " RETURN t.fileName").single().get("t.fileName").asString();

	// this was included to exclude C elements declared outside the translation unit (usage of #include)
	// but this does not work with the current jqassistant setup, since the files gets downloaded and thereby the filename is changed which is crucial
	//if (fileNameChild.equals(fileNameTranslationUnit)) {
	//If variable/constant is part of a struct, union or enum it could have the same name as another variable/constant therefore add parent name to name.
	String fqn = "";
	if ((node.hasLabel(Labels.Variable.name()) || node.hasLabel(Labels.EnumConstant.name())) && declaringParent != null
			&& (declaringParent.hasLabel(Labels.Struct.name()) || declaringParent.hasLabel(Labels.Union.name()) || declaringParent.hasLabel(Labels.Enum.name()))) {
		fqn = fileNameTranslationUnit + "_" + declaringParent.get("name") + "_" + node.get("name");
	} else if (node.get("fqn").isNull()) {
		fqn = fileNameTranslationUnit + "_" + node.get("name");
	}

	if (node.get("hash").isNull()) {
		String hash = createHash(node.get("fqn").toString());
		connector.executeWrite(
				"MATCH (n) WHERE ID(n) = " + node.id() + " SET n.hash = '" + hash + "', n.fqn = '" + fqn + "'");
	} else {
		connector.executeWrite(
				"MATCH (n) WHERE ID(n) = " + node.id() + " SET n.fqn = '" + fqn + "'");
	}
}
 
Example 8
Source File: JavaEnhancement.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private void enhanceNode(Record record) {
	Node node = record.get("n").asNode();
	Value fqnValue = node.get("fqn");
	String fqn = fqnValue.asString();
	if (fqnValue.isNull()) {
		Node container = connector.executeRead(
			"MATCH (n)<-[:DECLARES]-(container) " +
			"WHERE ID(n) = " + node.id() + " " +
			"RETURN container"
		).single().get("container").asNode();
		String containerFqn = container.get("fqn").asString();
		String name = node.get("name").asString();
		String signature = node.get("signature").asString();
		int index = signature.indexOf(" ") + 1;
		if (node.hasLabel("Method")) {
			int indexOfBracket = signature.indexOf("(");
			if (name.isEmpty()) {
				name = signature.substring(index, indexOfBracket);
			}
			fqn = containerFqn + "." + signature.substring(index);
		} else {
			if (name.isEmpty()) {
				name = signature.substring(index);
			}
			fqn = containerFqn + "." + name;
		}
		connector.executeWrite(
	"MATCH (n) WHERE ID(n) = " + node.id() + " SET n.name = '" + name + "', n.fqn = '" + fqn + "'");
	}
	connector.executeWrite(
"MATCH (n) WHERE ID(n) = " + node.id() + " SET n.hash = '" + createHash(fqn) + "'"
	);
}
 
Example 9
Source File: City2X3D.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private String toBuildingSegment(Node segment, Node entity) {
	Node position = connector.getPosition(segment.id());
	List<Record> separators = new ArrayList<>();
	connector.executeRead("MATCH (n)-[:HAS]->(ps:PanelSeparator)-[:HAS]->(p:Position) WHERE ID(n) = " + segment.id()
			+ " RETURN ps,p").forEachRemaining(separators::add);
	double x = position.get("x").asDouble();
	double y = position.get("y").asDouble();
	double z = position.get("z").asDouble();
	double width = segment.get("width").asDouble();
	double height = segment.get("height").asDouble();
	double length = segment.get("length").asDouble();
	StringBuilder builder = new StringBuilder();
	builder.append("<Group DEF='" + entity.get("hash").asString() + "'>");
	builder.append("\n");
	builder.append("\t");
	builder.append("<Transform translation='" + x + " " + y + " " + z + "'>");
	builder.append("\n");
	builder.append("\t\t <Shape>");
	builder.append("\n");
	if (buildingType == BuildingType.CITY_PANELS && entity.hasLabel(Labels.Field.name())
			&& showAttributesAsCylinders) {
		builder.append("\t\t <Cylinder radius='" + width / 2);
		builder.append("' height='" + height + "'></Cylinder>");
		builder.append("\n");
	} else {
		builder.append("\t\t <Box size='" + width + " " + height + " " + length + "'></Box>");
		builder.append("\n");
	}
	builder.append("\t\t\t <Appearance>");
	builder.append("\n");
	builder.append("\t\t\t\t <Material diffuseColor='" + segment.get("color").asString() + "'></Material>");
	builder.append("\n");
	builder.append("\t\t\t </Appearance>");
	builder.append("\n");
	builder.append("\t\t </Shape>");
	builder.append("\n");
	builder.append("\t </Transform>");
	builder.append("\n");
	for (final Record record : separators) {
		builder.append("\t");
		final Node separator = record.get("ps").asNode();
		builder.append("\n");
		builder.append("\t");
		final Node pos = record.get("p").asNode();
		builder.append("\n");
		builder.append("\t <Transform translation='" + pos.get("x").asDouble() + " " + pos.get("y").asDouble()
				+ " " + pos.get("z").asDouble() + "'>");
		builder.append("\n");
		builder.append("\t\t<Shape>");
		builder.append("\n");
		if (separator.hasLabel(Labels.Cylinder.name())) {
			builder.append("\t\t <Cylinder radius='" + separator.get("radius").asDouble() + "' height='"
					+ "\'></Cylinder>");
			builder.append("\n");
		} else {
			builder.append("\t\t <Box size='" + separator.get("width").asDouble() + " "
					+ panelSeparatorHeight + " " + separator.get("length").asDouble() + "'></Box>");
			builder.append("\n");
		}
		builder.append("\t\t\t <Appearance>");
		builder.append("\n");
		builder.append(
				"\t\t\t\t <Material diffuseColor='" + colorAsPercentage + "'></Material>");
		builder.append("\n");
		builder.append("\t\t\t </Appearance>");
		builder.append("\n");
		builder.append("\t\t </Shape>");
		builder.append("\n");
		builder.append("\t </Transform>");
		builder.append("\n");
	}
	builder.append("</Group>");
	builder.append("\n");
	return builder.toString();
}
 
Example 10
Source File: City2AFrame.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private String toBuildingSegment(Node segment, Node position) {
	Node entity = connector.getVisualizedEntity(segment.id());
	List<Node> separators = new ArrayList<>();
	connector.executeRead("MATCH (n)-[:HAS]->(ps:PanelSeparator) RETURN ps").forEachRemaining((record) -> separators.add(record.get("ps").asNode()));
	double width = segment.get("width").asDouble();
	double height = segment.get("height").asDouble();
	double length = segment.get("length").asDouble();
	StringBuilder builder = new StringBuilder();
	if (buildingType == BuildingType.CITY_PANELS && entity.hasLabel(Labels.Field.name())
			&& showAttributesAsCylinders) {
		builder.append("<a-cylinder id=\"").append(entity.get("hash").asString()).append("\"");
		builder.append("\n");
		builder.append(buildPosition(position));
		builder.append("\n");
		builder.append("\t radius=\"").append(width / 2).append("\"");
		builder.append("\n");
		builder.append("\t height=\"" + "\" ");
		builder.append("\n");
		builder.append("\t color=\"").append(segment.get("color").asString()).append("\"");
		builder.append("\n");
		builder.append("\t segments-height=\"2\"");
		builder.append("\n");
		builder.append("\t segments-radial=\"20\">");
		builder.append("\n");
		builder.append("</a-cylinder>");
		builder.append("\n");
	} else {
		builder.append("<a-box id=\"").append(entity.get("hash").asString()).append("\"");
		builder.append("\n");
		builder.append(buildPosition(position));
		builder.append("\n");
		builder.append("\t width=\"").append(width).append("\"");
		builder.append("\n");
		builder.append("\t height=\"").append(height).append("\"");
		builder.append("\n");
		builder.append("\t depth=\"").append(length).append("\"");
		builder.append("\n");
		builder.append(buildColor(segment)).append(">");
		builder.append("\n");
		builder.append("</a-box>");
		builder.append("\n");
	}
	for (final Node separator : separators) {
		final Node pos = connector.getPosition(separator.id());
		builder.append("\n");
		if (separator.hasLabel(Labels.Cylinder.name())) {
			builder.append("<a-cylinder  id=\"").append(entity.get("hash").asString()).append("\"");
			builder.append("\n");
			builder.append(buildPosition(pos));
			builder.append("\n");
			builder.append("\t radius=\"").append(separator.get("radius")).append("\" ");
			builder.append("\n");
			builder.append("\t height=\"").append(panelSeparatorHeight).append("\" ");
			builder.append("\n");
			builder.append("\t color=\"").append(color).append("\"");
			builder.append("\n");
			builder.append("\t segments-height=\"2\"");
			builder.append("\n");
			builder.append("\t segments-radial=\"20\">");
			builder.append("\n");
			builder.append("</a-cylinder>");
			builder.append("\n");
		} else {
			builder.append("<a-box id=\"").append(entity.get("hash").asString()).append("\"");
			builder.append("\n");
			builder.append(buildPosition(pos));
			builder.append("\n");
			builder.append("\t width=\"").append(separator.get("width")).append("\"");
			builder.append("\n");
			builder.append("\t height=\"").append(panelSeparatorHeight).append("\"");
			builder.append("\n");
			builder.append("\t depth=\"").append(separator.get("length")).append("\"");
			builder.append("\n");
			builder.append("\t color=\"").append(color).append("\">");
			builder.append("\n");
			builder.append("</a-box>");
			builder.append("\n");
		}
	}
	return builder.toString();
}
 
Example 11
Source File: City2City.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private void setBuildingSegmentPositions(Node building) {
		// Sorting elements
		List<Node> classElements = new ArrayList<>();
		switch (classElementsMode) {
			case ATTRIBUTES_ONLY:
				classElements.addAll(CityUtils.getData(building.id()));
				break;
			case METHODS_AND_ATTRIBUTES: {
				classElements.addAll(CityUtils.getData(building.id()));
				classElements.addAll(CityUtils.getMethods(building.id()));
				break;
			}
			default:
				classElements.addAll(CityUtils.getMethods(building.id()));
				break;
		}
		CityUtils.sortBuildingSegments(classElements);
		// upper bound of the panel below the actual panel inside the loop
		Node position = connector.getPosition(building.id());
		double lowerBsPosY = position.get("y").asDouble() + building.get("height").asDouble() / 2 + panelVerticalMargin;

		// Correcting the initial gap on top of building depending on SeparatorMode
		if (panelSeparatorMode == SeparatorModes.GAP ||
			panelSeparatorMode == SeparatorModes.SEPARATOR) {
			lowerBsPosY = lowerBsPosY - panelVerticalGap;
		}
		// System.out.println("")
		// Looping through methods of building
		for (int i = 0; i < classElements.size(); i++) {
			Node segment = classElements.get(i);
			double height = segment.get("height").asDouble();
			double width = segment.get("width").asDouble();
			// System.out.println(bs.getType() + " " + bs.getValue() + " " + bs.getModifiers() + " " + bs.getNumberOfStatements());
//			val bsPos = cityFactory.createPosition
			double x = position.get("x").asDouble();
			double y = 0;
			double z = position.get("z").asDouble();
			String panelSeparatorCypher = "";
			switch (panelSeparatorMode) {
				case NONE: { // place segments on top of each other
					y = lowerBsPosY + height / 2;
					lowerBsPosY = y + height / 2;
					break;
				}
				case GAP: { // Leave a free space between segments
					y = lowerBsPosY + panelVerticalGap + height / 2;
					lowerBsPosY = y + height / 2;
					break;
				}
				case SEPARATOR: { // Placing additional separators
					y = lowerBsPosY + height / 2;
					// Placing a separator on top of the current method if it is not last method
					if (i < classElements.size() - 1) {
						double sepY = y + height / 2 + panelSeparatorHeight / 2;
						// Deciding which shape the separator has to have
						Node nextElementType = connector.getVisualizedEntity(classElements.get(i + 1).id());
						Node segmentType = connector.getVisualizedEntity(segment.id());
						panelSeparatorCypher = String.format(
							"(psp:City:Position {x: %f, y: %f, z: %f})<-[:HAS]-(ps:City:PanelSeparator", x, sepY, z);
						if ((segmentType.hasLabel(Labels.Method.name()) &&
							nextElementType.hasLabel(Labels.Method.name())) || !showAttributesAsCylinders) {
							panelSeparatorCypher +=
								String.format(":Box {width: %f, length: %f})<-[:HAS]-", width,
									segment.get("length").asDouble());
						} else {
							panelSeparatorCypher += String.format(":Cylinder {radius: %f})<-[:HAS]-", width / 2);
						}
						lowerBsPosY = sepY + panelSeparatorHeight / 2;
						break;
					}
				}
			}
			String s = String.format(
				"MATCH(n) WHERE ID(n) = %d CREATE %s(n)-[:HAS]->(p:Position:City {x: %f, y: %f, z: %f})", segment.id(),
				panelSeparatorCypher, x, y, z);
			connector.executeWrite(s);
		}
	}
 
Example 12
Source File: C2JSON.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private String toJSON(List<Node> list) {
	StringBuilder builder = new StringBuilder();
	boolean hasElements = false;
	for (final Node el : list) {
		if (!hasElements) {
			hasElements = true;
			builder.append("[{");
		} else {
			builder.append("\n},{");
		}
		if (el.hasLabel(Labels.TranslationUnit.name())) {
			builder.append(toMetaDataTranslationUnit(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Function.name())) {
			builder.append(toMetaDataFunction(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Variable.name())) {
			builder.append(toMetaDataVariable(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.SingleCondition.name())) {
			builder.append(toMetaDataSingleCondition(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Not.name())) {
			builder.append(toMetaDataNegation(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.And.name())) {
			builder.append(toMetaDataAnd(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Or.name())) {
			builder.append(toMetaDataOr(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Struct.name())) {
			builder.append(toMetaDataStruct(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Union.name())) {
			builder.append(toMetaDataUnion(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Enum.name())) {
			builder.append(toMetaDataEnum(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.EnumConstant.name())) {
			builder.append(toMetaDataEnumValue(el));
			builder.append("\n");
		}
	}
	if (hasElements) {
		builder.append("}]");
	}
	return builder.toString();
}
 
Example 13
Source File: JQA2JSON.java    From Getaviz with Apache License 2.0 4 votes vote down vote up
private String toJSON(List<Node> list) {
	StringBuilder builder = new StringBuilder();
	boolean hasElements = false;
	for (final Node el : list) {
		if (!hasElements) {
			hasElements = true;
			builder.append("[{");
		} else {
			builder.append("\n},{");
		}
		if (el.hasLabel(Labels.Package.name())) {
			builder.append(toMetaDataNamespace(el));
			builder.append("\n");
		}
		if ((el.hasLabel(Labels.Class.name()) || el.hasLabel(Labels.Interface.name()))) {
			builder.append(toMetaDataClass(el));
			builder.append("\n");
		}
		if ((el.hasLabel(Labels.Type.name()) && el.hasLabel(Labels.Annotation.name()))) {
			builder.append(toMetaDataAnnotation(el));
			builder.append("\n");
		}
		if ((el.hasLabel(Labels.Type.name()) && el.hasLabel(Labels.Enum.name()))) {
			builder.append(toMetaDataEnum(el));
			builder.append("\n");
		}
		if (el.hasLabel(Labels.Method.name())) {
			builder.append(toMetaDataMethod(el));
			builder.append("\n");
		}
		if ((el.hasLabel(Labels.Field.name()) && (!el.hasLabel(Labels.Enum.name())))) {
			builder.append(toMetaDataAttribute(el));
		}
		if ((el.hasLabel(Labels.Field.name()) && el.hasLabel(Labels.Enum.name()))) {
			builder.append(toMetaDataEnumValue(el));
			builder.append("\n");
		}
	}
	if (hasElements) {
		builder.append("}]");
	}
	return builder.toString();
}