use of de.catma.repository.git.graph.NodeType.AnnotationProperty in project catma by forTEXT.
the class GraphWriter method addTagReferences.
void addTagReferences(String revisionHash, Vertex collectionV, List<TagReference> tagReferences) {
final ArrayListMultimap<TagInstance, Range> tagInstancesAndRanges = ArrayListMultimap.create();
tagReferences.forEach(tagReference -> {
tagInstancesAndRanges.put(tagReference.getTagInstance(), tagReference.getRange());
});
Map<String, Vertex> tagNodesById = new HashMap<>();
Set<String> availablePropertyDefIds = new HashSet<>();
for (TagInstance ti : tagInstancesAndRanges.keySet()) {
List<Range> ranges = tagInstancesAndRanges.get(ti);
List<Integer> flatRanges = ranges.stream().sorted().flatMap(range -> Stream.of(range.getStartPoint(), range.getEndPoint())).collect(Collectors.toList());
if (ti.getAuthor() == null) {
ti.setAuthor(user.getIdentifier());
}
String tagsetId = ti.getTagsetId();
String tagId = ti.getTagDefinitionId();
Vertex tagInstanceV = graph.addVertex(nt(TagInstance));
tagInstanceV.property("tagInstanceId", ti.getUuid());
tagInstanceV.property("author", ti.getAuthor());
tagInstanceV.property("timestamp", ti.getTimestamp());
tagInstanceV.property("ranges", flatRanges);
collectionV.addEdge(rt(hasInstance), tagInstanceV);
Vertex tagV = tagNodesById.get(tagId);
GraphTraversalSource g = graph.traversal();
if (tagV == null) {
GraphTraversal<Vertex, Vertex> traversal = g.V().has(nt(ProjectRevision), "revisionHash", revisionHash).outE(rt(hasTagset)).inV().has(nt(Tagset), "tagsetId", tagsetId).outE(rt(hasTag)).inV().has(nt(Tag), "tagId", tagId);
if (traversal.hasNext()) {
tagV = traversal.next();
tagNodesById.put(tagId, tagV);
}
}
if (tagV != null) {
// usually the Tag should always be present,
// because we delete stale Annotations when loading the Collection from git
// if we hit an orphan Annotation at this stage it gets ignored
// until the next sync might bring the corresponding Tag
tagV.addEdge(rt(hasInstance), tagInstanceV);
for (Property property : ti.getUserDefinedProperties()) {
if (availablePropertyDefIds.contains(property.getPropertyDefinitionId()) || g.V(tagV).outE(rt(hasProperty)).inV().has(nt(Property), "uuid", property.getPropertyDefinitionId()).hasNext()) {
Vertex annoPropertyV = graph.addVertex(nt(AnnotationProperty));
annoPropertyV.property("uuid", property.getPropertyDefinitionId());
annoPropertyV.property("values", property.getPropertyValueList());
tagInstanceV.addEdge(rt(hasProperty), annoPropertyV);
availablePropertyDefIds.add(property.getPropertyDefinitionId());
}
}
}
}
}
Aggregations