Commit efd6f22ec182782077682d0a7e58ea839124c1fd
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'virtuoso_integration' of gitlab.com:participa/noosfero into virtuoso_integration
Showing
10 changed files
with
101 additions
and
8 deletions
Show diff stats
plugins/virtuoso/Gemfile
plugins/virtuoso/lib/virtuoso_plugin.rb
@@ -8,4 +8,16 @@ class VirtuosoPlugin < Noosfero::Plugin | @@ -8,4 +8,16 @@ class VirtuosoPlugin < Noosfero::Plugin | ||
8 | _('Virtuoso integration') | 8 | _('Virtuoso integration') |
9 | end | 9 | end |
10 | 10 | ||
11 | + def content_types | ||
12 | + [VirtuosoPlugin::TriplesTemplate] | ||
13 | + end | ||
14 | + | ||
15 | + def settings | ||
16 | + @settings ||= Noosfero::Plugin::Settings.new(context.environment, VirtuosoPlugin) | ||
17 | + end | ||
18 | + | ||
19 | + def virtuoso_client | ||
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 | ||
22 | + | ||
11 | end | 23 | end |
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
@@ -7,18 +7,18 @@ class VirtuosoPlugin::DspaceHarvest | @@ -7,18 +7,18 @@ class VirtuosoPlugin::DspaceHarvest | ||
7 | @environment = environment | 7 | @environment = environment |
8 | end | 8 | end |
9 | 9 | ||
10 | - def settings | ||
11 | - @settings ||= Noosfero::Plugin::Settings.new(@environment, VirtuosoPlugin) | 10 | + attr_reader :environment |
11 | + | ||
12 | + def plugin | ||
13 | + @plugin ||= VirtuosoPlugin.new(self) | ||
12 | end | 14 | end |
13 | 15 | ||
16 | + delegate :settings, :to => :plugin | ||
17 | + | ||
14 | def dspace_client | 18 | def dspace_client |
15 | @dspace_client ||= OAI::Client.new("#{settings.dspace_uri}/oai/request") | 19 | @dspace_client ||= OAI::Client.new("#{settings.dspace_uri}/oai/request") |
16 | end | 20 | end |
17 | 21 | ||
18 | - def virtuoso_client | ||
19 | - @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 | - end | ||
21 | - | ||
22 | def triplify(record) | 22 | def triplify(record) |
23 | metadata = VirtuosoPlugin::DublinCoreMetadata.new(record.metadata) | 23 | metadata = VirtuosoPlugin::DublinCoreMetadata.new(record.metadata) |
24 | puts "triplify #{record.header.identifier}" | 24 | puts "triplify #{record.header.identifier}" |
@@ -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
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +class VirtuosoPlugin::TriplesTemplate < Article | ||
2 | + | ||
3 | + def self.short_description | ||
4 | + _('Triples template') | ||
5 | + end | ||
6 | + | ||
7 | + def self.description | ||
8 | + _('Triples template') | ||
9 | + end | ||
10 | + | ||
11 | + settings_items :query, :type => :string | ||
12 | + settings_items :template, :type => :string | ||
13 | + | ||
14 | + attr_accessible :query, :template | ||
15 | + | ||
16 | + def to_html(options = {}) | ||
17 | + article = self | ||
18 | + proc do | ||
19 | + render :file => 'content_viewer/triples_template', :locals => {:article => article} | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
23 | + def plugin | ||
24 | + @plugin ||= VirtuosoPlugin.new(self) | ||
25 | + end | ||
26 | + | ||
27 | + def template_content | ||
28 | + results = plugin.virtuoso_client.query(query) | ||
29 | + liquid_template = Liquid::Template.parse("{% for row in results %}#{template}{% endfor %}") | ||
30 | + liquid_template.render('results' => results) | ||
31 | + end | ||
32 | + | ||
33 | +end |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class VirtuosoPluginTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + def setup | ||
6 | + @environment = Environment.default | ||
7 | + @plugin = VirtuosoPlugin.new | ||
8 | + end | ||
9 | + | ||
10 | + attr_reader :plugin | ||
11 | + | ||
12 | + should 'define a new content' do | ||
13 | + assert_equal [VirtuosoPlugin::TriplesTemplate], plugin.content_types | ||
14 | + end | ||
15 | + | ||
16 | +end |
plugins/virtuoso/views/cms/virtuoso_plugin/_triples_template.html.erb
0 → 100644
@@ -0,0 +1,10 @@ | @@ -0,0 +1,10 @@ | ||
1 | +<%= required_fields_message %> | ||
2 | + | ||
3 | +<%= render :file => 'shared/tiny_mce' %> | ||
4 | + | ||
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')) %> | ||
8 | + | ||
9 | +<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> | ||
10 | +<%= render :partial => 'general_fields' %> |
plugins/virtuoso/views/content_viewer/triples_template.html.erb
0 → 100644