@Test
 @Transactional
 public void shouldCreateRelationshipWithProperty() throws Exception {
   Relationship relationship =
       neo4jTemplate.createRelationshipBetween(referenceNode, node1, "has", map("name", "rel2"));
   assertNotNull(relationship);
   assertEquals(referenceNode, relationship.getStartNode());
   assertEquals(node1, relationship.getEndNode());
   assertEquals(HAS.name(), relationship.getType().name());
   assertEquals("rel2", relationship.getProperty("name", "not set"));
 }
Esempio n. 2
0
    private Object toJsonCompatible(Object value) {
      if (value instanceof Node) {
        final Node node = (Node) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) node);
        result.put("_id", node.getId());

        final List<String> labelNames = SubGraph.getLabelNames(node);
        if (!labelNames.isEmpty()) result.put("_labels", labelNames);
        return result;
      }
      if (value instanceof Relationship) {
        final Relationship relationship = (Relationship) value;
        final Map<String, Object> result = SubGraph.toMap((PropertyContainer) relationship);
        result.put("_id", relationship.getId());
        result.put("_start", relationship.getStartNode().getId());
        result.put("_end", relationship.getEndNode().getId());
        result.put("_type", relationship.getType().name());
        return result;
      }
      if (value instanceof Map) {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) value;
        final Map<String, Object> result = new LinkedHashMap<>(map.size());
        for (Map.Entry<String, Object> entry : map.entrySet()) {
          result.put(entry.getKey(), toJsonCompatible(entry.getValue()));
        }
        return result;
      }
      if (value instanceof Iterable) {
        final List<Object> result = new ArrayList<>();
        for (Object inner : (Iterable) value) {
          result.add(toJsonCompatible(inner));
        }
        return result;
      }
      return value;
    }