Commit f77e542e3dfdc2bb3908e119f663dd0c277efb48
1 parent
c770f8a4
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Support to multiple dspace servers
(Todo fix access permissions)
Showing
8 changed files
with
63 additions
and
69 deletions
Show diff stats
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
1 | class VirtuosoPluginAdminController < AdminController | 1 | class VirtuosoPluginAdminController < AdminController |
2 | 2 | ||
3 | + #validates :dspace_servers, presence: true | ||
4 | + | ||
3 | def index | 5 | def index |
4 | settings = params[:settings] | 6 | settings = params[:settings] |
5 | settings ||= {} | 7 | settings ||= {} |
6 | - | ||
7 | -# raise settings.inspect.to_yaml | ||
8 | - | ||
9 | -# --- ! '{"virtuoso_uri"=>"http://hom.virtuoso.participa.br", "virtuoso_username"=>"dba", | ||
10 | -# "virtuoso_password"=>"dasas", "dspace_uri"=>"http://hom.dspace.participa.br"}#' | ||
11 | - | ||
12 | @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | 8 | @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) |
13 | @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present? | 9 | @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present? |
14 | - | ||
15 | if request.post? | 10 | if request.post? |
11 | + settings[:dspace_servers].delete_if do | server | | ||
12 | + server[:dspace_uri].empty? | ||
13 | + end | ||
16 | @settings.save! | 14 | @settings.save! |
17 | session[:notice] = 'Settings successfully saved.' | 15 | session[:notice] = 'Settings successfully saved.' |
18 | redirect_to :action => 'index' | 16 | redirect_to :action => 'index' |
@@ -20,8 +18,7 @@ class VirtuosoPluginAdminController < AdminController | @@ -20,8 +18,7 @@ class VirtuosoPluginAdminController < AdminController | ||
20 | end | 18 | end |
21 | 19 | ||
22 | def force_harvest | 20 | def force_harvest |
23 | - harvest = VirtuosoPlugin::DspaceHarvest.new(environment) | ||
24 | - harvest.start(params[:from_start]) | 21 | + VirtuosoPlugin::DspaceHarvest.harverst_all(environment, params[:from_start]) |
25 | session[:notice] = _('Harvest started') | 22 | session[:notice] = _('Harvest started') |
26 | redirect_to :action => :index | 23 | redirect_to :action => :index |
27 | end | 24 | end |
plugins/virtuoso/lib/virtuoso_plugin.rb
@@ -21,10 +21,6 @@ class VirtuosoPlugin < Noosfero::Plugin | @@ -21,10 +21,6 @@ class VirtuosoPlugin < Noosfero::Plugin | ||
21 | def virtuoso_client | 21 | def virtuoso_client |
22 | @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) | 22 | @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) |
23 | end | 23 | end |
24 | - | ||
25 | - def js_files | ||
26 | - ['edit-server-list'] | ||
27 | - end | ||
28 | 24 | ||
29 | def stylesheet? | 25 | def stylesheet? |
30 | true | 26 | true |
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
@@ -2,9 +2,10 @@ | @@ -2,9 +2,10 @@ | ||
2 | class VirtuosoPlugin::DspaceHarvest | 2 | class VirtuosoPlugin::DspaceHarvest |
3 | 3 | ||
4 | DC_CONVERSION = [:title, :creator, :subject, :description, :date, :type, :identifier, :language, :rights, :format] | 4 | DC_CONVERSION = [:title, :creator, :subject, :description, :date, :type, :identifier, :language, :rights, :format] |
5 | - | ||
6 | - def initialize(environment) | 5 | + |
6 | + def initialize(environment, dspace_uri = "") | ||
7 | @environment = environment | 7 | @environment = environment |
8 | + @dspace_uri = dspace_uri | ||
8 | end | 9 | end |
9 | 10 | ||
10 | attr_reader :environment | 11 | attr_reader :environment |
@@ -16,7 +17,7 @@ class VirtuosoPlugin::DspaceHarvest | @@ -16,7 +17,7 @@ class VirtuosoPlugin::DspaceHarvest | ||
16 | delegate :settings, :to => :plugin | 17 | delegate :settings, :to => :plugin |
17 | 18 | ||
18 | def dspace_client | 19 | def dspace_client |
19 | - @dspace_client ||= OAI::Client.new("#{settings.dspace_uri}/oai/request") | 20 | + @dspace_client ||= OAI::Client.new("#{@dspace_uri}/oai/request") |
20 | end | 21 | end |
21 | 22 | ||
22 | def triplify(record) | 23 | def triplify(record) |
@@ -26,7 +27,7 @@ class VirtuosoPlugin::DspaceHarvest | @@ -26,7 +27,7 @@ class VirtuosoPlugin::DspaceHarvest | ||
26 | DC_CONVERSION.each do |c| | 27 | DC_CONVERSION.each do |c| |
27 | values = [metadata.send(c)].flatten.compact | 28 | values = [metadata.send(c)].flatten.compact |
28 | values.each do |value| | 29 | 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)) | 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 | plugin.virtuoso_client.insert(query) | 31 | plugin.virtuoso_client.insert(query) |
31 | end | 32 | end |
32 | end | 33 | end |
@@ -35,7 +36,7 @@ class VirtuosoPlugin::DspaceHarvest | @@ -35,7 +36,7 @@ class VirtuosoPlugin::DspaceHarvest | ||
35 | def run | 36 | def run |
36 | harvest_time = Time.now.utc | 37 | harvest_time = Time.now.utc |
37 | params = settings.last_harvest ? {:from => settings.last_harvest.utc} : {} | 38 | params = settings.last_harvest ? {:from => settings.last_harvest.utc} : {} |
38 | - puts "starting harvest #{params} #{settings.dspace_uri} #{settings.virtuoso_uri}" | 39 | + puts "starting harvest #{params} #{@dspace_uri} #{settings.virtuoso_uri}" |
39 | begin | 40 | begin |
40 | records = dspace_client.list_records(params) | 41 | records = dspace_client.list_records(params) |
41 | records.each do |record| | 42 | records.each do |record| |
@@ -52,14 +53,22 @@ class VirtuosoPlugin::DspaceHarvest | @@ -52,14 +53,22 @@ class VirtuosoPlugin::DspaceHarvest | ||
52 | settings.save! | 53 | settings.save! |
53 | puts "ending harvest #{harvest_time}" | 54 | puts "ending harvest #{harvest_time}" |
54 | end | 55 | end |
55 | - | 56 | + |
57 | + def self.harvest_all(environment, from_start) | ||
58 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) | ||
59 | + settings.dspace_servers.each do |k, v| | ||
60 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri]) | ||
61 | + harvest.start(from_start) | ||
62 | + harvest.run | ||
63 | + end | ||
64 | + end | ||
65 | + | ||
56 | def start(from_start = false) | 66 | def start(from_start = false) |
57 | if find_job.empty? | 67 | if find_job.empty? |
58 | if from_start | 68 | if from_start |
59 | settings.last_harvest = nil | 69 | settings.last_harvest = nil |
60 | settings.save! | 70 | settings.save! |
61 | end | 71 | end |
62 | - | ||
63 | job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id) | 72 | job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id) |
64 | Delayed::Job.enqueue(job) | 73 | Delayed::Job.enqueue(job) |
65 | end | 74 | end |
plugins/virtuoso/public/edit-server-list.js
@@ -13,24 +13,21 @@ function send_ajax(source_url) { | @@ -13,24 +13,21 @@ function send_ajax(source_url) { | ||
13 | } | 13 | } |
14 | }); | 14 | }); |
15 | }, | 15 | }, |
16 | - | ||
17 | minLength: 3 | 16 | minLength: 3 |
18 | }); | 17 | }); |
19 | } | 18 | } |
20 | 19 | ||
21 | function new_server_action(){ | 20 | function new_server_action(){ |
22 | send_ajax(jQuery("#page_url").val()); | 21 | send_ajax(jQuery("#page_url").val()); |
23 | - | ||
24 | jQuery(".delete-server-list-row").click(function(){ | 22 | jQuery(".delete-server-list-row").click(function(){ |
25 | - jQuery(this).parent().parent().remove(); | 23 | + jQuery(this).parent().remove(); |
26 | return false; | 24 | return false; |
27 | }); | 25 | }); |
28 | - | ||
29 | jQuery(document).scrollTop(jQuery('#dropable-server-list').scrollTop()); | 26 | jQuery(document).scrollTop(jQuery('#dropable-server-list').scrollTop()); |
30 | } | 27 | } |
31 | 28 | ||
32 | function add_new_server() { | 29 | function add_new_server() { |
33 | - var new_server = jQuery('#edit-server-list-block #new-template>li').clone(); | 30 | + var new_server = jQuery('#edit-server-list-block #dspace-new-template > div').clone(); |
34 | new_server.show(); | 31 | new_server.show(); |
35 | jQuery('#dropable-server-list').append(new_server); | 32 | jQuery('#dropable-server-list').append(new_server); |
36 | new_server_action(); | 33 | new_server_action(); |
@@ -39,8 +36,8 @@ function add_new_server() { | @@ -39,8 +36,8 @@ function add_new_server() { | ||
39 | jQuery(document).ready(function(){ | 36 | jQuery(document).ready(function(){ |
40 | new_server_action(); | 37 | new_server_action(); |
41 | 38 | ||
42 | - jQuery("#dropable-server-list").sortable({ | ||
43 | - revert: true, | ||
44 | - axis: "y" | ||
45 | - }); | 39 | +// jQuery("#dropable-server-list").sortable({ |
40 | +// revert: true, | ||
41 | +// axis: "y" | ||
42 | +// }); | ||
46 | }); | 43 | }); |
plugins/virtuoso/public/style.css
plugins/virtuoso/views/virtuoso_plugin_admin/_server_list_item.html.erb
1 | -<li> | ||
2 | - <ul class="link-list-row"> | ||
3 | - <li> | ||
4 | - <% value = server_list_item[:dspace_uri] if server_list_item %> | ||
5 | - <%= text_field_tag 'settings[dspace_servers][][dspace_uri]', value, { :class => 'link-name', :maxlength => 40 } %> | ||
6 | - </li> | ||
7 | - <li> | ||
8 | - <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-server-list-row") %> | ||
9 | - </li> | ||
10 | - </ul> | ||
11 | -</li> | 1 | +<div> |
2 | + <% value = server_list_item[:dspace_uri] if server_list_item %> | ||
3 | + <%= text_field_tag 'settings[dspace_servers][][dspace_uri]', value, { :class => 'link-name', :maxlength => 60 } %> | ||
4 | + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-server-list-row") %> | ||
5 | + <BR><BR> | ||
6 | +</div> | ||
7 | + |
plugins/virtuoso/views/virtuoso_plugin_admin/index.html.erb
1 | <%= javascript_include_tag '/plugins/virtuoso/edit-server-list' %> | 1 | <%= javascript_include_tag '/plugins/virtuoso/edit-server-list' %> |
2 | +<link rel="stylesheet" type="text/css" href="/plugins/virtuoso/virtuoso_plugin_admin.css"> | ||
2 | 3 | ||
3 | <h1><%= _('Virtuoso settings') %></h1> | 4 | <h1><%= _('Virtuoso settings') %></h1> |
4 | 5 | ||
5 | <%= form_for(:settings) do |f| %> | 6 | <%= form_for(:settings) do |f| %> |
6 | - | ||
7 | <strong> | 7 | <strong> |
8 | <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri) %> | 8 | <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri) %> |
9 | <%= labelled_form_field _('Virtuoso Username:'), f.text_field(:virtuoso_username) %> | 9 | <%= labelled_form_field _('Virtuoso Username:'), f.text_field(:virtuoso_username) %> |
10 | <%= labelled_form_field _('Virtuoso Password:'), f.password_field(:virtuoso_password) %> | 10 | <%= labelled_form_field _('Virtuoso Password:'), f.password_field(:virtuoso_password) %> |
11 | </strong> | 11 | </strong> |
12 | - | ||
13 | -<strong><%= _('Dspace Servers') %></strong> | ||
14 | -<div id='edit-server-list-block'> | ||
15 | - <ul class='link-list-header'> | ||
16 | - <li class='link-list-name'><%= _('DSpace URL') %></li> | ||
17 | - </ul> | ||
18 | - <ul id="dropable-server-list"> | ||
19 | - <%= render :partial => 'server_list_item', :collection=>@settings.dspace_servers %> | ||
20 | - </ul> | ||
21 | - <div id="new-template"> | ||
22 | - <% template_server = {'icon' => 'ok'} %> | ||
23 | - <%= render :partial => 'server_list_item', :locals => {:dspace_uri => "http://" } %> | 12 | + <BR> |
13 | + | ||
14 | +<div class="dspace-servers-config-box" > | ||
15 | + | ||
16 | + <strong><%= _('Dspace Servers\' URL:') %></strong> | ||
17 | + <div id='edit-server-list-block'> | ||
18 | + <div id="dropable-server-list"> | ||
19 | + <%= render :partial => 'server_list_item', :collection=>@settings.dspace_servers %> | ||
20 | + </div> | ||
21 | + <div id="dspace-new-template"> | ||
22 | + <div > | ||
23 | + <%= render :partial => 'server_list_item', :locals => {:dspace_uri => "http://"} %> | ||
24 | + </div> | ||
24 | </div> | 25 | </div> |
25 | -</div> | ||
26 | - | ||
27 | -<%= link_to_function(_('New Dspace Server'), 'add_new_server();', :class => 'button icon-add with-text') %> | ||
28 | - | 26 | + <%= link_to_function(_('New Dspace Server'), 'add_new_server();', :class => 'button icon-add with-text') %> |
27 | + </div> | ||
28 | +</div> | ||
29 | <% button_bar do %> | 29 | <% button_bar do %> |
30 | - <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> | 30 | + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> |
31 | + <% end %> | ||
31 | <% end %> | 32 | <% end %> |
32 | - | ||
33 | -<% end %> | ||
34 | - | ||
35 | - | ||
36 | - | ||
37 | - | ||
38 | - | ||
39 | - | ||
40 | -<hr/> | ||
41 | <div class="harvest"> | 33 | <div class="harvest"> |
42 | <% if @settings.last_harvest %> | 34 | <% if @settings.last_harvest %> |
43 | <div class="date"> | 35 | <div class="date"> |
@@ -54,9 +46,7 @@ | @@ -54,9 +46,7 @@ | ||
54 | <% end %> | 46 | <% end %> |
55 | </div> | 47 | </div> |
56 | </div> | 48 | </div> |
57 | - | ||
58 | <hr /> | 49 | <hr /> |
59 | - | ||
60 | <div class="triple-management"> | 50 | <div class="triple-management"> |
61 | <div class="actions"> | 51 | <div class="actions"> |
62 | <%= button :edit, _('Triple management'), :action => :triple_management %> | 52 | <%= button :edit, _('Triple management'), :action => :triple_management %> |