-
Notifications
You must be signed in to change notification settings - Fork 30
WIP GobiertoData add dcat catalog endpoint #3846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stbnrivas
wants to merge
10
commits into
master
Choose a base branch
from
2671-add-gobierto-data-rdf-dcat-endpoint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4201cf
WIP ci skip
stbnrivas 4efaad6
mv catalog generation to presenter & test ci skip
stbnrivas 57d273c
fixes for review
stbnrivas 55d3919
add&fix test
stbnrivas 8e23033
Merge branch 'master' into 2671-add-gobierto-data-rdf-dcat-endpoint
stbnrivas 034e24f
add description & license & category into dcat
stbnrivas dd8abc9
hard refactor to gob.es dcat template
stbnrivas c3b7307
mv dcat config from custom_fields_records to site.config
stbnrivas dcd63d8
fix if existing config was nil
stbnrivas 7a689c0
Merge branch 'master' into 2671-add-gobierto-data-rdf-dcat-endpoint
stbnrivas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| module GobiertoData | ||
| class DatasetPresenter | ||
| include ActionView::Helpers::UrlHelper | ||
| include ActionView::Helpers::TranslationHelper | ||
|
|
||
| attr_reader :site | ||
|
|
||
| def initialize(site) | ||
| @site = site | ||
| end | ||
|
|
||
| def build_catalog | ||
| catalog = { | ||
| identifier_uri: url_helpers.gobierto_data_root_url(host: site.domain), | ||
| 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: site.updated_at, | ||
| language: site_locale, | ||
| homepage: url_helpers.gobierto_data_root_url(host: site.domain), | ||
| datasets: build_datasets_for_catalog | ||
| } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def build_datasets_for_catalog | ||
| site.datasets.visibles.map do |dataset| | ||
| build_dataset_for_catalog(dataset) | ||
| end | ||
| 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), | ||
| 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) | ||
| } | ||
| end | ||
|
|
||
| def build_distribution_for_catalog(dataset) | ||
| [ | ||
| { | ||
| format: 'application/csv', | ||
| download_url: url_helpers.download_gobierto_data_api_v1_dataset_url(slug: dataset.slug, host: site.domain) | ||
| } | ||
| ] | ||
| end | ||
|
|
||
| def url_helpers | ||
| Rails.application.routes.url_helpers | ||
| end | ||
|
|
||
| def site_locale | ||
| site.configuration.default_locale | ||
| end | ||
|
|
||
| def description_custom_field_record(dataset) | ||
| if dataset.custom_field_record_with_uid("description") | ||
| dataset.custom_field_record_with_uid("description").payload["description"][site_locale] | ||
| else | ||
| "" | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <rdf:RDF | ||
| xmlns:time="http://www.w3.org/2006/time#" | ||
| xmlns:dct="http://purl.org/dc/terms/" | ||
| xmlns:dcat="http://www.w3.org/ns/dcat#" | ||
| xmlns:foaf="http://xmlns.com/foaf/0.1/" | ||
| xmlns:xsd="http://www.w3.org/2001/XMLSchema#" | ||
| xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" | ||
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> | ||
| <dcat:Catalog rdf:about="https://data.some.org/catalog"> | ||
| <dct:identifier><%= @catalog[:identifier_uri] %></dct:identifier> | ||
| <dct:title><%= @catalog[:title] %></dct:title> | ||
| <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> | ||
| <dct:language><%= @catalog[:language] %></dct:language> | ||
| <foaf:homepage rdf:resource="<%= @catalog[:homepage] %>"/> | ||
| <% @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> | ||
| <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 %> | ||
| <dct:license rdf:resource="<%= dataset[:title] %>"/> | ||
| <dct:publisher> | ||
| <foaf:Organization> | ||
| <foaf:name><%= dataset[:publisher] %></foaf:name> | ||
| <foaf:mbox><%= dataset[:publisher_mbox] %></foaf:mbox> | ||
| </foaf:Organization> | ||
| </dct:publisher> | ||
| <% dataset[:distributions].each do |distribution| %> | ||
| <dcat:distribution> | ||
| <dcat:Distribution> | ||
| <dct:identifier><%= @identifier_uri %></dct:identifier> | ||
| <dct:title><%= dataset[:title] %></dct:title> | ||
| <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> | ||
| </dcat:Distribution> | ||
| </dcat:distribution> | ||
| <% end %> | ||
| </dcat:Dataset> | ||
| </dcat:dataset><% end %> | ||
ferblape marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </dcat:Catalog> | ||
| </rdf:RDF> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <rdf:RDF | ||
| xmlns:time="http://www.w3.org/2006/time#" | ||
| xmlns:dct="http://purl.org/dc/terms/" | ||
| xmlns:dcat="http://www.w3.org/ns/dcat#" | ||
| xmlns:foaf="http://xmlns.com/foaf/0.1/" | ||
| xmlns:xsd="http://www.w3.org/2001/XMLSchema#" | ||
| xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" | ||
| xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> | ||
| <dcat:Catalog rdf:about="https://data.some.org/catalog"> | ||
| <dct:identifier>http://madrid.gobierto.test/datos</dct:identifier> | ||
| <dct:title>Catalog for datasets of Ayuntamiento de Madrid into format rdf/xml dcat</dct:title> | ||
| <dct:description>Public catalog with datasets published by Ayuntamiento de Madrid, through URL http://madrid.gobierto.test/datos</dct:description> | ||
| <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-01-01 08:00:00 +0100</dct:issued> | ||
| <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2019-01-01 08:00:00 +0100</dct:modified> | ||
| <dct:language>en</dct:language> | ||
| <foaf:homepage rdf:resource="http://madrid.gobierto.test/datos"/> | ||
| <dcat:dataset> | ||
| <dcat:Dataset rdf:about="http://madrid.gobierto.test/datos/users-dataset"> | ||
| <dct:identifier>http://madrid.gobierto.test/datos/users-dataset</dct:identifier> | ||
| <dct:title>Users</dct:title> | ||
| <dct:description></dct:description> | ||
| <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-02 08:00:00 +0100</dct:issued> | ||
| <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-02 08:00:00 +0100</dct:modified> | ||
| <dct:language>en</dct:language> | ||
| <dct:license rdf:resource="Users"/> | ||
| <dct:publisher> | ||
| <foaf:Organization> | ||
| <foaf:name>Ayuntamiento de Madrid</foaf:name> | ||
| <foaf:mbox>contact@madrid.es</foaf:mbox> | ||
| </foaf:Organization> | ||
| </dct:publisher> | ||
| <dcat:distribution> | ||
| <dcat:Distribution> | ||
| <dct:identifier></dct:identifier> | ||
| <dct:title>Users</dct:title> | ||
| <dct:description></dct:description> | ||
| <dcat:downloadURL rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://madrid.gobierto.test/api/v1/data/datasets/users-dataset/download.csv</dcat:downloadURL> | ||
| <dcat:mediaType>application/csv</dcat:mediaType> | ||
| </dcat:Distribution> | ||
| </dcat:distribution> | ||
| </dcat:Dataset> | ||
| </dcat:dataset><dcat:dataset> | ||
| <dcat:Dataset rdf:about="http://madrid.gobierto.test/datos/events-dataset"> | ||
| <dct:identifier>http://madrid.gobierto.test/datos/events-dataset</dct:identifier> | ||
| <dct:title>Events</dct:title> | ||
| <dct:description></dct:description> | ||
| <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-03 08:00:00 +0100</dct:issued> | ||
| <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-03 08:00:00 +0100</dct:modified> | ||
| <dct:language>en</dct:language> | ||
| <dct:license rdf:resource="Events"/> | ||
| <dct:publisher> | ||
| <foaf:Organization> | ||
| <foaf:name>Ayuntamiento de Madrid</foaf:name> | ||
| <foaf:mbox>contact@madrid.es</foaf:mbox> | ||
| </foaf:Organization> | ||
| </dct:publisher> | ||
| <dcat:distribution> | ||
| <dcat:Distribution> | ||
| <dct:identifier></dct:identifier> | ||
| <dct:title>Events</dct:title> | ||
| <dct:description></dct:description> | ||
| <dcat:downloadURL rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://madrid.gobierto.test/api/v1/data/datasets/events-dataset/download.csv</dcat:downloadURL> | ||
| <dcat:mediaType>application/csv</dcat:mediaType> | ||
| </dcat:Distribution> | ||
| </dcat:distribution> | ||
| </dcat:Dataset> | ||
| </dcat:dataset><dcat:dataset> | ||
| <dcat:Dataset rdf:about="http://madrid.gobierto.test/datos/no-size"> | ||
| <dct:identifier>http://madrid.gobierto.test/datos/no-size</dct:identifier> | ||
| <dct:title>No size</dct:title> | ||
| <dct:description></dct:description> | ||
| <dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-06 08:00:00 +0100</dct:issued> | ||
| <dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2020-01-06 08:00:00 +0100</dct:modified> | ||
| <dct:language>en</dct:language> | ||
| <dct:license rdf:resource="No size"/> | ||
| <dct:publisher> | ||
| <foaf:Organization> | ||
| <foaf:name>Ayuntamiento de Madrid</foaf:name> | ||
| <foaf:mbox>contact@madrid.es</foaf:mbox> | ||
| </foaf:Organization> | ||
| </dct:publisher> | ||
| <dcat:distribution> | ||
| <dcat:Distribution> | ||
| <dct:identifier></dct:identifier> | ||
| <dct:title>No size</dct:title> | ||
| <dct:description></dct:description> | ||
| <dcat:downloadURL rdf:datatype="http://www.w3.org/2001/XMLSchema#anyURI">http://madrid.gobierto.test/api/v1/data/datasets/no-size/download.csv</dcat:downloadURL> | ||
| <dcat:mediaType>application/csv</dcat:mediaType> | ||
| </dcat:Distribution> | ||
| </dcat:distribution> | ||
| </dcat:Dataset> | ||
| </dcat:dataset> | ||
| </dcat:Catalog> | ||
| </rdf:RDF> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.