Commit e4797aafbb31ea22a3331ecb602bb4b04c79807d
1 parent
6698b64c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: small fixes
Showing
4 changed files
with
18 additions
and
11 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin.rb
1 | class VirtuosoPlugin < Noosfero::Plugin | 1 | class VirtuosoPlugin < Noosfero::Plugin |
2 | 2 | ||
3 | - @virtuosoServers | ||
4 | - | ||
5 | def self.plugin_name | 3 | def self.plugin_name |
6 | "Virtuoso integration" | 4 | "Virtuoso integration" |
7 | end | 5 | end |
@@ -30,6 +28,12 @@ class VirtuosoPlugin < Noosfero::Plugin | @@ -30,6 +28,12 @@ class VirtuosoPlugin < Noosfero::Plugin | ||
30 | true | 28 | true |
31 | end | 29 | end |
32 | 30 | ||
31 | + def self.ontology_mapping_default_setting | ||
32 | + VirtuosoPlugin::DublinCoreMetadata::FIELDS.map do |field| | ||
33 | + {:source => "dc:#{field}", :target => "http://purl.org/dc/elements/1.1/#{field}"} | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
33 | protected | 37 | protected |
34 | 38 | ||
35 | def virtuoso_client_builder(uri, username, password) | 39 | def virtuoso_client_builder(uri, username, password) |
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
@@ -24,10 +24,10 @@ class VirtuosoPlugin::DspaceHarvest | @@ -24,10 +24,10 @@ class VirtuosoPlugin::DspaceHarvest | ||
24 | metadata = VirtuosoPlugin::DublinCoreMetadata.new(record.metadata) | 24 | metadata = VirtuosoPlugin::DublinCoreMetadata.new(record.metadata) |
25 | puts "triplify #{record.header.identifier}" | 25 | puts "triplify #{record.header.identifier}" |
26 | 26 | ||
27 | - DC_CONVERSION.each do |c| | ||
28 | - values = [metadata.send(c)].flatten.compact | 27 | + settings.ontology_mapping.each do |mapping| |
28 | + values = [metadata.extract_field(mapping[:source])].flatten.compact | ||
29 | values.each do |value| | 29 | values.each do |value| |
30 | - 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(@dspace_uri)) | 30 | + query = RDF::Virtuoso::Query.insert_data([RDF::URI.new(metadata.identifier), RDF::URI.new(mapping[:target]), value]).graph(RDF::URI.new(@dspace_uri)) |
31 | plugin.virtuoso_client.insert(query) | 31 | plugin.virtuoso_client.insert(query) |
32 | end | 32 | end |
33 | end | 33 | end |
@@ -53,16 +53,15 @@ class VirtuosoPlugin::DspaceHarvest | @@ -53,16 +53,15 @@ class VirtuosoPlugin::DspaceHarvest | ||
53 | settings.save! | 53 | settings.save! |
54 | puts "ending harvest #{harvest_time}" | 54 | puts "ending harvest #{harvest_time}" |
55 | end | 55 | end |
56 | - | 56 | + |
57 | def self.harvest_all(environment, from_start) | 57 | def self.harvest_all(environment, from_start) |
58 | settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) | 58 | settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) |
59 | settings.dspace_servers.each do |k, v| | 59 | settings.dspace_servers.each do |k, v| |
60 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri]) | 60 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri]) |
61 | harvest.start(from_start) | 61 | harvest.start(from_start) |
62 | - harvest.run | ||
63 | - end | ||
64 | - end | ||
65 | - | 62 | + end |
63 | + end | ||
64 | + | ||
66 | def start(from_start = false) | 65 | def start(from_start = false) |
67 | if find_job.empty? | 66 | if find_job.empty? |
68 | if from_start | 67 | if from_start |
plugins/virtuoso/lib/virtuoso_plugin/dublin_core_metadata.rb
@@ -21,7 +21,7 @@ class VirtuosoPlugin::DublinCoreMetadata | @@ -21,7 +21,7 @@ class VirtuosoPlugin::DublinCoreMetadata | ||
21 | when 1 | 21 | when 1 |
22 | value.first.text | 22 | value.first.text |
23 | else | 23 | else |
24 | - value.map(&:text) | 24 | + value.map { |v| v.respond_to?(:text) ? v.text : v} |
25 | end | 25 | end |
26 | end | 26 | end |
27 | 27 |
plugins/virtuoso/test/unit/virtuoso_plugin_test.rb
@@ -29,4 +29,8 @@ class VirtuosoPluginTest < ActiveSupport::TestCase | @@ -29,4 +29,8 @@ class VirtuosoPluginTest < ActiveSupport::TestCase | ||
29 | plugin.virtuoso_readonly_client | 29 | plugin.virtuoso_readonly_client |
30 | end | 30 | end |
31 | 31 | ||
32 | + should 'has a default value for ontology mapping setting' do | ||
33 | + assert plugin.settings.ontology_mapping | ||
34 | + end | ||
35 | + | ||
32 | end | 36 | end |