publish_my_data 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -3
- data/app/controllers/publish_my_data/application_controller.rb +21 -32
- data/app/controllers/publish_my_data/datasets_controller.rb +7 -19
- data/app/controllers/publish_my_data/resources_controller.rb +18 -24
- data/app/controllers/publish_my_data/sparql_controller.rb +6 -3
- data/app/controllers/publish_my_data/themes_controller.rb +28 -0
- data/app/helpers/publish_my_data/resources_helper.rb +2 -2
- data/app/models/publish_my_data/concept.rb +14 -0
- data/app/models/publish_my_data/concept_scheme.rb +16 -0
- data/app/models/publish_my_data/dataset.rb +48 -13
- data/app/models/publish_my_data/ontology.rb +35 -0
- data/app/models/publish_my_data/ontology_class.rb +11 -0
- data/app/models/publish_my_data/property.rb +11 -0
- data/app/models/publish_my_data/rdf_type.rb +1 -0
- data/app/models/publish_my_data/resource.rb +80 -6
- data/app/models/publish_my_data/theme.rb +34 -0
- data/app/views/layouts/publish_my_data/application.html.erb +0 -1
- data/app/views/layouts/publish_my_data/error.html.erb +12 -2
- data/app/views/publish_my_data/concept_schemes/_concepts.html.erb +3 -0
- data/app/views/publish_my_data/concept_schemes/show.html.erb +9 -0
- data/app/views/publish_my_data/concepts/show.html.erb +3 -0
- data/app/views/publish_my_data/datasets/index.html.erb +4 -4
- data/app/views/publish_my_data/datasets/show.html.erb +1 -1
- data/app/views/publish_my_data/errors/bad_request.html.erb +1 -0
- data/app/views/publish_my_data/errors/not_found.html.erb +1 -1
- data/app/views/publish_my_data/errors/timeout.html.erb +1 -0
- data/app/views/publish_my_data/errors/uncaught.html.erb +6 -0
- data/app/views/publish_my_data/ontologies/_classes.html.erb +3 -0
- data/app/views/publish_my_data/ontologies/_properties.html.erb +3 -0
- data/app/views/publish_my_data/ontologies/show.html.erb +17 -0
- data/app/views/publish_my_data/properties/show.html.erb +3 -0
- data/app/views/publish_my_data/resources/_predicates_table.html.erb +12 -4
- data/app/views/publish_my_data/resources/_resource_formats.html.erb +5 -5
- data/app/views/publish_my_data/resources/_uri_and_label.html.erb +2 -2
- data/app/views/publish_my_data/resources/index.html.erb +4 -4
- data/app/views/publish_my_data/resources/show.html.erb +3 -3
- data/app/views/publish_my_data/sparql/_pagination.html.erb +2 -2
- data/app/views/publish_my_data/themes/index.html.erb +12 -0
- data/app/views/publish_my_data/themes/show.html.erb +15 -0
- data/config/initializers/{tripod.rb → 00_tripod.rb} +0 -0
- data/config/initializers/10_vocabularies.rb +6 -0
- data/config/initializers/zz_factories.rb +7 -0
- data/config/routes.rb +4 -5
- data/lib/publish_my_data/defined_by_ontology.rb +10 -0
- data/lib/publish_my_data/paginator.rb +63 -0
- data/lib/publish_my_data/render_params/concept_render_params.rb +14 -0
- data/lib/publish_my_data/render_params/concept_scheme_render_params.rb +14 -0
- data/lib/publish_my_data/render_params/ontology_class_render_params.rb +14 -0
- data/lib/publish_my_data/render_params/ontology_render_params.rb +14 -0
- data/lib/publish_my_data/render_params/property_render_params.rb +14 -0
- data/lib/publish_my_data/render_params/resource_render_params.rb +13 -0
- data/lib/publish_my_data/render_params/theme_render_params.rb +23 -0
- data/lib/publish_my_data/render_params.rb +7 -0
- data/lib/publish_my_data/resource_module.rb +8 -0
- data/lib/publish_my_data/version.rb +1 -1
- data/lib/publish_my_data.rb +6 -1
- data/spec/controllers/publish_my_data/datasets_controller_spec.rb +0 -10
- data/spec/controllers/publish_my_data/resources_controller_spec.rb +78 -38
- data/spec/controllers/publish_my_data/sparql_controller_spec.rb +4 -4
- data/spec/controllers/publish_my_data/themes_controller_spec.rb +110 -0
- data/spec/dummy/log/test.log +80255 -0
- data/spec/factories/00_theme_factories.rb +11 -0
- data/spec/factories/concept_scheme_factories.rb +48 -0
- data/spec/factories/dataset_factories.rb +10 -1
- data/spec/factories/ontology_factories.rb +55 -0
- data/spec/factories/property_factories.rb +2 -2
- data/spec/factories/resource_factories.rb +5 -5
- metadata +61 -16
- data/app/assets/javascripts/publish_my_data/resources.js +0 -2
- data/app/assets/stylesheets/publish_my_data/resources.css +0 -4
- data/app/views/publish_my_data/datasets/themes.html.erb +0 -3
- data/config/initializers/vocabularies.rb +0 -1
@@ -0,0 +1,63 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
|
3
|
+
class PaginationParams
|
4
|
+
|
5
|
+
DEFAULT_PAGE_SIZE = 20
|
6
|
+
MAX_PAGE_SIZE = 10000
|
7
|
+
|
8
|
+
attr_accessor :page
|
9
|
+
attr_accessor :per_page
|
10
|
+
attr_accessor :offset
|
11
|
+
attr_accessor :format
|
12
|
+
|
13
|
+
# example opts:
|
14
|
+
# {:per_page => 10, :page => 2, :format => :html}
|
15
|
+
def initialize(opts={})
|
16
|
+
self.per_page = (opts[:per_page] || PaginationParams::DEFAULT_PAGE_SIZE).to_i
|
17
|
+
self.per_page = PaginationParams::MAX_PAGE_SIZE if self.per_page > PaginationParams::MAX_PAGE_SIZE
|
18
|
+
self.page = (opts[:page] || 1).to_i
|
19
|
+
self.offset = self.per_page.to_i * (self.page.to_i-1)
|
20
|
+
self.format = opts[:format]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.from_request(request)
|
24
|
+
PaginationParams.new(per_page: request.params[:per_page], page: request.params[:page], format: request.format.to_sym)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ==(other)
|
28
|
+
other.page == self.page &&
|
29
|
+
other.per_page == self.per_page &&
|
30
|
+
other.format == self.format
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
class Paginator
|
36
|
+
|
37
|
+
attr_accessor :pagination_params
|
38
|
+
attr_accessor :criteria
|
39
|
+
|
40
|
+
def initialize(criteria, pagination_params)
|
41
|
+
self.criteria = criteria
|
42
|
+
self.pagination_params = pagination_params
|
43
|
+
end
|
44
|
+
|
45
|
+
# returns a Kaminari paginatable array, or a plain old array
|
46
|
+
def paginate
|
47
|
+
count = criteria.count #this has to happen first, before we modify the criteria with limit/offset
|
48
|
+
resources = criteria.limit(self.pagination_params.per_page).offset(self.pagination_params.offset).resources
|
49
|
+
|
50
|
+
if self.pagination_params.format == :html
|
51
|
+
Kaminari.paginate_array(resources.to_a, total_count: count).page(self.pagination_params.page).per(self.pagination_params.per_page)
|
52
|
+
else
|
53
|
+
resources # non html versions just need the raw array
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def ==(other)
|
58
|
+
self.pagination_params == other.pagination_params &&
|
59
|
+
self.criteria == other.criteria
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class ConceptRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@concept = resource.as_concept
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
{template: 'publish_my_data/concepts/show', locals: {concept: @concept}}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class ConceptSchemeRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@concept_scheme = resource.as_concept_scheme
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
{template: 'publish_my_data/concept_schemes/show', locals: {concept_scheme: @concept_scheme}}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class OntologyClassRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@ontology_class = resource.as_ontology_class
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
{template: 'publish_my_data/classes/show', locals: {ontology_class: @ontology_class}}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class OntologyRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@ontology = resource.as_ontology
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
{template: 'publish_my_data/ontologies/show', locals: {ontology: @ontology}}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class PropertyRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@property = resource.as_property
|
7
|
+
end
|
8
|
+
|
9
|
+
def render_params(opts={})
|
10
|
+
{template: 'publish_my_data/properties/show', locals: {property: @property}}
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PublishMyData
|
2
|
+
class ThemeRenderParams
|
3
|
+
|
4
|
+
def initialize(resource)
|
5
|
+
@resource = resource
|
6
|
+
@theme = resource.as_theme
|
7
|
+
end
|
8
|
+
|
9
|
+
# e.g. opts[:pagination_params] => PaginationParams.new
|
10
|
+
def render_params(opts)
|
11
|
+
datasets = Paginator.new(@theme.datasets_criteria, opts[:pagination_params]).paginate
|
12
|
+
{
|
13
|
+
template: 'publish_my_data/themes/show',
|
14
|
+
locals: {
|
15
|
+
theme: @theme,
|
16
|
+
datasets: datasets,
|
17
|
+
pagination_params: opts[:pagination_params]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require "publish_my_data/render_params/resource_render_params"
|
2
|
+
require "publish_my_data/render_params/ontology_render_params"
|
3
|
+
require "publish_my_data/render_params/theme_render_params"
|
4
|
+
require "publish_my_data/render_params/property_render_params"
|
5
|
+
require "publish_my_data/render_params/ontology_class_render_params"
|
6
|
+
require "publish_my_data/render_params/concept_scheme_render_params"
|
7
|
+
require "publish_my_data/render_params/concept_render_params"
|
data/lib/publish_my_data.rb
CHANGED
@@ -2,9 +2,13 @@ require "publish_my_data/engine"
|
|
2
2
|
require "publish_my_data/renderers"
|
3
3
|
require "publish_my_data/sparql_query"
|
4
4
|
require "publish_my_data/sparql_query_result"
|
5
|
+
require "publish_my_data/resource_module"
|
6
|
+
require "publish_my_data/defined_by_ontology"
|
7
|
+
require "publish_my_data/paginator"
|
8
|
+
require "publish_my_data/render_params"
|
5
9
|
|
6
|
-
module PublishMyData
|
7
10
|
|
11
|
+
module PublishMyData
|
8
12
|
|
9
13
|
# The local domain of the website. Used to decide if resources andexdsf
|
10
14
|
# datasets are local or not
|
@@ -37,6 +41,7 @@ module PublishMyData
|
|
37
41
|
end
|
38
42
|
|
39
43
|
require 'kaminari'
|
44
|
+
require 'rdiscount'
|
40
45
|
|
41
46
|
Kaminari.configure do |config|
|
42
47
|
config.default_per_page = 20
|
@@ -87,7 +87,6 @@ module PublishMyData
|
|
87
87
|
graph = Dataset.metadata_graph_uri(slug)
|
88
88
|
d = PublishMyData::Dataset.new(uri, graph)
|
89
89
|
d.title = "Dataset #{i.to_s}"
|
90
|
-
d.theme = (i.even? ? 'theme' : 'othertheme')
|
91
90
|
d.save!
|
92
91
|
end
|
93
92
|
end
|
@@ -175,15 +174,6 @@ module PublishMyData
|
|
175
174
|
end
|
176
175
|
end
|
177
176
|
|
178
|
-
context "with a theme parameter" do
|
179
|
-
let(:theme) {'theme'}
|
180
|
-
|
181
|
-
it "should filter the results to only datasets in the theme" do
|
182
|
-
get :index, theme: theme, use_route: :publish_my_data
|
183
|
-
assigns['datasets'].length.should == 15 # only the even ones are in this theme
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
177
|
end
|
188
178
|
|
189
179
|
end
|
@@ -15,6 +15,7 @@ module PublishMyData
|
|
15
15
|
response.status.should eq(303)
|
16
16
|
response.should redirect_to "/doc/this/is/my/path"
|
17
17
|
end
|
18
|
+
|
18
19
|
end
|
19
20
|
|
20
21
|
context "with an alternative mime type passed in the header" do
|
@@ -29,32 +30,31 @@ module PublishMyData
|
|
29
30
|
response.content_type.should == Mime::RDF
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#doc" do
|
36
36
|
|
37
|
-
|
38
|
-
@resource = FactoryGirl.create(:yuri_unicorn_resource)
|
39
|
-
end
|
37
|
+
let!(:resource) { FactoryGirl.create(:yuri_unicorn_resource) }
|
40
38
|
|
41
39
|
it "should respond successfully" do
|
42
40
|
get :doc, :path => "unicorns/yuri", use_route: :publish_my_data
|
43
41
|
response.should be_success
|
44
42
|
end
|
45
43
|
|
46
|
-
it "should render the show template" do
|
47
|
-
get :doc, :path => "unicorns/yuri", use_route: :publish_my_data
|
48
|
-
response.should render_template("publish_my_data/resources/show")
|
49
|
-
end
|
50
|
-
|
51
44
|
context "for html" do
|
52
45
|
it "should eager load the labels" do
|
53
|
-
Resource.should_receive(:find).and_return(
|
54
|
-
|
55
|
-
|
46
|
+
Resource.should_receive(:find).and_return(resource)
|
47
|
+
resource.should_receive(:eager_load_predicate_triples!)
|
48
|
+
resource.should_receive(:eager_load_object_triples!)
|
56
49
|
get :doc, :path => "unicorns/yuri", use_route: :publish_my_data
|
57
50
|
end
|
51
|
+
|
52
|
+
context "with an arbitrary resource" do
|
53
|
+
it "should render the show template" do
|
54
|
+
get :doc, :path => "unicorns/yuri", use_route: :publish_my_data
|
55
|
+
response.should render_template("publish_my_data/resources/show")
|
56
|
+
end
|
57
|
+
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context "with an alternative mime type passed in the header" do
|
@@ -69,13 +69,13 @@ module PublishMyData
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should respond with the right content" do
|
72
|
-
response.body.should ==
|
72
|
+
response.body.should == resource.to_rdf
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should not eager load the labels" do
|
76
|
-
Resource.should_receive(:find).and_return(
|
77
|
-
|
78
|
-
|
76
|
+
Resource.should_receive(:find).and_return(resource)
|
77
|
+
resource.should_not_receive(:eager_load_predicate_triples!)
|
78
|
+
resource.should_not_receive(:eager_load_object_triples!)
|
79
79
|
get :doc, :path => "unicorns/yuri", use_route: :publish_my_data
|
80
80
|
end
|
81
81
|
|
@@ -98,7 +98,7 @@ module PublishMyData
|
|
98
98
|
|
99
99
|
it "should respond with the right content" do
|
100
100
|
get :doc, :path => "unicorns/yuri", format: 'ttl', use_route: :publish_my_data
|
101
|
-
response.body.should ==
|
101
|
+
response.body.should == resource.to_ttl
|
102
102
|
end
|
103
103
|
|
104
104
|
end
|
@@ -114,13 +114,26 @@ module PublishMyData
|
|
114
114
|
end
|
115
115
|
|
116
116
|
end
|
117
|
-
|
118
117
|
end
|
119
118
|
|
120
119
|
describe "#definition" do
|
121
120
|
|
121
|
+
let!(:resource) { FactoryGirl.create(:mean_result) }
|
122
|
+
let!(:theme) { FactoryGirl.create(:my_theme) }
|
123
|
+
let!(:onotology) { FactoryGirl.create(:ontology) }
|
124
|
+
let!(:concept_scheme) { FactoryGirl.create(:concept_scheme) }
|
125
|
+
|
122
126
|
before do
|
123
|
-
|
127
|
+
# make some datasets
|
128
|
+
(1..30).each do |i|
|
129
|
+
slug = i
|
130
|
+
uri = PublishMyData::Dataset.uri_from_slug(slug)
|
131
|
+
graph = PublishMyData::Dataset.metadata_graph_uri(slug)
|
132
|
+
d = PublishMyData::Dataset.new(uri, graph)
|
133
|
+
d.theme = theme.uri if i.even?
|
134
|
+
d.title = "Dataset #{i.to_s}"
|
135
|
+
d.save!
|
136
|
+
end
|
124
137
|
end
|
125
138
|
|
126
139
|
context "for resource in our database" do
|
@@ -130,19 +143,39 @@ module PublishMyData
|
|
130
143
|
response.should be_success
|
131
144
|
end
|
132
145
|
|
133
|
-
|
134
|
-
|
135
|
-
|
146
|
+
context "for an html request" do
|
147
|
+
|
148
|
+
context "for an abitrary resource" do
|
149
|
+
it "should render the show template" do
|
150
|
+
get :definition, :path => "statistics/meanResult", use_route: :publish_my_data
|
151
|
+
response.should render_template("publish_my_data/resources/show")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when resource is an ontology" do
|
156
|
+
it "should render the ontologies#show template" do
|
157
|
+
get :definition, :path => "my-topic/ontology", use_route: :publish_my_data
|
158
|
+
response.should render_template("publish_my_data/ontologies/show")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when resource is a concept scheme" do
|
163
|
+
it "should render the concept_schemes#show template" do
|
164
|
+
get :definition, :path => "my-topic/concept-scheme/my-concept-scheme", use_route: :publish_my_data
|
165
|
+
response.should render_template("publish_my_data/concept_schemes/show")
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
136
169
|
end
|
137
170
|
|
171
|
+
|
138
172
|
context "with an alternative mime type" do
|
139
173
|
it "should with the right mime type and content" do
|
140
174
|
get :definition, :path => "statistics/meanResult", :format => 'nt', use_route: :publish_my_data
|
141
175
|
response.content_type.should == Mime::NT
|
142
|
-
response.body.should ==
|
176
|
+
response.body.should == resource.to_nt
|
143
177
|
end
|
144
178
|
end
|
145
|
-
|
146
179
|
end
|
147
180
|
|
148
181
|
context "when resource doesn't exist" do
|
@@ -151,7 +184,6 @@ module PublishMyData
|
|
151
184
|
response.should be_not_found
|
152
185
|
end
|
153
186
|
end
|
154
|
-
|
155
187
|
end
|
156
188
|
|
157
189
|
describe "#show" do
|
@@ -188,30 +220,40 @@ module PublishMyData
|
|
188
220
|
|
189
221
|
context "with a resource in our database" do
|
190
222
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
r = Resource.new(uri, graph)
|
195
|
-
r.write_predicate('http://foo', 'blah')
|
196
|
-
r.save!
|
197
|
-
|
198
|
-
get :show, :uri => r.uri, use_route: :publish_my_data
|
199
|
-
end
|
223
|
+
let!(:resource) { FactoryGirl.create(:foreign_resource) }
|
224
|
+
let!(:external_concept_scheme) { FactoryGirl.create(:external_concept_scheme) }
|
225
|
+
let!(:external_ontology) { FactoryGirl.create(:external_ontology) }
|
200
226
|
|
201
227
|
it "should respond succesfully" do
|
228
|
+
get :show, :uri => resource.uri, use_route: :publish_my_data
|
202
229
|
response.should be_success
|
203
230
|
end
|
204
231
|
|
205
232
|
it "should render the show template" do
|
233
|
+
get :show, :uri => resource.uri, use_route: :publish_my_data
|
206
234
|
response.should render_template("publish_my_data/resources/show")
|
207
235
|
end
|
208
236
|
|
237
|
+
context "when resource is an ontology" do
|
238
|
+
it "should render the ontologies#show template" do
|
239
|
+
get :show, :uri => external_ontology.uri, use_route: :publish_my_data
|
240
|
+
response.should render_template("publish_my_data/ontologies/show")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when resource is a concept scheme" do
|
245
|
+
it "should render the concept_schemes#show template" do
|
246
|
+
get :show, :uri => external_concept_scheme.uri, use_route: :publish_my_data
|
247
|
+
response.should render_template("publish_my_data/concept_schemes/show")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
209
251
|
end
|
210
252
|
end
|
211
253
|
|
212
254
|
describe "#index" do
|
213
255
|
|
214
|
-
|
256
|
+
shared_examples_for "resource kaminari pagination" do
|
215
257
|
it "should call kaminari to paginate the results" do
|
216
258
|
res_array = Resource.all.limit(per_page).offset(offset).resources.to_a
|
217
259
|
count = Resource.count
|
@@ -287,7 +329,7 @@ module PublishMyData
|
|
287
329
|
end
|
288
330
|
|
289
331
|
it "should return paginated results for Resource.all" do
|
290
|
-
|
332
|
+
Paginator.should_receive(:new).with(Resource.all, PaginationParams.from_request(@request)).and_call_original
|
291
333
|
get :index, use_route: :publish_my_data
|
292
334
|
assigns['resources'].length.should == 10 # 8 resources, plus ds and type!
|
293
335
|
end
|
@@ -393,7 +435,5 @@ module PublishMyData
|
|
393
435
|
end
|
394
436
|
end
|
395
437
|
|
396
|
-
|
397
|
-
|
398
438
|
end
|
399
439
|
end
|