diff --git a/ckanext/publicamundi/lib/metadata/schemata/_common.py b/ckanext/publicamundi/lib/metadata/schemata/_common.py index e672f68..eb7a929 100644 --- a/ckanext/publicamundi/lib/metadata/schemata/_common.py +++ b/ckanext/publicamundi/lib/metadata/schemata/_common.py @@ -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( diff --git a/ckanext/publicamundi/lib/metadata/types/_common.py b/ckanext/publicamundi/lib/metadata/types/_common.py index 847f357..84eeab3 100644 --- a/ckanext/publicamundi/lib/metadata/types/_common.py +++ b/ckanext/publicamundi/lib/metadata/types/_common.py @@ -63,7 +63,7 @@ class FreeKeyword(Object): zope.interface.implements(IFreeKeyword) - value = None + values = list originating_vocabulary = None reference_date = None date_type = None diff --git a/ckanext/publicamundi/lib/metadata/types/inspire_metadata.py b/ckanext/publicamundi/lib/metadata/types/inspire_metadata.py index f7fc609..78205d9 100644 --- a/ckanext/publicamundi/lib/metadata/types/inspire_metadata.py +++ b/ckanext/publicamundi/lib/metadata/types/inspire_metadata.py @@ -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(): @@ -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 @@ -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: @@ -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( @@ -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): @@ -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 @@ -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 diff --git a/ckanext/publicamundi/plugins.py b/ckanext/publicamundi/plugins.py index 9285f4b..4643448 100644 --- a/ckanext/publicamundi/plugins.py +++ b/ckanext/publicamundi/plugins.py @@ -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 diff --git a/ckanext/publicamundi/templates/package/inspire_iso.xml b/ckanext/publicamundi/templates/package/inspire_iso.xml index 3a05dd7..756d8d8 100644 --- a/ckanext/publicamundi/templates/package/inspire_iso.xml +++ b/ckanext/publicamundi/templates/package/inspire_iso.xml @@ -202,9 +202,11 @@ {% for k in data.free_keywords -%} + {% for keyword in k['values'] %} - {{ k['value'] }} - + {{ keyword }} + + {% endfor %} {% if k['originating_vocabulary'] -%} diff --git a/ckanext/publicamundi/tests/test_inspire_common.py b/ckanext/publicamundi/tests/test_inspire_common.py index af68a55..b41d3c3 100644 --- a/ckanext/publicamundi/tests/test_inspire_common.py +++ b/ckanext/publicamundi/tests/test_inspire_common.py @@ -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') @@ -130,14 +139,14 @@ 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''' @@ -145,10 +154,15 @@ def test_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)