Commit 6698b64c55f82cfab1c9351d84273473a1d72a7b

Authored by Victor Costa
2 parents ca63fd93 2bd1be30

Merge branch 'virtuoso_integration' of gitlab.com:participa/noosfero into virtuoso_integration

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 @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) 8 @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings)
7 @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present? 9 @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present?
8 -  
9 if request.post? 10 if request.post?
  11 + settings[:dspace_servers].delete_if do | server |
  12 + server[:dspace_uri].empty?
  13 + end
10 @settings.save! 14 @settings.save!
11 session[:notice] = 'Settings successfully saved.' 15 session[:notice] = 'Settings successfully saved.'
12 redirect_to :action => 'index' 16 redirect_to :action => 'index'
@@ -14,8 +18,7 @@ class VirtuosoPluginAdminController &lt; AdminController @@ -14,8 +18,7 @@ class VirtuosoPluginAdminController &lt; AdminController
14 end 18 end
15 19
16 def force_harvest 20 def force_harvest
17 - harvest = VirtuosoPlugin::DspaceHarvest.new(environment)  
18 - harvest.start(params[:from_start]) 21 + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, params[:from_start])
19 session[:notice] = _('Harvest started') 22 session[:notice] = _('Harvest started')
20 redirect_to :action => :index 23 redirect_to :action => :index
21 end 24 end
plugins/virtuoso/lib/virtuoso_plugin.rb
1 class VirtuosoPlugin < Noosfero::Plugin 1 class VirtuosoPlugin < Noosfero::Plugin
2 2
  3 + @virtuosoServers
  4 +
3 def self.plugin_name 5 def self.plugin_name
4 "Virtuoso integration" 6 "Virtuoso integration"
5 end 7 end
@@ -24,10 +26,6 @@ class VirtuosoPlugin &lt; Noosfero::Plugin @@ -24,10 +26,6 @@ class VirtuosoPlugin &lt; Noosfero::Plugin
24 @virtuoso_readonly_client ||= virtuoso_client_builder(settings.virtuoso_uri, settings.virtuoso_readonly_username, settings.virtuoso_readonly_password) 26 @virtuoso_readonly_client ||= virtuoso_client_builder(settings.virtuoso_uri, settings.virtuoso_readonly_username, settings.virtuoso_readonly_password)
25 end 27 end
26 28
27 - def js_files  
28 - ['edit-server-list']  
29 - end  
30 -  
31 def stylesheet? 29 def stylesheet?
32 true 30 true
33 end 31 end
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
@@ -29,3 +29,4 @@ @@ -29,3 +29,4 @@
29 #virtuoso-triples-management #triples-list .triple-actions { 29 #virtuoso-triples-management #triples-list .triple-actions {
30 text-align: right; 30 text-align: right;
31 } 31 }
  32 +
plugins/virtuoso/public/virtuoso_plugin_admin.css 0 → 100644
@@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
  1 +.dspace-servers-config-box{
  2 + border: 1px solid gray;
  3 + padding: 5px;
  4 +}
  5 +
  6 +#dspace-new-template{
  7 + display: none;
  8 +}
0 \ No newline at end of file 9 \ No newline at end of file
plugins/virtuoso/views/virtuoso_plugin_admin/_server_list_item.html.erb 0 → 100644
@@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
  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 Admin Username:'), f.text_field(:virtuoso_username) %> 9 <%= labelled_form_field _('Virtuoso Admin Username:'), f.text_field(:virtuoso_username) %>
@@ -12,14 +12,26 @@ @@ -12,14 +12,26 @@
12 <%= labelled_form_field _('Virtuoso Read-Only Password:'), f.password_field(:virtuoso_readonly_password) %> 12 <%= labelled_form_field _('Virtuoso Read-Only Password:'), f.password_field(:virtuoso_readonly_password) %>
13 <%= labelled_form_field _('DSpace URL:'), f.text_field(:dspace_uri) %> 13 <%= labelled_form_field _('DSpace URL:'), f.text_field(:dspace_uri) %>
14 </strong> 14 </strong>
15 - 15 + <BR>
  16 +<div class="dspace-servers-config-box" >
  17 +
  18 + <strong><%= _('Dspace Servers\' URL:') %></strong>
  19 + <div id='edit-server-list-block'>
  20 + <div id="dropable-server-list">
  21 + <%= render :partial => 'server_list_item', :collection=>@settings.dspace_servers %>
  22 + </div>
  23 + <div id="dspace-new-template">
  24 + <div >
  25 + <%= render :partial => 'server_list_item', :locals => {:dspace_uri => "http://"} %>
  26 + </div>
  27 + </div>
  28 + <%= link_to_function(_('New Dspace Server'), 'add_new_server();', :class => 'button icon-add with-text') %>
  29 + </div>
  30 +</div>
16 <% button_bar do %> 31 <% button_bar do %>
17 - <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> 32 + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
  33 + <% end %>
18 <% end %> 34 <% end %>
19 -  
20 -<% end %>  
21 -  
22 -<hr/>  
23 <div class="harvest"> 35 <div class="harvest">
24 <% if @settings.last_harvest %> 36 <% if @settings.last_harvest %>
25 <div class="date"> 37 <div class="date">
@@ -36,9 +48,7 @@ @@ -36,9 +48,7 @@
36 <% end %> 48 <% end %>
37 </div> 49 </div>
38 </div> 50 </div>
39 -  
40 <hr /> 51 <hr />
41 -  
42 <div class="triple-management"> 52 <div class="triple-management">
43 <div class="actions"> 53 <div class="actions">
44 <%= button :edit, _('Triples management'), :action => :triples_management %> 54 <%= button :edit, _('Triples management'), :action => :triples_management %>