Skip to content

Commit

Permalink
changed free keyword INSPIRE class so as to support multiple keywords…
Browse files Browse the repository at this point in the history
… per dictionary - PublicaMundi/ckanext-publicamundi issue PublicaMundi#150
  • Loading branch information
smanousopoulos committed Jun 18, 2015
1 parent df07be3 commit 99376da
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 29 deletions.
7 changes: 5 additions & 2 deletions ckanext/publicamundi/lib/metadata/schemata/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ class IResponsibleParty(IObject):

class IFreeKeyword(IObject):

value = zope.schema.TextLine(
title = u"Keyword value",
values = zope.schema.List(
title = u"Keyword values",
description = u"The keyword value is a commonly used word, formalised word or phrase used to describe the subject. While the topic category is too coarse for detailed queries, keywords help narrowing a full text search and they allow for structured keyword search.\nThe value domain of this metadata element is free text.",
value_type = zope.schema.TextLine(title= u'Keyword value'),
min_length = 1,
max_length = 10,
required = True)

originating_vocabulary = zope.schema.TextLine(
Expand Down
2 changes: 1 addition & 1 deletion ckanext/publicamundi/lib/metadata/types/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FreeKeyword(Object):

zope.interface.implements(IFreeKeyword)

value = None
values = list
originating_vocabulary = None
reference_date = None
date_type = None
Expand Down
46 changes: 36 additions & 10 deletions ckanext/publicamundi/lib/metadata/types/inspire_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def deduce_basic_fields(self):
tags = []

for kw in self.free_keywords:
tags.append(dict(name=kw.value, display_name=kw.value))
for value in kw.values:
tags.append(dict(name=value, display_name=value))

for thes_name, thes_terms in self.keywords.items():
for term in thes_terms.iter_terms():
Expand Down Expand Up @@ -184,9 +185,15 @@ def to_date(s):
def to_responsible_party(alist):
result = []
for it in alist:
organization = None
if it.organization:
organization = it.organization
email = None
if it.email:
email = it.email
result.append(ResponsibleParty(
organization = unicode(it.organization),
email = unicode(it.email),
organization = organization,
email = email,
role = it.role))
return result

Expand All @@ -195,7 +202,20 @@ def to_responsible_party(alist):
md = MD_Metadata(e)

datestamp = to_date(md.datestamp)

if md.identification.title:
title = unicode(md.identification.title)
else:
# title not present - raise exception
raise Exception(_('Missing title'))
abstract = ''
if md.identification.abstract:
abstract = unicode(md.identification.abstract)

id_list = md.identification.uricode
id_list_item = None
if len(id_list):
id_list_item = id_list[0]

url_list = []
if md.distribution:
Expand Down Expand Up @@ -239,13 +259,14 @@ def to_responsible_party(alist):
# Treat as free keywords (not really a thesaurus)
vocab_date = to_date(it['thesaurus']['date'])
vocab_datetype = it['thesaurus']['datetype']
values = []
for keyword in it['keywords']:
free_keywords.append(FreeKeyword(
value = keyword,
values.append(keyword)
free_keywords.append(FreeKeyword(
values = values,
reference_date = vocab_date,
date_type = vocab_datetype,
originating_vocabulary = thes_title))

temporal_extent = []
if md.identification.temporalextent_start or md.identification.temporalextent_end:
temporal_extent = [TemporalExtent(
Expand Down Expand Up @@ -273,6 +294,9 @@ def to_responsible_party(alist):
elif it.type == 'revision':
revision_date = to_date(it.date)

lineage = None
if md.dataquality.lineage:
lineage = unicode(md.dataquality.lineage)
spatial_list = []

if len(md.identification.distance) != len(md.identification.uom):
Expand Down Expand Up @@ -357,9 +381,10 @@ def to_responsible_party(alist):
obj.contact = to_responsible_party(md.contact)
obj.datestamp = datestamp
obj.languagecode = md.languagecode
obj.title = unicode(md.identification.title)
obj.abstract = unicode(md.identification.abstract)
obj.identifier = id_list[0]
obj.title = title
obj.abstract = abstract

obj.identifier = id_list_item
obj.locator = url_list
#obj.resource_language = md.identification.resourcelanguage
obj.topic_category = topic_list
Expand All @@ -370,7 +395,8 @@ def to_responsible_party(alist):
obj.creation_date = creation_date
obj.publication_date = publication_date
obj.revision_date = revision_date
obj.lineage = unicode(md.dataquality.lineage)
obj.lineage = lineage
obj.lineage = md.dataquality.lineage
obj.spatial_resolution = spatial_list
obj.reference_system = reference_system
obj.conformity = conf_list
Expand Down
2 changes: 1 addition & 1 deletion ckanext/publicamundi/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def configure(self, config):

# Are we in debug mode?

cls._debug = asbool(config['global_conf']['debug'])
#cls._debug = asbool(config['global_conf']['debug'])

# Set supported dataset types

Expand Down
6 changes: 4 additions & 2 deletions ckanext/publicamundi/templates/package/inspire_iso.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@
{% for k in data.free_keywords -%}
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
{% for keyword in k['values'] %}
<gmd:keyword>
<gco:CharacterString>{{ k['value'] }}</gco:CharacterString>
</gmd:keyword>
<gco:CharacterString>{{ keyword }}</gco:CharacterString>
</gmd:keyword>
{% endfor %}
{% if k['originating_vocabulary'] -%}
<gmd:thesaurusName>
<gmd:CI_Citation>
Expand Down
40 changes: 27 additions & 13 deletions ckanext/publicamundi/tests/test_inspire_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,46 @@ def test_cnf2():

# Fixtures


# Find schema validation errors: date_type
fkw1 = FreeKeyword(
value = u"val",
values = [u"val"],
originating_vocabulary = u"Vocabulary",
reference_date = datetime.date(800,1,1),
date_type = "creationn")

# Find schema validation error - value not set
# Find schema validation errors: values not list

fkw2 = FreeKeyword(
values = u"val",
originating_vocabulary = u"Vocabulary",
reference_date = datetime.date(800,1,1),
date_type = "creation")

# Find schema validation invariant error - dates set without originating vocabulary
# Find schema validation error - value not set
fkw3 = FreeKeyword(
value = u"val",
originating_vocabulary = u"Vocabulary",
reference_date = datetime.date(800,1,1),
date_type = "creation")

# Find schema validation invariant error - dates set without originating vocabulary
fkw4 = FreeKeyword(
values = [u"val"],
reference_date = datetime.date.today(),
date_time = 'creation')

# Find schema validation invariant error - originating vocabulary without dates
fkw4 = FreeKeyword(
value = u"val",
fkw5 = FreeKeyword(
values = [u"val"],
originating_vocabulary = u"Vocabulary")

# Only value set - correct
fkw_correct = FreeKeyword(
value = u"val")
values = [u"val", u"val2"])

# Validate correct schema
fkw_correct_2 = FreeKeyword(
value = u"val",
values = [u"val"],
originating_vocabulary = u"original",
reference_date = datetime.date.today(),
date_type = 'creation')
Expand All @@ -130,25 +139,30 @@ def test_fkw1():
expected_keys=set(['date_type']))

def test_fkw2():
'''Free Keywords validation errors: date_type'''
'''Free Keywords validation errors: values not list'''
assert_faulty_keys(fkw2,
expected_keys=set(['value']))
expected_keys=set(['values']))

def test_fkw3():
'''Free Keywords validation invariant error - not all fields set'''
'''Free Keywords validation errors: required values missing'''
assert_faulty_keys(fkw3,
expected_keys=set(['__after']), expected_invariants=["You need to fill in the rest free-keyword fields"])
expected_keys=set(['values']))

def test_fkw4():
'''Free Keywords validation invariant error - not all fields set'''
assert_faulty_keys(fkw4,
expected_keys=set(['__after']), expected_invariants=["You need to fill in the rest free-keyword fields"])

def test_fkw5():
'''Free Keywords validation invariant error - not all fields set'''
assert_faulty_keys(fkw5,
expected_keys=set(['__after']), expected_invariants=["You need to fill in the rest free-keyword fields"])

def test_fkw6():
'''Free Keywords correct schema'''
assert_faulty_keys(fkw_correct)

def test_fkw6():
def test_fkw7():
'''Free Keywords correct schema 2'''
assert_faulty_keys(fkw_correct_2)

Expand Down

0 comments on commit 99376da

Please sign in to comment.