use of org.neo4j.ogm.response.model.RelationshipModel in project neo4j-ogm by neo4j.
the class MultiStatementCypherCompiler method groupRelationshipsByType.
private Map<String, Set<Edge>> groupRelationshipsByType(List<RelationshipBuilder> relationshipBuilders) {
Map<String, Set<Edge>> relsByType = new HashMap<>();
for (RelationshipBuilder relationshipBuilder : relationshipBuilders) {
if (!relsByType.containsKey(relationshipBuilder.type())) {
relsByType.put(relationshipBuilder.type(), new HashSet<>());
}
// Replace the node ids
RelationshipModel edge = (RelationshipModel) relationshipBuilder.edge();
edge.setStartNode(context.getId(edge.getStartNode()));
edge.setEndNode(context.getId(edge.getEndNode()));
relsByType.get(relationshipBuilder.type()).add(edge);
relsByType.get(relationshipBuilder.type()).add(edge);
}
return relsByType;
}
use of org.neo4j.ogm.response.model.RelationshipModel in project neo4j-ogm by neo4j.
the class RestModelAdapter method buildRelationship.
private RelationshipModel buildRelationship(Object relationship) {
RelationshipModel relationshipModel = new RelationshipModel();
relationshipModel.setId(relationshipId(relationship));
relationshipModel.setStartNode(startNodeId(relationship));
relationshipModel.setEndNode(endNodeId(relationship));
relationshipModel.setType(relationshipType(relationship));
relationshipModel.setProperties(properties(relationship));
return relationshipModel;
}
use of org.neo4j.ogm.response.model.RelationshipModel in project neo4j-ogm by neo4j.
the class RestModelAdapter method buildEntity.
private Object buildEntity(Map entity) {
if (entity.containsKey("metadata") && ((Map) entity.get("metadata")).get("id") != null) {
Map entityMetadata = (Map) entity.get("metadata");
if (entityMetadata.containsKey("labels")) {
List<String> labelList = (List<String>) (entityMetadata.get("labels"));
String[] labels = new String[labelList.size()];
labels = labelList.toArray(labels);
NodeModel nodeModel = new NodeModel(((Number) entityMetadata.get("id")).longValue());
nodeModel.setProperties((Map) entity.get("data"));
nodeModel.setLabels(labels);
return nodeModel;
} else if (entityMetadata.containsKey("type")) {
String relationshipType = (String) entityMetadata.get("type");
RelationshipModel relationshipModel = new RelationshipModel();
relationshipModel.setId(((Number) entityMetadata.get("id")).longValue());
relationshipModel.setProperties((Map) entity.get("data"));
relationshipModel.setType(relationshipType);
String startURL = (String) entity.get("start");
String endURL = (String) entity.get("end");
relationshipModel.setStartNode(Long.valueOf(startURL.substring(startURL.lastIndexOf("/") + 1)));
relationshipModel.setEndNode(Long.valueOf(endURL.substring(endURL.lastIndexOf("/") + 1)));
return relationshipModel;
}
}
return entity;
}
use of org.neo4j.ogm.response.model.RelationshipModel in project neo4j-ogm by neo4j.
the class MultiStatementCypherCompiler method createRelationshipsStatements.
@Override
public List<Statement> createRelationshipsStatements() {
assertStatementFactoryExists();
// Group relationships by type and non-null properties
// key: relationship type, value: Map where key=Set<Property strings>, value: Set of edges with those properties
Map<String, Map<String, Set<Edge>>> relsByTypeAndProps = new HashMap<>();
for (RelationshipBuilder relationshipBuilder : newRelationshipBuilders) {
if (relationshipBuilder.edge().getStartNode() == null || relationshipBuilder.edge().getEndNode() == null) {
// TODO this is a carry forward from the old emitters. We want to prevent this rel builder getting created or remove it
continue;
}
Map<String, Set<Edge>> relsByProps = relsByTypeAndProps.computeIfAbsent(relationshipBuilder.type(), (key) -> new HashMap<>());
RelationshipModel edge = (RelationshipModel) relationshipBuilder.edge();
String primaryId = edge.getPrimaryIdName();
Set<Edge> rels = relsByProps.computeIfAbsent(primaryId, (s) -> new HashSet<>());
edge.setStartNode(context.getId(edge.getStartNode()));
edge.setEndNode(context.getId(edge.getEndNode()));
rels.add(edge);
}
List<Statement> statements = new ArrayList<>();
// For each relationship type
for (Map<String, Set<Edge>> edgesByProperties : relsByTypeAndProps.values()) {
// For each set of unique property keys
for (Set<Edge> edges : edgesByProperties.values()) {
NewRelationshipStatementBuilder newRelationshipBuilder = new NewRelationshipStatementBuilder(edges, statementFactory);
statements.add(newRelationshipBuilder.build());
}
}
return statements;
}
use of org.neo4j.ogm.response.model.RelationshipModel in project neo4j-ogm by neo4j.
the class GraphModelAdapter method buildRelationship.
void buildRelationship(Object relationship, DefaultGraphModel graphModel, Set<Long> edgeIdentities) {
if (edgeIdentities.contains(relationshipId(relationship))) {
return;
}
edgeIdentities.add(relationshipId(relationship));
RelationshipModel edgeModel = new RelationshipModel();
edgeModel.setId(relationshipId(relationship));
edgeModel.setType(relationshipType(relationship));
edgeModel.setStartNode(startNodeId(relationship));
edgeModel.setEndNode(endNodeId(relationship));
edgeModel.setProperties(convertArrayPropertiesToCollection(properties(relationship)));
graphModel.addRelationship(edgeModel);
}
Aggregations