Search in sources :

Example 1 with NodeModel

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);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) NodeModel(org.neo4j.ogm.response.model.NodeModel) ExtendedUser(org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser) User(org.neo4j.ogm.domain.cineasts.annotated.User) Map(java.util.Map) HashMap(java.util.HashMap) Result(org.neo4j.ogm.model.Result) Test(org.junit.Test)

Example 2 with NodeModel

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);
}
Also used : NodeModel(org.neo4j.ogm.response.model.NodeModel) Test(org.junit.Test)

Example 3 with NodeModel

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);
}
Also used : NodeModel(org.neo4j.ogm.response.model.NodeModel)

Example 4 with 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;
}
Also used : NodeModel(org.neo4j.ogm.response.model.NodeModel)

Example 5 with 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;
}
Also used : NodeModel(org.neo4j.ogm.response.model.NodeModel) RelationshipModel(org.neo4j.ogm.response.model.RelationshipModel) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

NodeModel (org.neo4j.ogm.response.model.NodeModel)9 Test (org.junit.Test)6 Map (java.util.Map)2 Individual (org.neo4j.ogm.domain.social.Individual)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)1 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)1 User (org.neo4j.ogm.domain.cineasts.annotated.User)1 RestModel (org.neo4j.ogm.model.RestModel)1 Result (org.neo4j.ogm.model.Result)1 RelationshipModel (org.neo4j.ogm.response.model.RelationshipModel)1