Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve handling/detection of multivalued fields

We were just assuming that a field with only one value was not multivalued.
It's quite possible to have a multivalued field with only a single value.
This is certainly the case for elasticsearch where an array could have only
one value.
  • Loading branch information...
commit 329e08830ab6735afc13fa5d624c6d4ebde076fa 1 parent d3e04a1
@egaumer egaumer authored
View
6 .gitignore
@@ -20,8 +20,10 @@ ui/*.egg
ui/pypesvds.egg-info
etc/transactions.xml
nbproject/*
-
+sink
+/plugins
+etc/trnews.xml
# switch to regexp syntax.
syntax: regexp
-^plugins$
+^plugins
View
10 ui/pypesvds/lib/packet.py
@@ -82,7 +82,7 @@ def get(self, attr, default=None):
if attr in self._doc:
value = self._doc[attr]
- if len(value) == 1:
+ if len(value) == 1 and self.get_meta('multi', attr) is False:
value = value[0]
else:
value = value[:]
@@ -109,8 +109,10 @@ def set(self, attr, value, multi=False, keep_meta=True):
if isinstance(value, list) and multi:
self._doc[attr] = value[:]
+ self.set_meta('multi', multi, attr)
else:
self._doc[attr] = [value]
+ self.set_meta('multi', multi, attr)
if not keep_meta and attr in self._attr_meta:
del self._attr_meta[attr]
@@ -131,7 +133,7 @@ def add(self, attr, value, multi=False):
if attr in self._doc:
LOG.debug('Attribute %s exists, not adding!' % attr)
else:
- self.set(attr, value, multi, False)
+ self.set(attr, value, multi, True)
def append(self, attr, value, extend=False):
"""Appends a value to an attribute. If the attribute is not already
@@ -366,7 +368,9 @@ def is_multivalued(self, attr):
is_multi = False
if attr in self._doc:
- is_multi = (len(self._doc[attr]) > 1)
+ is_multi = self.get_meta('multi', attr)
+ #if attr in self._doc:
+ # is_multi = (len(self._doc[attr]) > 1)
return is_multi
View
8 ui/pypesvds/plugins/xmladapter/xmladapter.py
@@ -76,7 +76,13 @@ def _do_mapping(self, doc):
roots = xml.findall(self._docroot)
for root in roots:
- newdoc = doc.clone(metas=False)
+ newdoc = doc.clone(metas=True)
+
+ try:
+ newdoc.set('id', root.get('guid'))
+ except:
+ log.warn('Missing id')
+
for mapping in self._mappings:
# determine path
Please sign in to comment.
Something went wrong with that request. Please try again.