0

I am currently usring Spring and neo4j. One mission is to display the graph using linkurious. However, how can I tell Spring through spring-data-neo4j the labels of the nodes? I need the labels to color the graph in linkurious. If using findAll() defined in the graph repository, only node properties will be returned?

Any suggestion?

UPDATE

I tried to use @QueryResult, but there's something wrong with the respond. To be more specific:

I define

@QueryResult
public class NodeWithLabel {
    GLNode glNode;
    ArrayList<String> labels;
}

then in the repository, I have

@Query("MATCH (n:GLNode) RETURN n AS glNode, labels(n) as labels")
Collection<NodeWithLabel> getAllNodesWithLabel();

Finally, I will get a result with ArrayList<E>, so the spring mvc will respond empty like [{},{},{},{}]. Normally, such as the embedded findAll() function, a LinkedHashSet<E> should be returned, in this case, the spring mvc can send back a json respond.

Luanne
  • 19,145
  • 1
  • 39
  • 51
Steven Luo
  • 2,350
  • 3
  • 18
  • 35
  • Do you want the labels of all nodes or some nodes? I just answered http://stackoverflow.com/questions/35978001/is-there-a-way-to-get-all-the-labels-for-a-node-in-sdn-4-0 if it helps. And which version of SDN? – Luanne Mar 14 '16 at 01:47
  • @Luanne Actually, I need both the nodes and lables. I have updated my question to be more specific. It's SDN 4. – Steven Luo Mar 14 '16 at 02:16

1 Answers1

1

SDN 4.0 does not map nodes/relations to domain entities in a @QueryResult. The code you've posted will work with SDN 4.1

If you want to achieve the same in SDN 4.0, you can do this:

@QueryResult
public class NodeWithLabel {
    Long id;
    Map<String,Object> node;
    ArrayList<String> labels;
}


@Query("MATCH (n:GLNode) RETURN ID(n) as id, labels(n) as labels, {properties : n} as node")
Collection<NodeWithLabel> getAllNodesWithLabel();

Note: Strongly recommend that you plan to upgrade to SDN 4.1

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Oh, yeah. BTW, I have to add the getters function for `NodeWithLabel` class in order to make spring mvc respond to HTTP request correctly., – Steven Luo Mar 14 '16 at 03:23