Skip to content

Commit

Permalink
[Fixes #33] Map json data element does not contain map sublement whe…
Browse files Browse the repository at this point in the history
…n creating a map
  • Loading branch information
afabiani committed Oct 13, 2020
1 parent e096e87 commit 35b609b
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions mapstore2_adapter/plugins/serializers.py
Expand Up @@ -139,7 +139,12 @@ def decode_base64(data):
if _a['name'] == 'abstract' and 'value' in _a:
_map_abstract = _a['value']
if 'thumb' in _a['name'] and 'value' in _a:
(_map_thumbnail, _map_thumbnail_format) = decode_base64(_a['value'])
try:
(_map_thumbnail, _map_thumbnail_format) = decode_base64(_a['value'])
except Exception:
if _a['value']:
_map_thumbnail = _a['value']
_map_thumbnail_format = 'link'
elif map_obj:
_map_title = map_obj.title
_map_abstract = map_obj.abstract
Expand Down Expand Up @@ -284,8 +289,11 @@ def decode_base64(data):

# Dumps thumbnail from MapStore2 Interface
if _map_thumbnail:
_map_thumbnail_filename = "map-%s-thumb.%s" % (map_obj.uuid, _map_thumbnail_format)
map_obj.save_thumbnail(_map_thumbnail_filename, _map_thumbnail)
if _map_thumbnail_format == 'link':
map_obj.thumbnail_url = _map_thumbnail
else:
_map_thumbnail_filename = "map-%s-thumb.%s" % (map_obj.uuid, _map_thumbnail_format)
map_obj.save_thumbnail(_map_thumbnail_filename, _map_thumbnail)

serializer.validated_data['id'] = map_obj.id
serializer.save(user=caller.request.user)
Expand All @@ -297,30 +305,33 @@ def decode_base64(data):
raise APIException("Map Configuration (data) is Mandatory!")

def perform_create(self, caller, serializer):
map_obj = self.get_geonode_map(caller, serializer)

_data = None
_attributes = None

if 'data' in serializer.validated_data:
_data = serializer.validated_data.pop('data', None)
else:
try:
_data = serializer.validated_data['data'].copy()
serializer.validated_data.pop('data')
except Exception as e:
logger.exception(e)
raise APIException("Map Configuration (data) is Mandatory!")

if 'attributes' in serializer.validated_data:
_attributes = serializer.validated_data.pop('attributes', None)
else:
try:
_attributes = serializer.validated_data['attributes'].copy()
serializer.validated_data.pop('attributes')
except Exception as e:
logger.exception(e)
raise APIException("Map Metadata (attributes) are Mandatory!")

self.set_geonode_map(caller, serializer, map_obj, _data, _attributes)
map_obj = self.get_geonode_map(caller, serializer)
self.set_geonode_map(caller, serializer, map_obj, _data.copy(), _attributes.copy())

if _data:
# Save JSON blob
GeoNodeSerializer.update_data(serializer, _data)
GeoNodeSerializer.update_data(serializer, _data.copy())

if _attributes:
# Sabe Attributes
GeoNodeSerializer.update_attributes(serializer, _attributes)
GeoNodeSerializer.update_attributes(serializer, _attributes.copy())

return serializer.save()

Expand All @@ -331,16 +342,18 @@ def perform_update(self, caller, serializer):
_attributes = None

if 'data' in serializer.validated_data:
_data = serializer.validated_data.pop('data', None)
_data = serializer.validated_data['data'].copy()
serializer.validated_data.pop('data')

# Save JSON blob
GeoNodeSerializer.update_data(serializer, _data)
GeoNodeSerializer.update_data(serializer, _data.copy())

if 'attributes' in serializer.validated_data:
_attributes = serializer.validated_data.pop('attributes', None)
_attributes = serializer.validated_data['attributes'].copy()
serializer.validated_data.pop('attributes')

# Sabe Attributes
GeoNodeSerializer.update_attributes(serializer, _attributes)
GeoNodeSerializer.update_attributes(serializer, _attributes.copy())

self.set_geonode_map(caller, serializer, map_obj, _data, _attributes)

Expand Down

0 comments on commit 35b609b

Please sign in to comment.