Skip to content

Commit

Permalink
Merge branch 'main' into enum
Browse files Browse the repository at this point in the history
  • Loading branch information
konradweiss authored Mar 13, 2024
2 parents 096ea94 + 4e6fb9f commit 819458b
Showing 1 changed file with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Schema {
/** Schema definition for node entities that is persisted to the neo4j database */
data class SchemaNode(
val name: String,
val isAbstract: Boolean,
val labels: Set<String>,
val childLabels: Set<String>,
val relationships: Set<SchemaRelationship>,
Expand All @@ -55,7 +56,8 @@ class Schema {
data class SchemaRelationship(
val label: String,
val targetNode: String,
val multiplicity: Char
val multiplicity: Char,
val inherited: Boolean,
)

/**
Expand Down Expand Up @@ -424,13 +426,11 @@ class Schema {
private fun entitiesToJson(classInfo: ClassInfo): MutableList<SchemaNode> {
val entityLabel = toLabel(classInfo)

val labels: MutableSet<String> = mutableSetOf()
val labels: MutableSet<String> = mutableSetOf(entityLabel)
if (hierarchy[classInfo]?.first != null) {

hierarchy[classInfo]?.first?.let {
getHierarchy(it).forEach { labels.add(toLabel(it)) }
}
labels.add(entityLabel)
}
val childLabels: MutableSet<String> = mutableSetOf()
if (hierarchy[classInfo]?.second?.isNotEmpty() == true) {
Expand All @@ -446,23 +446,23 @@ class Schema {
if (inherentRels.isNotEmpty() && inheritedRels.isNotEmpty()) {

if (inheritedRels[entityLabel]?.isNotEmpty() == true) {
removeLabelDuplicates(inheritedRels[entityLabel])?.forEach { inherited ->
removeLabelDuplicates(inheritedRels[entityLabel])?.forEach { inheritedRel ->
var current = classInfo
var baseClass: ClassInfo? = null
while (baseClass == null) {
inherentRels[toLabel(current)]?.let { rels ->
if (rels.any { it.second == inherited.second }) {
if (rels.any { it.second == inheritedRel.second }) {
baseClass = current
}
}
hierarchy[current]?.first?.let { current = it }
}
baseClass?.let { relationshipsToJson(it, inherited) }
baseClass?.let { relationships.add(relationshipToJson(it, inheritedRel, true)) }
}
}

removeLabelDuplicates(inherentRels[entityLabel])?.forEach {
relationships.add(relationshipsToJson(classInfo, it))
relationships.add(relationshipToJson(classInfo, it, false))
}
}

Expand All @@ -481,7 +481,17 @@ class Schema {
val entityNodes =
hierarchy[classInfo]?.second?.flatMap { entitiesToJson(it) }?.toMutableList()
?: mutableListOf<Schema.SchemaNode>()
entityNodes.add(0, SchemaNode(entityLabel, labels, childLabels, relationships, properties))
entityNodes.add(
0,
SchemaNode(
entityLabel,
classInfo.isAbstract,
labels,
childLabels,
relationships,
properties
)
)

return entityNodes
}
Expand Down Expand Up @@ -599,13 +609,19 @@ class Schema {
closeMermaid(out)
}

private fun relationshipsToJson(
private fun relationshipToJson(
classInfo: ClassInfo,
relationshipLabel: Pair<String, String>
relationshipLabel: Pair<String, String>,
inherited: Boolean
): SchemaRelationship {
val fieldInfo: FieldInfo = classInfo.getFieldInfo(relationshipLabel.first)
val targetInfo = getTargetInfo(fieldInfo)
val multiplicity = if (targetInfo.first) '*' else '1'
return SchemaRelationship(relationshipLabel.second, toLabel(classInfo), multiplicity)
return SchemaRelationship(
relationshipLabel.second,
toLabel(classInfo),
multiplicity,
inherited
)
}
}

0 comments on commit 819458b

Please sign in to comment.