Skip to content

Commit

Permalink
fixes for review
Browse files Browse the repository at this point in the history
  • Loading branch information
stbnrivas committed Apr 29, 2021
1 parent 4efaad6 commit 57d273c
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 32 deletions.
4 changes: 2 additions & 2 deletions app/controllers/gobierto_data/api/v1/datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class DatasetsController < BaseController
def catalog
@catalog = DatasetPresenter.new(current_site).build_catalog
respond_to do |format|
format.xml
end
format.xml
end
end

# GET /api/v1/data/datasets
Expand Down
38 changes: 17 additions & 21 deletions app/presenters/gobierto_data/dataset_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module GobiertoData
class DatasetPresenter
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TranslationHelper

attr_reader :site

Expand All @@ -11,48 +12,43 @@ def initialize(site)
def build_catalog
catalog = {
identifier_uri: url_helpers.gobierto_data_root_url(host: site.domain),
title: "dcat catalog for #{site}",
description: "this is catalog published by #{@catalog_identifier_uri} which contains datasets",
title: I18n.t('presenters.gobierto_data.catalog.title',site: site),
description: I18n.t('presenters.gobierto_data.catalog.description',site: site, publisher_url: url_helpers.gobierto_data_root_url(host: site.domain)),
issued: site.created_at,
modified: GobiertoData::Dataset.where(site_id: site.id).maximum(:created_at) || site.created_at,
languages: site["configuration_data"]["available_locales"],
modified: site.updated_at,
language: site_locale,
homepage: url_helpers.gobierto_data_root_url(host: site.domain),
license_url: "https://opendatacommons.org/licenses/odbl/",
datasets: build_datasets_for_catalog
}
end

private

def build_datasets_for_catalog
datasets = []
Dataset.where(site_id: site.id).visibles.each do |dataset|
datasets << build_dataset_for_catalog(dataset)
site.datasets.visibles.map do |dataset|
build_dataset_for_catalog(dataset)
end
datasets
end

def build_dataset_for_catalog(dataset)
{
url: url_helpers.gobierto_data_datasets_url(host: site.domain, id: dataset.slug),
title: dataset.name,
description: description_custom_field_record(dataset),
keywords: [],
issued: dataset.created_at,
modified: dataset.updated_at,
languages: [site_locale],
license_url: "https://opendatacommons.org/licenses/odbl/",
publisher: site.name,
url: url_helpers.gobierto_data_datasets_url(host: site.domain, id: dataset.slug),
title: dataset.name,
description: description_custom_field_record(dataset),
issued: dataset.created_at,
modified: dataset.updated_at,
languages: [site_locale],
publisher: site.name,
publisher_mbox: site.reply_to_email,
distributions: build_distribution_for_catalog(dataset)
distributions: build_distribution_for_catalog(dataset)
}
end

def build_distribution_for_catalog(dataset)
[
{
format: 'application/csv',
download_url: url_helpers.download_gobierto_data_api_v1_dataset_url(dataset, host: site.domain)
format: 'application/csv',
download_url: url_helpers.download_gobierto_data_api_v1_dataset_url(slug: dataset.slug, host: site.domain)
}
]
end
Expand Down
5 changes: 1 addition & 4 deletions app/views/gobierto_data/api/v1/datasets/catalog.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
<dct:description><%= @catalog[:description] %></dct:description>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= @catalog[:issued] %></dct:issued>
<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= @catalog[:modified] %></dct:modified>
<%= @catalog[:languages].map { |locale| "<dct:language>#{locale}</dct:language>" }.join.html_safe %>
<dct:language><%= @catalog[:language] %></dct:language>
<foaf:homepage rdf:resource="<%= @catalog[:homepage] %>"/>
<dct:license rdf:resource="<%= @catalog[:license_url] %>"/>
<% @catalog[:datasets].each do |dataset| %><dcat:dataset>
<dcat:Dataset rdf:about="<%= dataset[:url]%>">
<dct:identifier><%= dataset[:url] %></dct:identifier>
<dct:title><%= dataset[:title] %></dct:title>
<dct:description><%= dataset[:description] %></dct:description>
<%= dataset[:keywords].map { |keyword| "<dct:keyword>#{locale}</dct:keyword>" }.join.html_safe %>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= dataset[:issued] %></dct:issued>
<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= dataset[:modified] %></dct:modified>
<%= dataset[:languages].map { |lang| "<dct:language>#{lang}</dct:language>" }.join.html_safe %>
Expand All @@ -40,7 +38,6 @@
<dct:description><%= dataset[:description] %></dct:description>
<dcat:downloadURL rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI"><%= distribution[:download_url] %></dcat:downloadURL>
<dcat:mediaType><%= distribution[:format] %></dcat:mediaType>
<dct:license rdf:resource="<%= dataset[:license_url] %>"/>
</dcat:Distribution>
</dcat:distribution>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions config/locales/gobierto_data/presenters/ca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
ca:
presenters:
gobierto_data:
catalog:
description: Catàleg public de dades dels conjunts de dades publicades per%
{site}, a través de la URL% {publisher_url}
title: Catàleg DCAT de conjunts de dades de %{site} en format rdf/xml dcat
8 changes: 8 additions & 0 deletions config/locales/gobierto_data/presenters/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
en:
presenters:
gobierto_data:
catalog:
description: Public catalog with datasets published by %{site}, through URL
%{publisher_url}
title: Catalog for datasets of %{site} into format rdf/xml dcat
9 changes: 9 additions & 0 deletions config/locales/gobierto_data/presenters/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
es:
presenters:
gobierto_data:
catalog:
description: Catalogo publico de datos los conjuntos de datos publicados por
%{site}, a través de la URL %{publisher_url}
title: Catalogo DCAT para los conjuntos de datos de %{site} en formato rdf/xml
dcat
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@
resources :favorites, only: [:index]
collection do
get :meta
# get :catalog
get "catalog" => "datasets#catalog"
end
member do
get "meta" => "datasets#dataset_meta"
Expand All @@ -664,7 +666,6 @@
resource :favorite, only: [:create, :destroy]
resources :favorites, only: [:index]
end
get "catalog" => "datasets#catalog"
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions test/presenters/gobierto_data/dataset_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ def test_structure_catalog_building_using_site_with_datasets
assert catalog.has_key? :description
assert catalog.has_key? :issued
assert catalog.has_key? :modified
assert catalog.has_key? :languages
assert catalog.has_key? :language
assert catalog.has_key? :homepage
assert catalog.has_key? :license_url
assert catalog.has_key? :datasets
catalog[:datasets].each do |dataset|
assert dataset.has_key? :url
assert dataset.has_key? :title
assert dataset.has_key? :description
assert dataset.has_key? :keywords
assert dataset.has_key? :issued
assert dataset.has_key? :modified
assert dataset.has_key? :languages
assert dataset.has_key? :license_url
assert dataset.has_key? :publisher
assert dataset.has_key? :publisher_mbox
assert dataset.has_key? :distributions
Expand Down

0 comments on commit 57d273c

Please sign in to comment.