Hot questions for Using Neo4j in neo4j apoc

Top Java Programmings / Neo4j / neo4j apoc

Question:

I am trying to update a apoc plugin for Gephi, so that I can send weights from Neo4j to Gephi. This is the original version of the plugin. What was my thinking that I could easily rearrange

private Map<String, Object> data(PropertyContainer pc, Map<String, Map<String, Object>> colors) {
    if (pc instanceof Node) {
        Node n = (Node) pc;
        String labels = Util.labelString(n);
        Map<String, Object> attributes = map("label", caption(n), "TYPE", labels);
        attributes.putAll(positions());
        attributes.putAll(color(labels,colors));
        return map(idStr(n), attributes);
    }
    if (pc instanceof Relationship) {
        Relationship r = (Relationship) pc;
        String type = r.getType().name();
        Map<String, Object> attributes = map("label", type, "TYPE", type);
        attributes.putAll(map("source", idStr(r.getStartNode()), "target", idStr(r.getEndNode()), "directed", true));
        attributes.putAll(color(type, colors));
        return map(String.valueOf(r.getId()), attributes);
    }
    return map();
}

to something like this, where I would change how relationship is being parsed, and add a weight to return

private Map<String, Object> data(PropertyContainer pc, Map<String, Map<String, Object>> colors) {
    if (pc instanceof Node) {
        Node n = (Node) pc;
        String labels = Util.labelString(n);
        Map<String, Object> attributes = map("label", caption(n), "TYPE", labels);
        attributes.putAll(positions());
        attributes.putAll(color(labels,colors));
        return map(idStr(n), attributes);
    }
    if (pc instanceof Relationship) {
        Relationship r = (Relationship) pc;
        String type = r.getType().name();
        String weight = r.getProperty("weight");
        Map<String, Object> attributes = map("label", type, "TYPE", type);
        attributes.putAll(map("source", idStr(r.getStartNode()), "target", idStr(r.getEndNode()), "directed", false,"weight",weight));
        attributes.putAll(color(type, colors));
        return map(String.valueOf(r.getId()), attributes);
    }
    return map();
}

Now the problem occurs that I am a JAVA noob and have no idea how to interact with JAVA data types. I found this documentation on property container, where i found the getProperty(String key) method and I tried to use it, like above but got the next error

/Users/Hal/Job/neo4j-apoc-procedures/src/main/java/apoc/gephi/Gephi.java:81: error: incompatible types: Object cannot be converted to String String weight = r.getProperty("weight");

I think this is some basic JAVA problem, but I have no idea how to debug this. I also tried String weight = r.getProperty(weight); but got the same error. Help appreciated


Answer:

Instead tryObject weight = r.getProperty("weight"); The documentation says getProperty returns Object.

A string is an object. But an object is not (necessarily) a string.