easy_data 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.idea/EasyData.iml +11 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +11 -0
- data/.idea/modules.xml +9 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +2 -0
- data/Rakefile +8 -0
- data/easy_data.gemspec +1 -2
- data/lib/controllers/easy_datas_controller.rb +86 -47
- data/lib/data_models/RDFa.rb +22 -13
- data/lib/data_models/data_models.rb +21 -4
- data/lib/data_models/model_rdf.rb +152 -28
- data/lib/data_models/namespaces.rb +6 -6
- data/lib/easy_data/templates/easy_datas/_data_publications.html.erb +8 -12
- data/lib/easy_data/templates/easy_datas/_footer.html.erb +3 -1
- data/lib/easy_data/templates/easy_datas/_linked_data_model.html.erb +19 -1
- data/lib/easy_data/templates/easy_datas/_linked_datas.html.erb +6 -5
- data/lib/easy_data/templates/easy_datas/_list_model_info.html.erb +2 -2
- data/lib/easy_data/templates/easy_datas/_list_properties.html.erb +2 -2
- data/lib/easy_data/templates/easy_datas/_list_properties_edit.html.erb +31 -30
- data/lib/easy_data/templates/easy_datas/_menu.html.erb +4 -4
- data/lib/easy_data/templates/easy_datas/_menu_custom.html.erb +11 -8
- data/lib/easy_data/templates/easy_datas/_model_attributes.html.erb +4 -2
- data/lib/easy_data/templates/easy_datas/_model_attributes_edit.html.erb +14 -13
- data/lib/easy_data/templates/easy_datas/_model_attributes_info.html.erb +16 -9
- data/lib/easy_data/templates/easy_datas/_settings.html.erb +7 -4
- data/lib/easy_data/templates/easy_datas/authenticate_user.html.erb +9 -3
- data/lib/easy_data/templates/easy_datas/custom_rdf.html.erb +7 -5
- data/lib/easy_data/templates/easy_datas/show.xml.builder +15 -13
- data/lib/easy_data/templates/easy_datas/show_all.xml.builder +5 -5
- data/lib/easy_data/templates/easy_datas/view_settings.html.erb +4 -1
- data/lib/easy_data/templates/images/LogoEasyData.jpg +0 -0
- data/lib/easy_data/templates/images/lock.png +0 -0
- data/lib/easy_data/templates/images/loginBt.png +0 -0
- data/lib/easy_data/templates/images/login_bg.png +0 -0
- data/lib/easy_data/templates/images/powerby.jpg +0 -0
- data/lib/easy_data/templates/images/rdf_icon.png +0 -0
- data/lib/easy_data/templates/images/rdf_icon_s.png +0 -0
- data/lib/easy_data/templates/layouts/easy_data_layout.html.erb +3 -2
- data/lib/easy_data/templates/stylesheets/easy_data_style.css +39 -23
- data/lib/easy_data/version.rb +1 -1
- data/lib/easy_data.rb +34 -3
- data/lib/routes.rb +5 -9
- data/lib/tasks/testing_installation.rb +1 -1
- data/test/data_models_test.rb +11 -0
- data/test/rdfa_test.rb +18 -0
- data/test/unit/RDFa_test.rb +1 -0
- data/test/unit/data_models_test.rb +10 -0
- data/test/unit/linked_data_graph_test.rb +1 -0
- data/test/unit/model_rdf_test.rb +1 -0
- data/test/unit/namespaces_test.rb +2 -0
- metadata +33 -12
- data/lib/easy_data/templates/images/main_menu.jpg +0 -0
- data/lib/easy_data/templates/images/rdf_icon.jpeg +0 -0
data/.gitignore
CHANGED
data/.idea/EasyData.iml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager">
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
5
|
+
<orderEntry type="inheritedJdk" />
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
7
|
+
<orderEntry type="library" scope="PROVIDED" name="haml (v3.0.25, RVM: ruby-1.9.2-p180 [easy_data]) [gem]" level="application" />
|
8
|
+
<orderEntry type="library" scope="PROVIDED" name="hpricot (v0.8.4, RVM: ruby-1.9.2-p180 [easy_data]) [gem]" level="application" />
|
9
|
+
</component>
|
10
|
+
</module>
|
11
|
+
|
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="DependencyValidationManager">
|
4
|
+
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
5
|
+
</component>
|
6
|
+
<component name="ProjectResources">
|
7
|
+
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
|
8
|
+
</component>
|
9
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.2-p180 [easy_data]" project-jdk-type="RUBY_SDK" />
|
10
|
+
</project>
|
11
|
+
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/EasyData.iml" filepath="$PROJECT_DIR$/.idea/EasyData.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
9
|
+
|
data/.idea/vcs.xml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/easy_data.gemspec
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
|
4
|
-
|
5
4
|
require "easy_data/version"
|
6
5
|
|
7
6
|
Gem::Specification.new do |s|
|
@@ -16,7 +15,7 @@ Gem::Specification.new do |s|
|
|
16
15
|
s.rubyforge_project = "easy_data"
|
17
16
|
|
18
17
|
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files
|
18
|
+
s.test_files = `git ls-files test/*`.split("\n")
|
20
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
20
|
s.require_paths = ["lib"]
|
22
21
|
|
@@ -9,46 +9,64 @@ class EasyDatasController < ActionController::Base
|
|
9
9
|
before_filter :authenticated, :only => [:custom_rdf]
|
10
10
|
|
11
11
|
def show
|
12
|
-
|
13
|
-
|
12
|
+
begin
|
13
|
+
model = (eval params[:model].to_s)
|
14
14
|
|
15
|
-
|
15
|
+
conditions = parser_params(params)
|
16
16
|
|
17
17
|
rdf = ModelRdf.new
|
18
18
|
|
19
|
-
|
20
|
-
@reply = model.find :all, :conditions => conditions || nil
|
21
|
-
end
|
22
|
-
|
23
|
-
@host="http://"+request.env["HTTP_HOST"]
|
19
|
+
no_valid = lambda{|c| c.nil?||c.empty?}
|
24
20
|
|
25
|
-
@
|
21
|
+
@reply = model.find :all, :conditions => {:id => params[:id]}
|
22
|
+
|
23
|
+
unless @reply.nil?
|
24
|
+
@host="http://"+request.env["HTTP_HOST"]
|
26
25
|
|
26
|
+
@rdf_model = rdf.get_model_rdf(@reply,params[:model],"http://"+request.env["HTTP_HOST"])
|
27
|
+
end
|
28
|
+
|
27
29
|
@xml = Builder::XmlMarkup.new
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated
|
32
|
+
render :nothing => true, :status => 400
|
33
|
+
else
|
34
|
+
respond_to do |format|
|
35
|
+
format.html
|
36
|
+
format.xml # render :template => "/rdf/request.xml.builder"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
render :nothing => true, :status => 404
|
32
41
|
end
|
33
|
-
|
34
42
|
end
|
35
43
|
|
36
44
|
def show_all
|
37
|
-
|
45
|
+
begin
|
46
|
+
model = eval params[:model].to_s
|
38
47
|
|
39
|
-
|
48
|
+
rdf = ModelRdf.new
|
40
49
|
|
41
|
-
|
50
|
+
no_valid = lambda{|c| c.nil?||c.empty?}
|
51
|
+
|
52
|
+
@reply = model.find :all || nil
|
42
53
|
|
43
|
-
|
54
|
+
@host="http://"+request.env["HTTP_HOST"]
|
44
55
|
|
45
|
-
|
56
|
+
@rdf_model = rdf.get_model_rdf(@reply,params[:model],"http://"+request.env["HTTP_HOST"])
|
46
57
|
|
47
|
-
|
58
|
+
@xml = Builder::XmlMarkup.new
|
48
59
|
|
49
|
-
|
50
|
-
|
51
|
-
|
60
|
+
if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated
|
61
|
+
render :nothing => true, :status => 404
|
62
|
+
else
|
63
|
+
respond_to do |format|
|
64
|
+
format.html
|
65
|
+
format.xml # render :template => "/rdf/request.xml.builder"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
rescue
|
69
|
+
render :nothing => true, :status => 404
|
52
70
|
end
|
53
71
|
end
|
54
72
|
|
@@ -56,14 +74,15 @@ class EasyDatasController < ActionController::Base
|
|
56
74
|
#
|
57
75
|
#
|
58
76
|
def info_easy_data
|
59
|
-
|
77
|
+
rdf = ModelRdf.new
|
78
|
+
models = rdf.get_not_hidden_models
|
60
79
|
@list = []
|
61
80
|
@settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml"))
|
62
81
|
|
63
82
|
models.each do |mod|
|
64
83
|
@list << "#{mod.gsub("::","_")}"
|
65
84
|
end
|
66
|
-
|
85
|
+
|
67
86
|
respond_to do |format|
|
68
87
|
format.html
|
69
88
|
format.xml
|
@@ -90,13 +109,10 @@ class EasyDatasController < ActionController::Base
|
|
90
109
|
def model_attributes
|
91
110
|
|
92
111
|
rdf = ModelRdf.new
|
93
|
-
|
94
112
|
@model_attributes = rdf.get_attributes_model(params[:model])
|
95
113
|
@model = params[:model]
|
96
|
-
|
97
114
|
|
98
115
|
render :partial => "model_attributes",:layout => nil
|
99
|
-
|
100
116
|
end
|
101
117
|
|
102
118
|
def model_attributes_edit
|
@@ -149,15 +165,22 @@ class EasyDatasController < ActionController::Base
|
|
149
165
|
render :inline => ""
|
150
166
|
end
|
151
167
|
end
|
152
|
-
|
168
|
+
|
153
169
|
def load_linked_data_graph
|
154
170
|
if params[:model]
|
155
171
|
@model = params[:model]
|
172
|
+
@associations = ModelRdf.new.get_associations_model(@model)
|
173
|
+
@host = "http://"+request.env["HTTP_HOST"]
|
156
174
|
render :partial => "linked_data_model"
|
157
175
|
else
|
158
|
-
|
176
|
+
rdf = ModelRdf.new
|
177
|
+
models = []
|
178
|
+
DataModels.load_models.each do |mod|
|
179
|
+
unless rdf.hidden?(mod)
|
180
|
+
models << mod
|
181
|
+
end
|
182
|
+
end
|
159
183
|
@list = []
|
160
|
-
|
161
184
|
models.each do |mod|
|
162
185
|
@list << "#{mod.gsub("::","_")}"
|
163
186
|
end
|
@@ -167,33 +190,39 @@ class EasyDatasController < ActionController::Base
|
|
167
190
|
end
|
168
191
|
|
169
192
|
def custom_attributes
|
170
|
-
|
193
|
+
|
171
194
|
rdf = ModelRdf.new
|
172
195
|
@model = params[:model]
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
rdf.update_attributes_model(params[:model],att,'property',params["attributes_property"][att])
|
178
|
-
rdf.update_attributes_model(params[:model],att,'privacy',rdf.privacy(params[:privacy][att].to_i))
|
196
|
+
|
197
|
+
params["rdf_type_attributes"].each do |att,value|
|
198
|
+
rdf.update_attributes_model(params[:model],att,'namespace',value) if value != ""
|
199
|
+
if params["attributes_property"] && !params["attributes_property"][att].nil?
|
200
|
+
rdf.update_attributes_model(params[:model],att,'property',params["attributes_property"][att])
|
179
201
|
end
|
180
|
-
|
202
|
+
rdf.update_attributes_model(params[:model],att,'privacy',params[:privacy][att])
|
181
203
|
end
|
182
|
-
|
183
|
-
|
184
|
-
|
204
|
+
|
205
|
+
|
206
|
+
params["rdf_type_associations"].each do |assoc,value|
|
207
|
+
|
208
|
+
if value != ""
|
185
209
|
rdf.update_associations_model(params[:model],assoc,'namespace',value)
|
210
|
+
end
|
211
|
+
if params["associations_property"] && params["associations_property"][assoc]
|
186
212
|
rdf.update_associations_model(params[:model],assoc,'property',params["associations_property"][assoc])
|
187
|
-
rdf.update_associations_model(params[:model],assoc,'privacy',rdf.privacy(params[:privacy][assoc].to_i))
|
188
213
|
end
|
189
|
-
|
214
|
+
rdf.update_associations_model(params[:model],assoc,'privacy',params[:privacy][assoc])
|
215
|
+
|
190
216
|
end
|
191
217
|
|
218
|
+
|
192
219
|
rdf.update_model(params[:model],"privacy",params[:privacy][params[:model]]) if params[:privacy][params[:model]]
|
220
|
+
|
193
221
|
if params[:property]
|
194
222
|
rdf.update_model(params[:model],"namespace",params[:namespace][params[:model]])
|
195
223
|
rdf.update_model(params[:model],"property",params[:property][params[:model]])
|
196
224
|
end
|
225
|
+
|
197
226
|
rdf.save
|
198
227
|
|
199
228
|
@model_attributes = rdf.get_attributes_model(@model)
|
@@ -226,20 +255,27 @@ class EasyDatasController < ActionController::Base
|
|
226
255
|
if !params["project"]["description"].empty? && params["project"]["description"]!=@settings["project"]["description"]
|
227
256
|
@settings["project"]["description"] = params["project"]["description"]
|
228
257
|
end
|
258
|
+
|
259
|
+
if !params["project"]["email"].empty? && params["project"]["email"]!=@settings["project"]["contact_email"]
|
260
|
+
@settings["project"]["contact_email"] = params["project"]["email"]
|
261
|
+
end
|
229
262
|
|
230
263
|
if !params["user_admin"]["user"].empty? && !params["user_admin"]["pass"].empty?
|
231
264
|
(@settings["user_admin"]["user"] = params["user_admin"]["user"]) if @settings["user_admin"]["user"]!=params["user_admin"]["user"]
|
232
265
|
(@settings["user_admin"]["pass"] = params["user_admin"]["pass"]) if @settings["user_admin"]["pass"]!=params["user_admin"]["pass"]
|
233
266
|
end
|
234
267
|
|
235
|
-
if
|
236
|
-
(@settings["access"]["ip"] = params["access"]["ip"]) if params["access"]["ip"]!=@settings["access"]["ip"]
|
237
|
-
end
|
268
|
+
(@settings["access"]["ip"] = params["access"]["ip"]) if params["access"]["ip"]!=@settings["access"]["ip"] && params["access"]["ip"]!= ""
|
238
269
|
|
239
270
|
save_settings(@settings)
|
240
271
|
|
241
272
|
render :template => "easy_datas/view_settings",:layout => false
|
242
273
|
end
|
274
|
+
|
275
|
+
def refresh_information
|
276
|
+
EasyData.refresh_information
|
277
|
+
redirect_to :action => "custom_rdf"
|
278
|
+
end
|
243
279
|
|
244
280
|
def authenticate_user
|
245
281
|
end
|
@@ -264,12 +300,15 @@ class EasyDatasController < ActionController::Base
|
|
264
300
|
|
265
301
|
private
|
266
302
|
|
303
|
+
# Extract all parameters to build the query.
|
304
|
+
# @param [Hash] request's parameters
|
305
|
+
# @return [Hahs] Conditions hash
|
267
306
|
def parser_params (parameters = nil)
|
268
307
|
|
269
308
|
conditions = {}
|
270
309
|
|
271
310
|
if !parameters.empty?
|
272
|
-
parameters.each do |key,value|
|
311
|
+
parameters.each do |key,value| #Delete all elements that aren't need to query
|
273
312
|
unless ["controller","action","method","format","model"].include?key
|
274
313
|
conditions[key.to_sym] = value
|
275
314
|
end
|
data/lib/data_models/RDFa.rb
CHANGED
@@ -2,21 +2,13 @@ require "data_models/model_rdf"
|
|
2
2
|
|
3
3
|
class RDFa
|
4
4
|
|
5
|
-
def self.model(model)
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.attribute(model,attributes)
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
5
|
####################################
|
14
6
|
# HTML Tags
|
15
7
|
####################################
|
16
8
|
|
17
9
|
#-----------------------------------------------Links
|
18
|
-
def a(model,href,attribute=nil,options=nil)
|
19
|
-
_html_code('a',model,attribute,"href='#{href||'#'}' "+options.to_s)
|
10
|
+
def a(model,href,value,attribute=nil,options=nil)
|
11
|
+
_html_code('a',model,value,attribute,"href='#{href||'#'}' "+options.to_s)
|
20
12
|
end
|
21
13
|
|
22
14
|
#-----------------------------------------------End Links
|
@@ -38,7 +30,7 @@ class RDFa
|
|
38
30
|
nil
|
39
31
|
end
|
40
32
|
#------------------------------------------------END AUTO-CLOSED
|
41
|
-
|
33
|
+
|
42
34
|
# This method is called if doesnt exist the method called by class's users
|
43
35
|
def method_missing(sym, *args, &block)
|
44
36
|
_html_code(sym.to_s,args[0],args[1],args[2],args[3])
|
@@ -49,14 +41,25 @@ class RDFa
|
|
49
41
|
#######################################
|
50
42
|
private
|
51
43
|
|
44
|
+
# This method generate a HTML tag with RDFa information included.
|
45
|
+
# @param [String] Html tag
|
46
|
+
# @param [String] Model's name
|
47
|
+
# @param [String] Tag content.
|
48
|
+
# @param [String] model's attribute
|
49
|
+
# @param [String] css and html tag options
|
50
|
+
# @return [String] Html tag with RDFa information
|
52
51
|
def _html_code(tag,model,value,attribute,options = "")
|
53
|
-
rdf_info = ModelRdf.new
|
52
|
+
rdf_info = ModelRdf.new
|
54
53
|
|
55
54
|
if attribute.nil? #prefix + type_of
|
56
55
|
options = (options || "") + rdf_info.get_prefix(model)
|
57
56
|
options = options + rdf_info.model(model)
|
58
57
|
else #property
|
59
|
-
|
58
|
+
if attribute!=model
|
59
|
+
options = (options||"") + rdf_info.attribute(model,attribute)
|
60
|
+
else
|
61
|
+
options = (options||"") + rdf_info.model(model)
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
unless value.nil?
|
@@ -66,6 +69,12 @@ class RDFa
|
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
72
|
+
# This method generate a HTML list tag with RDFa information included.
|
73
|
+
# @param [String] Html tag
|
74
|
+
# @param [String] Model's name
|
75
|
+
# @param [String] Tag content
|
76
|
+
# @param [String] css and html tag options
|
77
|
+
# @return [String] Html list tag with RDFa information
|
69
78
|
def _html_code_list(tag,model,value,options = "")
|
70
79
|
rdf_info = ModelRdf.new
|
71
80
|
|
@@ -1,21 +1,26 @@
|
|
1
1
|
module DataModels
|
2
|
-
|
2
|
+
# This method reads all models that the project hash.
|
3
|
+
# @return [Array] The proyect models list.
|
3
4
|
def self.load_models
|
4
5
|
|
5
|
-
models = []
|
6
|
-
models_valids = []
|
6
|
+
models = [] #All models will be in this list.
|
7
|
+
models_valids = [] #This list is only to models with database table associated.
|
7
8
|
mod = nil
|
8
9
|
|
10
|
+
#Get all models in Model's folder
|
9
11
|
Dir["#{RAILS_ROOT}/app/models/**/*.rb"].each do |file|
|
10
12
|
models << file.gsub(RAILS_ROOT+'/app/models/',"").gsub('.rb','').classify
|
11
13
|
end
|
12
14
|
|
15
|
+
# Here, get the correct model's name: Singular or Plural
|
13
16
|
models.each do |model|
|
14
17
|
begin
|
15
18
|
mod = eval model
|
19
|
+
mod.columns
|
16
20
|
rescue
|
17
21
|
begin
|
18
22
|
mod = eval model.pluralize
|
23
|
+
mod.columns
|
19
24
|
rescue
|
20
25
|
mod = nil
|
21
26
|
end
|
@@ -28,14 +33,21 @@ module DataModels
|
|
28
33
|
models_valids
|
29
34
|
end
|
30
35
|
|
36
|
+
# This method return all model's attributes.
|
37
|
+
# @param [String] model's name
|
38
|
+
# @return [Array] model's attribute list.
|
31
39
|
def self.model_attributes(model)
|
32
40
|
model.columns.map{|att| att.name}.join(", ")
|
33
41
|
end
|
34
42
|
|
43
|
+
# This method return all model's relations
|
44
|
+
# @param [String] model's name
|
45
|
+
# @return [Hash] hash with all relations and relations type
|
35
46
|
def self.model_relations(model)
|
36
47
|
|
37
48
|
relations = {}
|
38
|
-
|
49
|
+
|
50
|
+
#Build the hash with relation name and relation's type.
|
39
51
|
model.reflections.each do |relation,values|
|
40
52
|
relations[relation] = {"model" => values.class_name,"type" => values.macro.to_s}
|
41
53
|
end
|
@@ -43,10 +55,15 @@ module DataModels
|
|
43
55
|
relations
|
44
56
|
end
|
45
57
|
|
58
|
+
# Return all RDF information stored in yaml file.
|
59
|
+
# @return [Hash] hash with all information stored in yaml file.
|
46
60
|
def self.build_models_yaml_file
|
47
61
|
self.models
|
48
62
|
end
|
49
63
|
|
64
|
+
# Return data model.
|
65
|
+
# @param [String] model's name
|
66
|
+
# @return [Hash] data model's information.
|
50
67
|
def self.get_model_data(model)
|
51
68
|
begin
|
52
69
|
eval model
|