Commit d0fa2ba717085edd10219e2baa5b03e773ab26f2
Exists in
staging
and in
4 other branches
Merge branch 'virtuoso_integration' of gitlab.com:participa/noosfero into virtuoso_integration
Showing
11 changed files
with
78 additions
and
13 deletions
Show diff stats
plugins/virtuoso/Gemfile
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
@@ -8,7 +8,7 @@ class VirtuosoPluginAdminController < AdminController | @@ -8,7 +8,7 @@ class VirtuosoPluginAdminController < AdminController | ||
8 | 8 | ||
9 | if request.post? | 9 | if request.post? |
10 | @settings.save! | 10 | @settings.save! |
11 | - session[:notice] = 'Settings succefully saved.' | 11 | + session[:notice] = 'Settings successfully saved.' |
12 | redirect_to :action => 'index' | 12 | redirect_to :action => 'index' |
13 | end | 13 | end |
14 | end | 14 | end |
plugins/virtuoso/lib/virtuoso_plugin.rb
@@ -20,4 +20,8 @@ class VirtuosoPlugin < Noosfero::Plugin | @@ -20,4 +20,8 @@ class VirtuosoPlugin < Noosfero::Plugin | ||
20 | @virtuoso_client ||= RDF::Virtuoso::Repository.new("#{settings.virtuoso_uri}/sparql", :update_uri => "#{settings.virtuoso_uri}/sparql-auth", :username => settings.virtuoso_username, :password => settings.virtuoso_password, :auth_method => 'digest', :timeout => 30) | 20 | @virtuoso_client ||= RDF::Virtuoso::Repository.new("#{settings.virtuoso_uri}/sparql", :update_uri => "#{settings.virtuoso_uri}/sparql-auth", :username => settings.virtuoso_username, :password => settings.virtuoso_password, :auth_method => 'digest', :timeout => 30) |
21 | end | 21 | end |
22 | 22 | ||
23 | + def stylesheet? | ||
24 | + true | ||
25 | + end | ||
26 | + | ||
23 | end | 27 | end |
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
@@ -27,7 +27,7 @@ class VirtuosoPlugin::DspaceHarvest | @@ -27,7 +27,7 @@ class VirtuosoPlugin::DspaceHarvest | ||
27 | values = [metadata.send(c)].flatten.compact | 27 | values = [metadata.send(c)].flatten.compact |
28 | values.each do |value| | 28 | values.each do |value| |
29 | query = RDF::Virtuoso::Query.insert_data([RDF::URI.new(metadata.identifier), RDF::URI.new("http://purl.org/dc/elements/1.1/#{c}"), value]).graph(RDF::URI.new(settings.dspace_uri)) | 29 | query = RDF::Virtuoso::Query.insert_data([RDF::URI.new(metadata.identifier), RDF::URI.new("http://purl.org/dc/elements/1.1/#{c}"), value]).graph(RDF::URI.new(settings.dspace_uri)) |
30 | - virtuoso_client.insert(query) | 30 | + plugin.virtuoso_client.insert(query) |
31 | end | 31 | end |
32 | end | 32 | end |
33 | end | 33 | end |
plugins/virtuoso/lib/virtuoso_plugin/dublin_core_metadata.rb
@@ -9,7 +9,7 @@ class VirtuosoPlugin::DublinCoreMetadata | @@ -9,7 +9,7 @@ class VirtuosoPlugin::DublinCoreMetadata | ||
9 | @creator = xpath(element, './/dc:creator') | 9 | @creator = xpath(element, './/dc:creator') |
10 | @subject = xpath_all(element, './/dc:subject').map(&:text) | 10 | @subject = xpath_all(element, './/dc:subject').map(&:text) |
11 | @description = xpath(element, './/dc:description') | 11 | @description = xpath(element, './/dc:description') |
12 | - @date = xpath_all(element, './/dc:date').map(&:text) | 12 | + @date = xpath(element, './/dc:date') |
13 | @type = xpath(element, './/dc:type') | 13 | @type = xpath(element, './/dc:type') |
14 | @identifier = xpath(element, './/dc:identifier') | 14 | @identifier = xpath(element, './/dc:identifier') |
15 | @language = xpath(element, './/dc:language') | 15 | @language = xpath(element, './/dc:language') |
plugins/virtuoso/lib/virtuoso_plugin/triples_template.rb
@@ -25,9 +25,14 @@ class VirtuosoPlugin::TriplesTemplate < Article | @@ -25,9 +25,14 @@ class VirtuosoPlugin::TriplesTemplate < Article | ||
25 | end | 25 | end |
26 | 26 | ||
27 | def template_content | 27 | def template_content |
28 | - plugin.virtuoso_client.query(query).map do |r| | ||
29 | - template % r | ||
30 | - end.join | 28 | + begin |
29 | + results = plugin.virtuoso_client.query(query) | ||
30 | + liquid_template = Liquid::Template.parse("{% for row in results %}#{template}{% endfor %}") | ||
31 | + liquid_template.render('results' => results) | ||
32 | + rescue => ex | ||
33 | + logger.info ex.to_s | ||
34 | + "Failed to process the template" | ||
35 | + end | ||
31 | end | 36 | end |
32 | 37 | ||
33 | end | 38 | end |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class TriplesTemplateTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @article = VirtuosoPlugin::TriplesTemplate.new | ||
7 | + end | ||
8 | + | ||
9 | + attr_reader :article | ||
10 | + | ||
11 | + should 'evaluate template using query results' do | ||
12 | + article.stubs(:plugin).returns(mock) | ||
13 | + article.plugin.expects(:virtuoso_client).at_least_once.returns(mock) | ||
14 | + article.plugin.virtuoso_client.expects(:query).returns([{'var' => 'Hello '}, {'var' => 'World'}]) | ||
15 | + article.template = "{{row.var}}" | ||
16 | + | ||
17 | + assert_equal 'Hello World', article.template_content | ||
18 | + end | ||
19 | + | ||
20 | + should 'display error message when failed to execute the query' do | ||
21 | + article.stubs(:plugin).returns(mock) | ||
22 | + article.plugin.expects(:virtuoso_client).at_least_once.returns(mock) | ||
23 | + article.plugin.virtuoso_client.expects(:query).raises(RuntimeError.new) | ||
24 | + article.template = "{{row.var}}" | ||
25 | + | ||
26 | + assert_equal "Failed to process the template", article.template_content | ||
27 | + end | ||
28 | + | ||
29 | +end |
plugins/virtuoso/views/cms/virtuoso_plugin/_triples_template.html.erb
1 | -<%= required_fields_message %> | 1 | +<div class="virtuoso-triples-template"> |
2 | + <%= required_fields_message %> | ||
2 | 3 | ||
3 | -<%= render :file => 'shared/tiny_mce' %> | 4 | + <%= render :file => 'shared/tiny_mce' %> |
4 | 5 | ||
5 | -<%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> | ||
6 | -<%= labelled_form_field(_('SPARQL Query'), text_area(:article, :query, :style => 'width: 98%; height: 120px;')) %> | ||
7 | -<%= labelled_form_field(_('Template'), text_area(:article, :template, :style => 'width: 98%; height: 200px;', :class => 'mceEditor')) %> | 6 | + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> |
7 | + <%= labelled_form_field(_('SPARQL Query'), text_area(:article, :query, :style => 'width: 98%; height: 120px;')) %> | ||
8 | 8 | ||
9 | -<%= render :partial => 'general_fields' %> | ||
10 | -<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> | 9 | + <div class="template"> |
10 | + <span class="label"><%= _('Template') %></span> | ||
11 | + <span class="reference" style="float: right;"><a href="https://github.com/Shopify/liquid/wiki/Liquid-for-Designers"><%= _('Template reference') %></a></span> | ||
12 | + <span class="input"> | ||
13 | + <%= text_area(:article, :template, :style => 'width: 98%; height: 200px;', :class => 'mceEditor') %> | ||
14 | + </span> | ||
15 | + </div> | ||
16 | + | ||
17 | + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> | ||
18 | + <%= render :partial => 'general_fields' %> | ||
19 | +</div> |