Skip to content

Commit

Permalink
Mark assumed public domain certified datasets
Browse files Browse the repository at this point in the history
In the case where we assume based on US public
domain law that the international license is
equivalent to CC0, mark that this assumption has
been made on the `KittenData` model

So we can for example display this on the
certificate page
  • Loading branch information
pkqk committed Oct 2, 2015
1 parent 8b92e79 commit fc4f461
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/models/certificate_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def generate(jurisdiction, create_user, dataset = nil)
.includes(:answers)
.each {|question| answer question}

response_set.autocomplete(autocomplete_url)
response_set.autocomplete(autocomplete_url, true)

user = determine_user(response_set, create_user)
response_set.assign_to_user!(user)
Expand Down
51 changes: 39 additions & 12 deletions app/models/kitten_data.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class KittenData < ActiveRecord::Base
belongs_to :response_set, inverse_of: :kitten_data

attr_accessible :data, :url, :response_set
attr_accessor :automatic
attr_accessible :data, :url, :response_set, :automatic

serialize :data

Expand Down Expand Up @@ -39,6 +40,10 @@ def source
@dataset.try(:source) || {}
end

def assumed_us_public_domain?
data[:assumptions].include?(:us_public_domain)
end

def distributions
dataset_field(:distributions, []).map { |distribution|
{
Expand All @@ -62,7 +67,7 @@ def fields
end

def compute_fields
return {} if data.blank?
return {} unless dataset.present?

begin
@fields = {}
Expand Down Expand Up @@ -255,14 +260,29 @@ def set_data_gov_assumptions
end

def data_gov_federal_assumptions
@fields["dataLicence"] = "other"
@fields["contentLicence"] = "other"
@fields["otherDataLicenceName"] = "U.S. Government Work"
@fields["otherDataLicenceURL"] = "http://www.usa.gov/publicdomain/label/1.0/"
@fields["otherDataLicenceOpen"] = "true"
@fields["otherContentLicenceName"] = "U.S. Government Work"
@fields["otherContentLicenceURL"] = "http://www.usa.gov/publicdomain/label/1.0/"
@fields["otherContentLicenceOpen"] = "true"
# usGovData: if the data was created by a federal agency then it is
# automatically in the public domain according to US copyright law

# internationalDataLicence: we assume internationally that cc-zero is
# appropriate as the license as that is in the spirit of the US Open Data
# policy
# https://www.whitehouse.gov/sites/default/files/omb/memoranda/2013/m-13-13.pdf
# we assume public domain if the license is not specified or set to one of
# the two public domain fields that catalog.data.gov uses (us-pd or
# other-pd).

@fields["usGovData"] = "true"

licenses = data[:licenses]
is_public_domain = licenses.any? do |license|
%w[notspecified us-pd other-pd cc-zero].include?(license.id)
end

if automatic? && (licenses.empty? || is_public_domain)
@fields['internationalDataLicence'] = 'cc_zero'
@fields['internationalContentRights'] = 'samerights'
data[:assumptions] << :us_public_domain
end
end

def set_structured_open
Expand Down Expand Up @@ -368,6 +388,10 @@ def set_schema
end

private
def automatic?
!!@automatic
end

def dataset_field(method, default = nil)
@dataset.try(method) || default
end
Expand All @@ -394,10 +418,13 @@ def request_data
:temporal_coverage => dataset_field(:temporal),
:spatial_coverage => dataset_field(:spatial),
:language => dataset_field(:language),
:distributions => distributions
:distributions => distributions,
:assumptions => []
}
else
self.data = {}
self.data = {
:assumptions => []
}
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/response_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,14 @@ def response_for(question_id)
assoc.first || assoc.build
end

def autocomplete(url)
def autocomplete(url, automatic=false)
return unless url.present?
update_responses({documentationUrl: url})
responses.update_all(autocompleted: false)
update_attribute('kitten_data', nil)

if ODIBot.new(url).valid?
create_kitten_data(url: url)
create_kitten_data(url: url, automatic: automatic)
update_responses(kitten_data.fields)
end
end
Expand Down
68 changes: 45 additions & 23 deletions test/unit/kitten_data_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def set_minimum_data
end
end

def set_us_data(organization_type = "Federal Government")
source = {
"organization" => {"id" => "gov-agency"}
}
organization = {
"extras" => {"organization_type" => organization_type}
}

DataKitten::Dataset.any_instance.stubs(:source).returns(source)
stub_request(:get, 'http://catalog.data.gov/some_data').to_return(status: 200)
stub_request(:get, 'http://catalog.data.gov/api/2/rest/group/gov-agency').to_return(body: organization.to_json)
end

def setup
stub_request(:get, "http://www.example.com").to_return(status: 200)
set_normal_data
Expand Down Expand Up @@ -425,36 +438,45 @@ def kitten_data
assert_equal "http://www.data.gov/issue/?media_url=http://catalog.data.gov/some_data", kitten_data.fields["improvementsContact"]
end

test 'data.gov assumptions are set for federal organizations' do
source = {
"organization" => { "id" => "federal" }
}
organization = {
"extras" => { "organization_type" => "Federal Government" }
}

DataKitten::Dataset.any_instance.stubs(:source).returns(source)
stub_request(:get, 'http://catalog.data.gov/some_data').to_return(status: 200)
stub_request(:get, 'http://catalog.data.gov/api/2/rest/group/federal').to_return(body: organization.to_json)
test 'data.gov assumptions are set for federal organizations with no license information when automatic' do
set_us_data
DataKitten::Dataset.any_instance.stubs(:licenses).returns([])
@kitten_data = KittenData.new(url: 'http://catalog.data.gov/some_data', automatic: true)

assert_equal "true", kitten_data.fields["usGovData"]
assert_equal "cc_zero", kitten_data.fields["internationalDataLicence"]
assert kitten_data.assumed_us_public_domain?
end

test 'data.gov only gov data assumption is set for federal organizations with no license information when not automatic' do
set_us_data
license = DataKitten::License.new(id: 'us-pd')
DataKitten::Dataset.any_instance.stubs(:licenses).returns([license])
@kitten_data = KittenData.new(url: 'http://catalog.data.gov/some_data')

assert_equal "http://www.usa.gov/publicdomain/label/1.0/", kitten_data.fields["otherDataLicenceURL"]
assert_equal "true", kitten_data.fields["usGovData"]
assert_nil kitten_data.fields["internationalDataLicence"]
refute kitten_data.assumed_us_public_domain?
end

%w[us-pd other-pd notspecified].each do |license_id|
test "data.gov assumptions are set for federal organizations with #{license_id} license" do
set_us_data
license = DataKitten::License.new(id: license_id)
DataKitten::Dataset.any_instance.stubs(:licenses).returns([license])
@kitten_data = KittenData.new(url: 'http://catalog.data.gov/some_data', automatic: true)

assert_equal "true", kitten_data.fields["usGovData"]
assert_equal "cc_zero", kitten_data.fields["internationalDataLicence"]
assert kitten_data.assumed_us_public_domain?
end
end

test 'data.gov assumptions are not set for non-federal organizations' do
source = {
"organization" => { "id" => "federal" }
}
organization = {
"extras" => { "organization_type" => "City Government" }
}

DataKitten::Dataset.any_instance.stubs(:source).returns(source)
stub_request(:get, 'http://catalog.data.gov/some_data').to_return(status: 200)
stub_request(:get, 'http://catalog.data.gov/api/2/rest/group/federal').to_return(body: organization.to_json)
set_us_data("City Government")
@kitten_data = KittenData.new(url: 'http://catalog.data.gov/some_data')

assert_nil kitten_data.fields["otherDataLicenceURL"]
assert_nil kitten_data.fields["internationalDataLicence"]
end

test 'Distribution metadata is set correctly' do
Expand Down

0 comments on commit fc4f461

Please sign in to comment.