use of org.neo4j.ogm.response.model.NodeModel in project neo4j-ogm by neo4j.
the class QueryCapabilityTest method shouldLoadNodesWithUnmappedOrNoLabels.
// #150
@Test
public void shouldLoadNodesWithUnmappedOrNoLabels() {
int movieCount = 0;
int userCount = 0;
int unmappedCount = 0;
int noLabelCount = 0;
session.query("CREATE (unknown), (m:Unmapped), (n:Movie), (n)-[:UNKNOWN]->(m)", emptyMap());
Result result = session.query("MATCH (n) return n", emptyMap());
assertThat(result).isNotNull();
Iterator<Map<String, Object>> resultIterator = result.iterator();
while (resultIterator.hasNext()) {
Map<String, Object> row = resultIterator.next();
Object n = row.get("n");
if (n instanceof User) {
userCount++;
} else if (n instanceof Movie) {
movieCount++;
} else if (n instanceof NodeModel) {
if (((NodeModel) n).getLabels().length == 0) {
noLabelCount++;
} else if (((NodeModel) n).getLabels()[0].equals("Unmapped")) {
unmappedCount++;
}
}
}
assertThat(unmappedCount).isEqualTo(1);
assertThat(noLabelCount).isEqualTo(1);
assertThat(movieCount).isEqualTo(4);
assertThat(userCount).isEqualTo(5);
}
use of org.neo4j.ogm.response.model.NodeModel in project neo4j-ogm by neo4j.
the class EntityFactoryTest method shouldBeAbleToConstructObjectWithNonPublicZeroArgConstructor.
@Test
public void shouldBeAbleToConstructObjectWithNonPublicZeroArgConstructor() {
NodeModel node = new NodeModel(163L);
node.setLabels(new String[] { "ClassWithPrivateConstructor" });
this.entityFactory.newObject(node);
}
use of org.neo4j.ogm.response.model.NodeModel in project neo4j-ogm by neo4j.
the class GraphModelAdapter method buildNode.
void buildNode(Object node, DefaultGraphModel graphModel, Set<Long> nodeIdentities, boolean generatedNode) {
long nativeId = nodeId(node);
if (nodeIdentities.contains(nativeId)) {
return;
}
nodeIdentities.add(nativeId);
NodeModel nodeModel = new NodeModel(nativeId);
List<String> labels = labels(node);
nodeModel.setLabels(labels.toArray(new String[0]));
nodeModel.setProperties(convertArrayPropertiesToCollection(properties(node)));
nodeModel.setGeneratedNode(generatedNode);
graphModel.addNode(nodeModel);
}
use of org.neo4j.ogm.response.model.NodeModel in project neo4j-ogm by neo4j.
the class RestModelAdapter method buildNode.
private NodeModel buildNode(Object node) {
NodeModel nodeModel = new NodeModel(nodeId(node));
List<String> labels = labels(node);
nodeModel.setLabels(labels.toArray(new String[labels.size()]));
nodeModel.setProperties(convertArrayPropertiesToCollection(properties(node)));
return nodeModel;
}
use of org.neo4j.ogm.response.model.NodeModel 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;
}
Aggregations