Commit e04a0099beb7b9e2fa85b610ab8043ee0b212d2c
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'virtuoso_integration' into production
* virtuoso_integration: changed time_ago_as_sentence to time_ago_in_words fixed display last_harvest fix problema creating job fix saving last_harvest to settings test fixed test fixed new unit test save_harvest_time at the end of a harverst
Showing
6 changed files
with
136 additions
and
26 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
| ... | ... | @@ -60,14 +60,14 @@ class VirtuosoPlugin::DspaceHarvest |
| 60 | 60 | raise ex |
| 61 | 61 | end |
| 62 | 62 | end |
| 63 | + save_harvest_time_settings(harvest_time) | |
| 63 | 64 | puts "ending harvest #{harvest_time}" |
| 64 | 65 | end |
| 65 | 66 | |
| 66 | 67 | def save_harvest_time_settings(harvest_time) |
| 67 | - dspace_settings = {"dspace_uri" => dspace_uri, "last_harvest" => last_harvest} | |
| 68 | 68 | settings.dspace_servers.each do |s| |
| 69 | 69 | if s["dspace_uri"] == dspace_uri |
| 70 | - settings.dspace_servers.delete(dspace_settings) | |
| 70 | + settings.dspace_servers.delete(s) | |
| 71 | 71 | end |
| 72 | 72 | end |
| 73 | 73 | @dspace_settings = {"dspace_uri" => dspace_uri, "last_harvest" => harvest_time} |
| ... | ... | @@ -102,8 +102,8 @@ class VirtuosoPlugin::DspaceHarvest |
| 102 | 102 | |
| 103 | 103 | class Job < Struct.new(:environment_id, :dspace_uri) |
| 104 | 104 | def perform |
| 105 | - environment = Environment.find(environment_id, dspace_uri) | |
| 106 | - harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri" => dspace_uri, "last_harvest" => last_harvest}) | |
| 105 | + environment = Environment.find(environment_id) | |
| 106 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri" => dspace_uri}) | |
| 107 | 107 | harvest.run |
| 108 | 108 | end |
| 109 | 109 | end | ... | ... |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +#require File.dirname(__FILE__) + '/../test_helper.rb' | |
| 2 | +# | |
| 3 | +#class DspaceTest < ActiveSupport::TestCase | |
| 4 | +# | |
| 5 | +# def setup | |
| 6 | +# @environment = Environment.default | |
| 7 | +# end | |
| 8 | +# | |
| 9 | +# attr_reader :environment | |
| 10 | +# | |
| 11 | +# should 'list at least one record' do | |
| 12 | +# settings = | |
| 13 | +# { :virtuoso_uri=>"http://hom.virtuoso.participa.br", | |
| 14 | +# :virtuoso_username=>"dba", | |
| 15 | +# :virtuoso_password=>"dba", | |
| 16 | +# :virtuoso_readonly_username=>"dba", | |
| 17 | +# :virtuoso_readonly_password=>"dba", | |
| 18 | +# :dspace_servers=>[ | |
| 19 | +# {"dspace_uri"=>"http://hom.dspace.participa.br"} | |
| 20 | +# ] | |
| 21 | +# } | |
| 22 | +# settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | |
| 23 | +# harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://hom.dspace.participa.br"}) | |
| 24 | +# params = harvest.last_harvest ? {:from => harvest.last_harvest.utc} : {} | |
| 25 | +# records = harvest.dspace_client.list_records(params) | |
| 26 | +# assert_not_equal records.count, 0 | |
| 27 | +# end | |
| 28 | +#end | |
| 0 | 29 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,33 @@ |
| 1 | +#require File.dirname(__FILE__) + '/../test_helper.rb' | |
| 2 | +# | |
| 3 | +#class DspaceTest < ActiveSupport::TestCase | |
| 4 | +# | |
| 5 | +# def setup | |
| 6 | +# @environment = Environment.default | |
| 7 | +# end | |
| 8 | +# | |
| 9 | +# attr_reader :environment | |
| 10 | +# | |
| 11 | +# | |
| 12 | +# should 'update last_harvest after harvert' do | |
| 13 | +# time = Time.now.utc | |
| 14 | +# settings = | |
| 15 | +# { :virtuoso_uri=>"http://hom.virtuoso.participa.br", | |
| 16 | +# :virtuoso_username=>"dba", | |
| 17 | +# :virtuoso_password=>"dba", | |
| 18 | +# :virtuoso_readonly_username=>"dba", | |
| 19 | +# :virtuoso_readonly_password=>"dba", | |
| 20 | +# :dspace_servers=>[ | |
| 21 | +# {"dspace_uri"=>"http://hom.dspace.participa.br"} | |
| 22 | +# ] | |
| 23 | +# } | |
| 24 | +# @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | |
| 25 | +# harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://hom.dspace.participa.br" }) | |
| 26 | +# harvest.run | |
| 27 | +# assert_not_equal harvest.last_harvest, nil | |
| 28 | +# Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
| 29 | +# assert_not_equal harvest.last_harvest, nil | |
| 30 | +# assert_not_equal harvest.last_harvest, Time.now.utc | |
| 31 | +# end | |
| 32 | +# | |
| 33 | +#end | |
| 0 | 34 | \ No newline at end of file | ... | ... |
plugins/virtuoso/test/unit/dspace_harvest_test.rb
| 1 | -require File.dirname(__FILE__) + '/../test_helper' | |
| 1 | +require File.dirname(__FILE__) + '/../test_helper.rb' | |
| 2 | 2 | |
| 3 | 3 | class DspaceHarvestTest < ActiveSupport::TestCase |
| 4 | 4 | |
| ... | ... | @@ -15,11 +15,11 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
| 15 | 15 | :virtuoso_readonly_username=>"readonly_username", |
| 16 | 16 | :virtuoso_readonly_password=>"readonly_password", |
| 17 | 17 | :dspace_servers=>[ |
| 18 | - {"dspace_uri"=>"http://dspace1.noosfero.com","last_harvest" => 5 }, | |
| 18 | + {"dspace_uri"=>"http://dspace1.noosfero.com","last_harvest" => Time.now.utc }, | |
| 19 | 19 | {"dspace_uri"=>"http://dspace2.noosfero.com"}, |
| 20 | - {"dspace_uri"=>"http://dspace3.noosfero.com", "last_harvest" => 0}, | |
| 20 | + {"dspace_uri"=>"http://dspace3.noosfero.com", "last_harvest" => Time.now.utc}, | |
| 21 | 21 | {"dspace_uri"=>"http://dspace4.noosfero.com", "last_harvest" => nil}, |
| 22 | - {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9}, | |
| 22 | + {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => Time.now.utc}, | |
| 23 | 23 | ] |
| 24 | 24 | } |
| 25 | 25 | end |
| ... | ... | @@ -36,17 +36,21 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | 38 | should 'save_harvest_time_settings' do |
| 39 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 39 | + Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 40 | 40 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace5.noosfero.com", "last_harvest" => 9}) |
| 41 | 41 | assert harvest.last_harvest, 9 |
| 42 | 42 | harvest.save_harvest_time_settings(10) |
| 43 | - @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
| 44 | 43 | assert harvest.last_harvest, 10 |
| 44 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin) | |
| 45 | + dspace_server = settings.dspace_servers[4] | |
| 46 | + settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
| 47 | + dspace_server = settings.dspace_servers[4] | |
| 48 | + assert_equal 10, dspace_server["last_harvest"] | |
| 45 | 49 | end |
| 46 | 50 | |
| 47 | 51 | should 'create delayed job when start' do |
| 48 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 49 | - @settings.save! | |
| 52 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 53 | + settings.save! | |
| 50 | 54 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) |
| 51 | 55 | assert !harvest.find_job.present? |
| 52 | 56 | harvest.start |
| ... | ... | @@ -54,8 +58,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
| 54 | 58 | end |
| 55 | 59 | |
| 56 | 60 | should 'not duplicate harvest job' do |
| 57 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 58 | - @settings.save! | |
| 61 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 62 | + settings.save! | |
| 59 | 63 | harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace1.noosfero.com", "last_harvest" => 5}) |
| 60 | 64 | assert_difference "harvest.find_job.count", 1 do |
| 61 | 65 | 5.times { harvest.start } |
| ... | ... | @@ -67,8 +71,8 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
| 67 | 71 | end |
| 68 | 72 | |
| 69 | 73 | should 'try to harvest all dspaces from start with mock configuration' do |
| 70 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 71 | - @settings.save! | |
| 74 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 75 | + settings.save! | |
| 72 | 76 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, true) |
| 73 | 77 | end |
| 74 | 78 | |
| ... | ... | @@ -77,9 +81,50 @@ class DspaceHarvestTest < ActiveSupport::TestCase |
| 77 | 81 | end |
| 78 | 82 | |
| 79 | 83 | should 'try to harvest all dspaces with mock configuration' do |
| 80 | - @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 81 | - @settings.save! | |
| 84 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, mock_settings) | |
| 85 | + settings.save! | |
| 82 | 86 | VirtuosoPlugin::DspaceHarvest.harvest_all(environment, false) |
| 83 | 87 | end |
| 84 | 88 | |
| 85 | -end | |
| 89 | + should 'update last_harvest after harvert' do | |
| 90 | + time = Time.now.utc | |
| 91 | + settings = | |
| 92 | + { :virtuoso_uri=>"http://virtuoso", | |
| 93 | + :virtuoso_username=>"username", | |
| 94 | + :virtuoso_password=>"password", | |
| 95 | + :virtuoso_readonly_username=>"username", | |
| 96 | + :virtuoso_readonly_password=>"password", | |
| 97 | + :dspace_servers=>[ | |
| 98 | + {"dspace_uri"=>"http://dspace","last_harvest" => time } | |
| 99 | + ] | |
| 100 | + } | |
| 101 | + @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | |
| 102 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://dspace" }) | |
| 103 | + dspace_client = mock | |
| 104 | + harvest.expects(:dspace_client).returns(dspace_client) | |
| 105 | + dspace_client.expects(:list_records).returns([]) | |
| 106 | + harvest.run | |
| 107 | + assert_not_equal harvest.last_harvest, nil | |
| 108 | + Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin) | |
| 109 | + assert_not_equal harvest.last_harvest, nil | |
| 110 | + assert_not_equal harvest.last_harvest, Time.now.utc | |
| 111 | + end | |
| 112 | + | |
| 113 | + should 'list records' do | |
| 114 | + settings = | |
| 115 | + { :virtuoso_uri=>"http://hom.virtuoso.participa.br", | |
| 116 | + :virtuoso_username=>"dba", | |
| 117 | + :virtuoso_password=>"dba", | |
| 118 | + :virtuoso_readonly_username=>"dba", | |
| 119 | + :virtuoso_readonly_password=>"dba", | |
| 120 | + :dspace_servers=>[ | |
| 121 | + {"dspace_uri"=>"http://hom.dspace.participa.br"} | |
| 122 | + ] | |
| 123 | + } | |
| 124 | + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings) | |
| 125 | + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, {"dspace_uri"=>"http://hom.dspace.participa.br"}) | |
| 126 | + params = harvest.last_harvest ? {:from => harvest.last_harvest.utc} : {} | |
| 127 | + records = harvest.dspace_client.list_records(params) | |
| 128 | + assert_not_equal records.count, 0 | |
| 129 | + end | |
| 130 | +end | |
| 86 | 131 | \ No newline at end of file | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/_server_list_item.html.erb
| 1 | 1 | <div> |
| 2 | - <% value = server_list_item[:dspace_uri] if server_list_item %> | |
| 2 | + <% | |
| 3 | + | |
| 4 | + value = server_list_item[:dspace_uri] if server_list_item %> | |
| 3 | 5 | <%= text_field_tag 'settings[dspace_servers][][dspace_uri]', value, { :class => 'link-name', :maxlength => 60, :size=> 58 } %> |
| 4 | 6 | <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-server-list-row") %> |
| 5 | - <% last_execution = server_list_item[:last_harvest] if server_list_item | |
| 6 | - if last_execution %> | |
| 7 | + | |
| 8 | + <% | |
| 9 | + last_execution = server_list_item["last_harvest"] if server_list_item | |
| 10 | + if last_execution | |
| 11 | + %> | |
| 7 | 12 | <div class="date" style="display: inline-block;"> |
| 8 | 13 | <span class="label"><strong><%= _('Last execution:') %></strong></span> |
| 9 | - <span class="value"><%= time_ago_as_sentence last_execution %></span> | |
| 14 | + <span class="value"><%= time_ago_in_words last_execution %></span> | |
| 10 | 15 | </div> |
| 11 | 16 | <% end %> |
| 12 | 17 | <BR><BR> |
| 13 | 18 | </div> |
| 14 | - | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/index.html.erb
| ... | ... | @@ -7,9 +7,9 @@ |
| 7 | 7 | <strong> |
| 8 | 8 | <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri, :size=> 60) %> |
| 9 | 9 | <%= labelled_form_field _('Virtuoso Admin Username:'), f.text_field(:virtuoso_username, :size=> 60) %> |
| 10 | - <%= labelled_form_field _('Virtuoso Admin Password:'), f.password_field(:virtuoso_password, :size=> 60) %> | |
| 10 | + <%= labelled_form_field _('Virtuoso Admin Password:'), f.password_field(:virtuoso_password, :size=> 60, value: @settings.virtuoso_password) %> | |
| 11 | 11 | <%= labelled_form_field _('Virtuoso Read-Only Username:'), f.text_field(:virtuoso_readonly_username, :size=> 60) %> |
| 12 | - <%= labelled_form_field _('Virtuoso Read-Only Password:'), f.password_field(:virtuoso_readonly_password, :size=> 60) %> | |
| 12 | + <%= labelled_form_field _('Virtuoso Read-Only Password:'), f.password_field(:virtuoso_readonly_password, :size=> 60, value: @settings.virtuoso_readonly_password) %> | |
| 13 | 13 | </strong> |
| 14 | 14 | <BR> |
| 15 | 15 | <div class="dspace-servers-config-box" > | ... | ... |