Skip to content

Commit

Permalink
WIP ci skip
Browse files Browse the repository at this point in the history
  • Loading branch information
stbnrivas committed Apr 27, 2021
1 parent a5c8e02 commit 6d824d1
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/controllers/gobierto_data/api/v1/datasets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ class DatasetsController < BaseController
skip_before_action :authenticate_in_site, only: [:new, :create, :update, :destroy]
skip_before_action :set_admin_with_token, except: [:new, :create, :update, :destroy]

def catalog
# TODO TRANSLATIONS...
@catalog_identifier_uri = gobierto_data_root_url
@catalog_title = "dcat catalog for #{current_site}"
@catalog_description = "this is catalog published by #{@catalog_identifier_uri} which contains datasets"
@catalog_issued = current_site.created_at
@catalog_modified = GobiertoData::Dataset.where(site_id: current_site.id).maximum(:created_at) || current_site.created_at
@catalog_languages = current_site.configuration.available_locales
@catalog_homepage = gobierto_data_root_url
@catalog_license_url = "https://opendatacommons.org/licenses/odbl/" # REVIEW

@catalog_datasets = []
GobiertoData::Dataset.where(site_id: current_site.id).each do |dataset|
@catalog_datasets << {
dataset_url: gobierto_data_datasets_url(id: dataset.slug),
dataset_title: dataset.name,
dataset_description: GobiertoCommon::CustomFieldRecord.for_item(dataset).select { |record| record.payload.has_key? "description" }.first["payload"]["description"][preferred_locale],
dataset_keywords: [],
dataset_issued: dataset.created_at,
dataset_modified: dataset.updated_at,
dataset_languages: [preferred_locale],
dataset_license_url: "https://opendatacommons.org/licenses/odbl/", # FIX license belongs to datase
dataset_publisher: current_site.name,
dataset_publisher_mbox: current_site.reply_to_email,
dataset_distribution: [ {
format: 'application/csv',
download_url: download_gobierto_data_api_v1_dataset_url(dataset) # FIX link don't work directly
} ]
}
end

respond_to do |format|
format.xml
end
end


# GET /api/v1/data/datasets
# GET /api/v1/data/datasets.json
# GET /api/v1/data/datasets.csv
Expand Down
50 changes: 50 additions & 0 deletions app/views/gobierto_data/api/v1/datasets/catalog.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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><%= @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>
<%= @catalog_languages.map { |locale| "<dct:language>#{locale}</dct:language>" }.join.html_safe %>
<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[:dataset_url]%>">
<dct:identifier><%= dataset[:dataset_url] %></dct:identifier>
<dct:title><%= dataset[:dataset_title] %></dct:title>
<dct:description><%= dataset[:dataset_description] %></dct:description>
<%= dataset[:dataset_keywords].map { |keyword| "<dct:keyword>#{locale}</dct:keyword>" }.join.html_safe %>
<dct:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= dataset[:dataset_issued] %></dct:issued>
<dct:modified rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime"><%= dataset[:dataset_modified] %></dct:modified>
<%= dataset[:dataset_languages].map { |lang| "<dct:language>#{lang}</dct:language>" }.join.html_safe %>
<dct:license rdf:resource="<%= dataset[:dataset_title] %>"/>
<dct:publisher>
<foaf:Organization>
<foaf:name><%= dataset[:dataset_publisher] %></foaf:name>
<foaf:mbox><%= dataset[:dataset_publisher_mbox] %></foaf:mbox>
</foaf:Organization>
</dct:publisher>
<% dataset[:dataset_distribution].each do |distribution| %>
<dcat:distribution>
<dcat:Distribution>
<dct:identifier><%= @identifier_uri %></dct:identifier>
<dct:title><%= dataset[:dataset_title] %> in CSV format</dct:title>
<dct:description><%= dataset[: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[:dataset_title] %>"/>
</dcat:Distribution>
</dcat:distribution>
<% end %>
</dcat:Dataset>
</dcat:dataset><% end %>
</dcat:Catalog>
</rdf:RDF>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@
resource :favorite, only: [:create, :destroy]
resources :favorites, only: [:index]
end
get "catalog" => "datasets#catalog"
end
end
end
Expand Down

0 comments on commit 6d824d1

Please sign in to comment.