summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2015-01-11 15:58:01 +0200
committerLV-426 <lv-426@taproot.org.il>2015-01-11 18:30:42 +0200
commitcbb56c76266ae56fa1c71a0700b5e3c2c0075535 (patch)
tree8fcea24c615abe0b05b57cea2d8c9a9cf58632a1
parent71ccf85c80faccc031116b2850957ac6d68fe001 (diff)
__type, __label_set: expect array of length 1 in both cases on backend
-rw-r--r--src/client/model/util.js4
-rw-r--r--src/server/neo4j_util.py26
2 files changed, 19 insertions, 11 deletions
diff --git a/src/client/model/util.js b/src/client/model/util.js
index cf9f005d..501edc21 100644
--- a/src/client/model/util.js
+++ b/src/client/model/util.js
@@ -63,7 +63,7 @@ define([ 'jquery', 'model/diff' ], function($, model_diff) {
// type:
// - discard all but first label
// - adjust to lowercase
- '__type' : __sanitize_label__read(l_raw['__type']),
+ '__type' : __sanitize_label__read(l_raw['__type'][0]),
'state' : 'perm',
}, l_raw);
@@ -82,7 +82,7 @@ define([ 'jquery', 'model/diff' ], function($, model_diff) {
'__dst_id' : l_raw.target.id,
}, l_raw);
- ret['__type'] = __sanitize_label__write(l_raw.__type);
+ ret['__type'] = [__sanitize_label__write(l_raw.__type)];
delete ret.__dst;
delete ret.__src;
diff --git a/src/server/neo4j_util.py b/src/server/neo4j_util.py
index b067e033..06b9d811 100644
--- a/src/server/neo4j_util.py
+++ b/src/server/neo4j_util.py
@@ -273,25 +273,33 @@ def meta_attr_list_to_meta_attr_map(e_set, meta_attr='__label_set'):
convert a list of maps each containing a meta_attr key into a
meta_attr-mapped collection of lists with the meta_attr removed - eg:
- in: [{'id':0, '__type': 'T'}, {'id':1, '__type': 'T'}]
+ nodes:
+ in: [{'id':0, '__label_set': ['T']}, {'id':1, '__label_set': ['T']}]
+ out: { 'T': [{'id':0}, {'id':1}] }
+
+ links:
+ in: [{'id':0, '__type': ['T']}, {'id':1, '__type': ['T']}]
out: { 'T': [{'id':0}, {'id':1}] }
[!] as of 2015-01 multiple labels for relations are not supported,
which is why meta_attr='__type' should be used when calling this
function to map links
"""
+
+ assert '__label_set' == meta_attr or '__type' == meta_attr, 'type meta-attribute != __label_set or __type'
+
ret = {}
for v in e_set:
meta_attr_list = v.get(meta_attr)
- assert None != meta_attr_list, 'missing type meta-attribute'
+ assert None != meta_attr_list, 'element missing type meta-attribute'
+ assert list == type(meta_attr_list), 'element with non-list type meta-attribute set: ' + str(v)
- # Amir - refactor at will
- # handle either a list or a string - we use a list for __label_set
- # and a string for __type
- if list == type(meta_attr_list):
- v_type = v[meta_attr][0]
- else:
- v_type = v[meta_attr]
+ if '__label_set' == meta_attr:
+ assert 1 == len(meta_attr_list), 'only single-label mapping currently supported for nodes'
+ if '__type' == meta_attr:
+ assert 1 == len(meta_attr_list), 'only single-type mapping currently supported by neo4j for links'
+
+ v_type = v[meta_attr][0]
if None == ret.get(v_type): # init type list if necessary
ret[v_type] = []