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 1 class VirtuosoPluginAdminController < AdminController
2 2  
  3 + #validates :dspace_servers, presence: true
  4 +
3 5 def index
4   - settings = params[:settings]
  6 + settings = params[:settings]
5 7 settings ||= {}
6 8 @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings)
7 9 @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present?
8   -
9 10 if request.post?
  11 + settings[:dspace_servers].delete_if do | server |
  12 + server[:dspace_uri].empty?
  13 + end
10 14 @settings.save!
11 15 session[:notice] = 'Settings successfully saved.'
12 16 redirect_to :action => 'index'
... ... @@ -14,8 +18,7 @@ class VirtuosoPluginAdminController &lt; AdminController
14 18 end
15 19  
16 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 22 session[:notice] = _('Harvest started')
20 23 redirect_to :action => :index
21 24 end
... ...
plugins/virtuoso/lib/virtuoso_plugin.rb
1 1 class VirtuosoPlugin < Noosfero::Plugin
2 2  
  3 + @virtuosoServers
  4 +
3 5 def self.plugin_name
4 6 "Virtuoso integration"
5 7 end
... ... @@ -24,10 +26,6 @@ class VirtuosoPlugin &lt; Noosfero::Plugin
24 26 @virtuoso_readonly_client ||= virtuoso_client_builder(settings.virtuoso_uri, settings.virtuoso_readonly_username, settings.virtuoso_readonly_password)
25 27 end
26 28  
27   - def js_files
28   - ['edit-server-list']
29   - end
30   -
31 29 def stylesheet?
32 30 true
33 31 end
... ...
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
... ... @@ -2,9 +2,10 @@
2 2 class VirtuosoPlugin::DspaceHarvest
3 3  
4 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 7 @environment = environment
  8 + @dspace_uri = dspace_uri
8 9 end
9 10  
10 11 attr_reader :environment
... ... @@ -16,7 +17,7 @@ class VirtuosoPlugin::DspaceHarvest
16 17 delegate :settings, :to => :plugin
17 18  
18 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 21 end
21 22  
22 23 def triplify(record)
... ... @@ -26,7 +27,7 @@ class VirtuosoPlugin::DspaceHarvest
26 27 DC_CONVERSION.each do |c|
27 28 values = [metadata.send(c)].flatten.compact
28 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 31 plugin.virtuoso_client.insert(query)
31 32 end
32 33 end
... ... @@ -35,7 +36,7 @@ class VirtuosoPlugin::DspaceHarvest
35 36 def run
36 37 harvest_time = Time.now.utc
37 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 40 begin
40 41 records = dspace_client.list_records(params)
41 42 records.each do |record|
... ... @@ -52,14 +53,22 @@ class VirtuosoPlugin::DspaceHarvest
52 53 settings.save!
53 54 puts "ending harvest #{harvest_time}"
54 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 66 def start(from_start = false)
57 67 if find_job.empty?
58 68 if from_start
59 69 settings.last_harvest = nil
60 70 settings.save!
61 71 end
62   -
63 72 job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id)
64 73 Delayed::Job.enqueue(job)
65 74 end
... ...
plugins/virtuoso/public/edit-server-list.js
... ... @@ -13,24 +13,21 @@ function send_ajax(source_url) {
13 13 }
14 14 });
15 15 },
16   -
17 16 minLength: 3
18 17 });
19 18 }
20 19  
21 20 function new_server_action(){
22 21 send_ajax(jQuery("#page_url").val());
23   -
24 22 jQuery(".delete-server-list-row").click(function(){
25   - jQuery(this).parent().parent().remove();
  23 + jQuery(this).parent().remove();
26 24 return false;
27 25 });
28   -
29 26 jQuery(document).scrollTop(jQuery('#dropable-server-list').scrollTop());
30 27 }
31 28  
32 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 31 new_server.show();
35 32 jQuery('#dropable-server-list').append(new_server);
36 33 new_server_action();
... ... @@ -39,8 +36,8 @@ function add_new_server() {
39 36 jQuery(document).ready(function(){
40 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 29 #virtuoso-triples-management #triples-list .triple-actions {
30 30 text-align: right;
31 31 }
  32 +
... ...
plugins/virtuoso/public/virtuoso_plugin_admin.css 0 → 100644
... ... @@ -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 9 \ No newline at end of file
... ...
plugins/virtuoso/views/virtuoso_plugin_admin/_server_list_item.html.erb 0 → 100644
... ... @@ -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 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 6 <%= form_for(:settings) do |f| %>
6   -
7 7 <strong>
8 8 <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri) %>
9 9 <%= labelled_form_field _('Virtuoso Admin Username:'), f.text_field(:virtuoso_username) %>
... ... @@ -12,14 +12,26 @@
12 12 <%= labelled_form_field _('Virtuoso Read-Only Password:'), f.password_field(:virtuoso_readonly_password) %>
13 13 <%= labelled_form_field _('DSpace URL:'), f.text_field(:dspace_uri) %>
14 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 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 34 <% end %>
19   -
20   -<% end %>
21   -
22   -<hr/>
23 35 <div class="harvest">
24 36 <% if @settings.last_harvest %>
25 37 <div class="date">
... ... @@ -36,9 +48,7 @@
36 48 <% end %>
37 49 </div>
38 50 </div>
39   -
40 51 <hr />
41   -
42 52 <div class="triple-management">
43 53 <div class="actions">
44 54 <%= button :edit, _('Triples management'), :action => :triples_management %>
... ...