Java Code Examples for org.neo4j.graphdb.Node#getPropertyKeys()

The following examples show how to use org.neo4j.graphdb.Node#getPropertyKeys() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
public static AbstractVertex convertNodeToVertex(Node node)
{
    AbstractVertex resultVertex = new Vertex();
    for (String key : node.getPropertyKeys())
    {
        if(key.equalsIgnoreCase(PRIMARY_KEY))
        {
            continue;
        }
        Object value = node.getProperty(key);
        if (value instanceof String)
        {
            resultVertex.addAnnotation(key, (String) value);
        }
        else if (value instanceof Long)
        {
            resultVertex.addAnnotation(key, Long.toString((Long) value));
        }
        else if (value instanceof Double)
        {
            resultVertex.addAnnotation(key, Double.toString((Double) value));
        }
    }
    return resultVertex;
}
 
Example 2
Source File: ZdrProcedures.java    From ongdb-lab-apoc with Apache License 2.0 5 votes vote down vote up
/**
 * 判断字符串中是否包含中文
 *
 * @param node:节点的所有属性中是否包含中文
 * @return 是否为中文
 * @warn 不能校验是否为中文标点符号
 */
@UserFunction(name = "zdr.apoc.isContainChinese")
@Description("Node is contains chinese or not")
public long isContainChinese(@Name("node") Node node) {

    Iterable<String> iterableKeys = node.getPropertyKeys();
    StringBuilder nodeValueBuilder = new StringBuilder();
    for (Iterator iterator = iterableKeys.iterator(); iterator.hasNext(); ) {
        Object next = iterator.next();
        Object nodeValue = node.getProperty((String) next);
        if (nodeValue instanceof String) {
            nodeValueBuilder.append(nodeValue);
        }
    }
    // 所有节点属性value
    char[] nodeValueChar = nodeValueBuilder.toString().toCharArray();

    int chineseCharCount = 0;
    ChineseVerify chineseVerify = new ChineseVerify();
    for (int i = 0; i < nodeValueChar.length; i++) {
        char c = nodeValueChar[i];
        if (chineseVerify.isContainChinese(String.valueOf(c))) {
            chineseCharCount++;
        }
    }
    return chineseCharCount;
}
 
Example 3
Source File: ZdrProcedures.java    From ongdb-lab-apoc with Apache License 2.0 5 votes vote down vote up
/**
 * @param
 * @return
 * @Description: TODO(节点是否包含权限)
 */
@UserFunction(name = "zdr.apoc.isContainAuthority")
@Description("Node is contains authority or not")
public boolean isContainAuthority(@Name("node") Node node) {
    Iterable<String> iterableKeys = node.getPropertyKeys();

    String prefix = "sysuser_id_";
    for (Iterator iterator = iterableKeys.iterator(); iterator.hasNext(); ) {
        String key = (String) iterator.next();
        if (key.contains(prefix)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, Map<String, String>> readHashToVertexMap(String vertexAliasInQuery, String query){
		Map<String, Map<String, String>> hashToVertexAnnotations = new HashMap<String, Map<String, String>>();
		try(Transaction tx = graphDb.beginTx()){
//			globalTxCheckin();
			try{
				Result result = graphDb.execute(query);
				Iterator<Node> nodes = result.columnAs(vertexAliasInQuery);
				while(nodes.hasNext()){
					Node node = nodes.next();
					String hashAnnotationValue = null;
					Map<String, String> annotations = new HashMap<String, String>();
					for(String key : node.getPropertyKeys()){
						if(!HelperFunctions.isNullOrEmpty(key)){
							String annotationValueString = null;
							Object annotationValueObject = node.getProperty(key);
							if(annotationValueObject == null){
								annotationValueString = "";
							}else{
								annotationValueString = annotationValueObject.toString();
							}
							if(PRIMARY_KEY.equals(key)){
								hashAnnotationValue = annotationValueString;
							}else{
								annotations.put(key, annotationValueString);
							}
						}
					}
					hashToVertexAnnotations.put(hashAnnotationValue, annotations);
				}
				return hashToVertexAnnotations;
			}catch(QueryExecutionException ex){
				logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
			}finally{
				tx.success();
			}
		}
		return hashToVertexAnnotations;
	}