2014-01-14 18:01:25 +01:00
|
|
|
import ckan.plugins as p
|
|
|
|
|
2012-11-29 17:52:10 +01:00
|
|
|
from ckan.logic.schema import default_extras_schema
|
2012-11-29 12:48:36 +01:00
|
|
|
from ckan.logic.validators import (package_id_exists,
|
|
|
|
name_validator,
|
2013-01-10 13:23:01 +01:00
|
|
|
owner_org_validator,
|
2012-11-29 12:48:36 +01:00
|
|
|
package_name_validator,
|
2012-11-29 17:52:10 +01:00
|
|
|
ignore_not_package_admin,
|
2014-01-14 18:01:25 +01:00
|
|
|
boolean_validator,
|
2012-11-29 12:48:36 +01:00
|
|
|
)
|
2012-11-30 14:20:37 +01:00
|
|
|
from ckan.logic.converters import convert_to_extras, convert_from_extras
|
2012-03-06 17:01:43 +01:00
|
|
|
|
2011-05-13 15:17:58 +02:00
|
|
|
from ckan.lib.navl.validators import (ignore_missing,
|
|
|
|
not_empty,
|
|
|
|
ignore,
|
2012-11-29 12:48:36 +01:00
|
|
|
if_empty_same_as,
|
2012-11-30 14:20:37 +01:00
|
|
|
)
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
from ckanext.harvest.logic.validators import (harvest_source_url_validator,
|
|
|
|
harvest_source_type_exists,
|
|
|
|
harvest_source_config_validator,
|
2013-02-25 19:07:34 +01:00
|
|
|
harvest_source_extra_validator,
|
2012-11-30 14:20:37 +01:00
|
|
|
harvest_source_frequency_exists,
|
|
|
|
dataset_type_exists,
|
2013-02-25 19:07:34 +01:00
|
|
|
harvest_source_convert_from_config,
|
2013-09-17 17:49:19 +02:00
|
|
|
harvest_source_id_exists,
|
2013-10-03 16:51:37 +02:00
|
|
|
harvest_job_exists,
|
2013-09-17 17:49:19 +02:00
|
|
|
harvest_object_extras_validator,
|
2012-11-30 14:20:37 +01:00
|
|
|
)
|
2012-11-29 12:48:36 +01:00
|
|
|
|
|
|
|
def harvest_source_schema():
|
|
|
|
|
|
|
|
schema = {
|
|
|
|
'id': [ignore_missing, unicode, package_id_exists],
|
|
|
|
'type': [dataset_type_exists, unicode],
|
|
|
|
'url': [not_empty, unicode, harvest_source_url_validator],
|
|
|
|
'name': [not_empty, unicode, name_validator, package_name_validator],
|
|
|
|
'source_type': [not_empty, unicode, harvest_source_type_exists, convert_to_extras],
|
|
|
|
'title': [if_empty_same_as("name"), unicode],
|
|
|
|
'notes': [ignore_missing, unicode],
|
2013-01-10 13:23:01 +01:00
|
|
|
'owner_org': [owner_org_validator, unicode],
|
2014-01-14 18:01:25 +01:00
|
|
|
'private': [ignore_missing, boolean_validator],
|
2013-03-08 15:47:11 +01:00
|
|
|
'organization': [ignore_missing],
|
2012-11-29 12:48:36 +01:00
|
|
|
'frequency': [ignore_missing, unicode, harvest_source_frequency_exists, convert_to_extras],
|
2013-01-09 18:31:30 +01:00
|
|
|
'state': [ignore_missing],
|
2012-11-29 17:52:10 +01:00
|
|
|
'config': [ignore_missing, harvest_source_config_validator, convert_to_extras],
|
|
|
|
'extras': default_extras_schema(),
|
2012-11-29 12:48:36 +01:00
|
|
|
}
|
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
extras_schema = default_extras_schema()
|
|
|
|
extras_schema['__extras'] = [ignore]
|
|
|
|
|
|
|
|
schema['extras'] = extras_schema
|
|
|
|
|
2014-01-14 18:01:25 +01:00
|
|
|
if p.toolkit.check_ckan_version('2.2'):
|
|
|
|
from ckan.logic.validators import datasets_with_no_organization_cannot_be_private
|
|
|
|
schema['private'].append(datasets_with_no_organization_cannot_be_private)
|
|
|
|
|
|
|
|
|
2012-11-29 12:48:36 +01:00
|
|
|
return schema
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2013-03-25 18:38:07 +01:00
|
|
|
def harvest_source_create_package_schema():
|
2011-05-13 15:17:58 +02:00
|
|
|
|
2012-11-29 12:48:36 +01:00
|
|
|
schema = harvest_source_schema()
|
2013-02-25 19:07:34 +01:00
|
|
|
schema['__extras'] = [harvest_source_extra_validator]
|
2011-05-13 15:17:58 +02:00
|
|
|
schema['save'] = [ignore]
|
2012-11-29 12:48:36 +01:00
|
|
|
schema.pop("id")
|
2011-05-13 15:17:58 +02:00
|
|
|
|
|
|
|
return schema
|
2012-11-29 12:48:36 +01:00
|
|
|
|
2013-03-28 16:00:44 +01:00
|
|
|
def harvest_source_update_package_schema():
|
|
|
|
|
|
|
|
schema = harvest_source_create_package_schema()
|
2013-06-27 13:15:51 +02:00
|
|
|
schema['owner_org'] = [ignore_missing, owner_org_validator, unicode]
|
2013-03-28 16:00:44 +01:00
|
|
|
|
|
|
|
return schema
|
|
|
|
|
2013-03-25 18:38:07 +01:00
|
|
|
def harvest_source_show_package_schema():
|
2012-11-30 14:20:37 +01:00
|
|
|
|
|
|
|
schema = harvest_source_schema()
|
|
|
|
schema.update({
|
|
|
|
'source_type': [convert_from_extras, ignore_missing],
|
|
|
|
'frequency': [convert_from_extras, ignore_missing],
|
2013-02-25 19:07:34 +01:00
|
|
|
'config': [convert_from_extras, harvest_source_convert_from_config, ignore_missing],
|
2014-01-14 18:01:25 +01:00
|
|
|
'metadata_created': [],
|
|
|
|
'metadata_modified': [],
|
2014-10-08 13:02:26 +02:00
|
|
|
'owner_org': [],
|
|
|
|
'creator_user_id': [],
|
|
|
|
'organization': [],
|
|
|
|
'notes': [],
|
|
|
|
'revision_id': [],
|
2015-11-13 14:32:55 +01:00
|
|
|
'revision_timestamp': [ignore_missing],
|
|
|
|
'tracking_summary': [ignore_missing],
|
2012-11-30 14:20:37 +01:00
|
|
|
})
|
|
|
|
|
2014-01-14 18:01:25 +01:00
|
|
|
schema['__extras'] = [ignore]
|
|
|
|
|
2012-11-30 14:20:37 +01:00
|
|
|
return schema
|
2013-09-17 17:49:19 +02:00
|
|
|
|
|
|
|
def harvest_object_create_schema():
|
|
|
|
schema = {
|
|
|
|
'guid': [ignore_missing, unicode],
|
|
|
|
'content': [ignore_missing, unicode],
|
|
|
|
'state': [ignore_missing, unicode],
|
2013-10-03 16:51:37 +02:00
|
|
|
'job_id': [harvest_job_exists],
|
2013-09-17 17:49:19 +02:00
|
|
|
'source_id': [ignore_missing, harvest_source_id_exists],
|
|
|
|
'package_id': [ignore_missing, package_id_exists],
|
|
|
|
'extras': [ignore_missing, harvest_object_extras_validator],
|
|
|
|
}
|
|
|
|
return schema
|
|
|
|
|