Commit d1f2a38256105758863dc25b3661a2664f422477

Authored by Victor Costa
2 parents 996e4d6f 8f767e88

Merge branch 'virtuoso_integration' into stable

plugins/virtuoso/controllers/admin/virtuoso_plugin_ontology_mapping_controller.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class VirtuosoPluginOntologyMappingController < AdminController
  2 +
  3 + def index
  4 + @settings = VirtuosoPlugin.new(self).settings
  5 + if request.post?
  6 + @settings.ontology_mapping = params['ontology_mapping']
  7 + @settings.save!
  8 + session[:notice] = _('Saved!')
  9 + end
  10 + @ontology_mapping = @settings.ontology_mapping
  11 + end
  12 +
  13 +end
... ...
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
... ... @@ -5,8 +5,10 @@ class VirtuosoPluginAdminController &lt; AdminController
5 5 settings ||= {}
6 6 @settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin, settings)
7 7 @harvest_running = VirtuosoPlugin::DspaceHarvest.new(environment).find_job.present?
8   -
9 8 if request.post?
  9 + settings[:dspace_servers].delete_if do | server |
  10 + server[:dspace_uri].empty?
  11 + end
10 12 @settings.save!
11 13 session[:notice] = 'Settings successfully saved.'
12 14 redirect_to :action => 'index'
... ... @@ -14,13 +16,12 @@ class VirtuosoPluginAdminController &lt; AdminController
14 16 end
15 17  
16 18 def force_harvest
17   - harvest = VirtuosoPlugin::DspaceHarvest.new(environment)
18   - harvest.start(params[:from_start])
  19 + VirtuosoPlugin::DspaceHarvest.harvest_all(environment, params[:from_start])
19 20 session[:notice] = _('Harvest started')
20 21 redirect_to :action => :index
21 22 end
22 23  
23   - def triple_management
  24 + def triples_management
24 25 triples_management = VirtuosoPlugin::TriplesManagement.new(environment)
25 26 @triples = []
26 27 if request.post?
... ... @@ -45,4 +46,33 @@ class VirtuosoPluginAdminController &lt; AdminController
45 46 redirect_to :action => :triple_management
46 47 end
47 48  
  49 + def add_triple
  50 + if request.post?
  51 +
  52 + triple = VirtuosoPlugin::Triple.new
  53 + triple.graph = params[:triple][:graph]
  54 + triple.subject = params[:triple][:subject]
  55 + triple.predicate = params[:triple][:predicate]
  56 + triple.object = params[:triple][:object]
  57 +
  58 + triples_management = VirtuosoPlugin::TriplesManagement.new(environment)
  59 + triples_management.add_triple(triple)
  60 +
  61 + render json: { :ok => true, :message => _('Triple succesfully added.') }
  62 + end
  63 + end
  64 +
  65 + def remove_triple
  66 + triple = VirtuosoPlugin::Triple.new
  67 + triple.graph = params[:triple][:graph]
  68 + triple.subject = params[:triple][:subject]
  69 + triple.predicate = params[:triple][:predicate]
  70 + triple.object = params[:triple][:object]
  71 +
  72 + triples_management = VirtuosoPlugin::TriplesManagement.new(environment)
  73 + triples_management.remove_triple(triple)
  74 +
  75 + render json: { :ok => true, :message => _('Triple succesfully removed.') }
  76 + end
  77 +
48 78 end
... ...
plugins/virtuoso/lib/virtuoso_plugin.rb
... ... @@ -24,14 +24,16 @@ class VirtuosoPlugin &lt; Noosfero::Plugin
24 24 @virtuoso_readonly_client ||= virtuoso_client_builder(settings.virtuoso_uri, settings.virtuoso_readonly_username, settings.virtuoso_readonly_password)
25 25 end
26 26  
27   - def js_files
28   - ['edit-server-list']
29   - end
30   -
31 27 def stylesheet?
32 28 true
33 29 end
34 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 +
35 37 protected
36 38  
37 39 def virtuoso_client_builder(uri, username, password)
... ...
plugins/virtuoso/lib/virtuoso_plugin/dspace_harvest.rb
1 1 #inspired by https://github.com/code4lib/ruby-oai/blob/master/lib/oai/harvester/harvest.rb
2 2 class VirtuosoPlugin::DspaceHarvest
3 3  
4   - DC_CONVERSION = [:title, :creator, :subject, :description, :date, :type, :identifier, :language, :rights, :format]
5   -
6   - def initialize(environment)
  4 + def initialize(environment, dspace_uri = nil)
7 5 @environment = environment
  6 + @dspace_uri = dspace_uri
8 7 end
9 8  
10 9 attr_reader :environment
... ... @@ -16,17 +15,18 @@ class VirtuosoPlugin::DspaceHarvest
16 15 delegate :settings, :to => :plugin
17 16  
18 17 def dspace_client
19   - @dspace_client ||= OAI::Client.new("#{settings.dspace_uri}/oai/request")
  18 + @dspace_client ||= OAI::Client.new("#{@dspace_uri}/oai/request")
20 19 end
21 20  
22 21 def triplify(record)
23 22 metadata = VirtuosoPlugin::DublinCoreMetadata.new(record.metadata)
24   - puts "triplify #{record.header.identifier}"
  23 + subject_identifier = extract_identifier(record)
  24 + puts "triplify #{subject_identifier}"
25 25  
26   - DC_CONVERSION.each do |c|
27   - values = [metadata.send(c)].flatten.compact
  26 + settings.ontology_mapping.each do |mapping|
  27 + values = [metadata.extract_field(mapping[:source])].flatten.compact
28 28 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))
  29 + query = RDF::Virtuoso::Query.insert_data([RDF::URI.new(subject_identifier), RDF::URI.new(mapping[:target]), value]).graph(RDF::URI.new(@dspace_uri))
30 30 plugin.virtuoso_client.insert(query)
31 31 end
32 32 end
... ... @@ -35,7 +35,7 @@ class VirtuosoPlugin::DspaceHarvest
35 35 def run
36 36 harvest_time = Time.now.utc
37 37 params = settings.last_harvest ? {:from => settings.last_harvest.utc} : {}
38   - puts "starting harvest #{params} #{settings.dspace_uri} #{settings.virtuoso_uri}"
  38 + puts "starting harvest #{params} #{@dspace_uri} #{settings.virtuoso_uri}"
39 39 begin
40 40 records = dspace_client.list_records(params)
41 41 records.each do |record|
... ... @@ -53,28 +53,42 @@ class VirtuosoPlugin::DspaceHarvest
53 53 puts "ending harvest #{harvest_time}"
54 54 end
55 55  
  56 + def self.harvest_all(environment, from_start)
  57 + settings = Noosfero::Plugin::Settings.new(environment, VirtuosoPlugin)
  58 + settings.dspace_servers.each do |k, v|
  59 + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, k[:dspace_uri])
  60 + harvest.start(from_start)
  61 + end
  62 + end
  63 +
56 64 def start(from_start = false)
57 65 if find_job.empty?
58 66 if from_start
59 67 settings.last_harvest = nil
60 68 settings.save!
61 69 end
62   -
63   - job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id)
  70 + job = VirtuosoPlugin::DspaceHarvest::Job.new(@environment.id, @dspace_uri)
64 71 Delayed::Job.enqueue(job)
65 72 end
66 73 end
67 74  
68 75 def find_job
69   - Delayed::Job.where(:handler => "--- !ruby/struct:VirtuosoPlugin::DspaceHarvest::Job\nenvironment_id: #{@environment.id}\n")
  76 + Delayed::Job.where(:handler => "--- !ruby/struct:VirtuosoPlugin::DspaceHarvest::Job\nenvironment_id: #{@environment.id}\ndspace_uri: #{@dspace_uri}\n")
70 77 end
71 78  
72   - class Job < Struct.new(:environment_id)
  79 + class Job < Struct.new(:environment_id, :dspace_uri)
73 80 def perform
74 81 environment = Environment.find(environment_id)
75   - harvest = VirtuosoPlugin::DspaceHarvest.new(environment)
  82 + harvest = VirtuosoPlugin::DspaceHarvest.new(environment, dspace_uri)
76 83 harvest.run
77 84 end
78 85 end
79 86  
  87 + protected
  88 +
  89 + def extract_identifier(record)
  90 + parsed_identifier = /oai:(.+):(\d+\/\d+)/.match(record.header.identifier)
  91 + "#{@dspace_uri}/handle/#{parsed_identifier[2]}"
  92 + end
  93 +
80 94 end
... ...
plugins/virtuoso/lib/virtuoso_plugin/dublin_core_metadata.rb
... ... @@ -2,19 +2,27 @@ class VirtuosoPlugin::DublinCoreMetadata
2 2  
3 3 include OAI::XPath
4 4  
5   - attr_accessor :date, :title, :creator, :subject, :description, :date, :type, :identifier, :language, :rights, :format
  5 + FIELDS = ['title', 'creator', 'subject', 'description', 'date',
  6 + 'type', 'identifier', 'language', 'rights', 'format']
6 7  
7 8 def initialize(element)
8   - @title = xpath(element, './/dc:title')
9   - @creator = xpath(element, './/dc:creator')
10   - @subject = xpath_all(element, './/dc:subject').map(&:text)
11   - @description = xpath(element, './/dc:description')
12   - @date = xpath(element, './/dc:date')
13   - @type = xpath(element, './/dc:type')
14   - @identifier = xpath(element, './/dc:identifier')
15   - @language = xpath(element, './/dc:language')
16   - @rights = xpath_all(element, './/dc:rights').map(&:text)
17   - @format = xpath(element, './/dc:format')
  9 + @element = element
  10 + FIELDS.each do |field|
  11 + self.class.send(:attr_accessor, field)
  12 + self.send("#{field}=", extract_field("dc:#{field}"))
  13 + end
  14 + end
  15 +
  16 + def extract_field(name)
  17 + value = xpath_all(@element, ".//#{name}")
  18 + case value.size
  19 + when 0
  20 + nil
  21 + when 1
  22 + value.first.text
  23 + else
  24 + value.map(&:text)
  25 + end
18 26 end
19 27  
20 28 end
... ...
plugins/virtuoso/lib/virtuoso_plugin/triple.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class VirtuosoPlugin::Triple
  2 +
  3 + attr_accessor :graph, :subject, :predicate, :object
  4 +
  5 + def object=(value)
  6 + @object = format_triple_term(value)
  7 + end
  8 +
  9 + protected
  10 +
  11 + def format_triple_term(term)
  12 + term =~ /^(http|https):\/\// ? "<#{term}>" : "'#{term}'"
  13 + end
  14 +
  15 +end
  16 +
... ...
plugins/virtuoso/lib/virtuoso_plugin/triples_management.rb
... ... @@ -29,6 +29,16 @@ class VirtuosoPlugin::TriplesManagement
29 29 plugin.virtuoso_client.query(query)
30 30 end
31 31  
  32 + def add_triple(triple)
  33 + query = "WITH <#{triple.graph}> INSERT { <#{triple.subject}> <#{triple.predicate}> #{triple.object} }"
  34 + plugin.virtuoso_client.query(query)
  35 + end
  36 +
  37 + def remove_triple(triple)
  38 + query = "WITH <#{triple.graph}> DELETE { <#{triple.subject}> <#{triple.predicate}> #{triple.object} }"
  39 + plugin.virtuoso_client.query(query)
  40 + end
  41 +
32 42 protected
33 43  
34 44 def format_triple_term(term)
... ...
plugins/virtuoso/lib/virtuoso_plugin/triples_template.rb
... ... @@ -21,6 +21,7 @@ class VirtuosoPlugin::TriplesTemplate &lt; Article
21 21 settings_items :query, :type => :string
22 22 settings_items :template, :type => :string, :default => initial_template
23 23 settings_items :stylesheet, :type => :string
  24 + settings_items :per_page, :type => :integer, :default => 50
24 25  
25 26 attr_accessible :query, :template, :stylesheet
26 27  
... ... @@ -35,12 +36,12 @@ class VirtuosoPlugin::TriplesTemplate &lt; Article
35 36 @plugin ||= VirtuosoPlugin.new(self)
36 37 end
37 38  
38   - def template_content
  39 + def template_content(page=1)
39 40 begin
40   - results = plugin.virtuoso_readonly_client.query(query)
  41 + results = plugin.virtuoso_readonly_client.query(query).paginate({:per_page => per_page, :page => page})
41 42 liquid_template = Liquid::Template.parse(template)
42   - page = liquid_template.render('results' => results)
43   - transform_html(page)
  43 + rendered_template = liquid_template.render('results' => results)
  44 + transform_html(rendered_template)
44 45 rescue => ex
45 46 logger.info ex.to_s
46 47 "Failed to process the template"
... ...
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/ontology_mapping.js 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +jQuery(document).ready(function($) {
  2 +
  3 + $('#new-ontology-button').on('click', function() {
  4 + $('#ontology-table').append($('#ontology-item-template tr').clone());
  5 + });
  6 +
  7 + $('#ontology-table').on('click', '.remove-ontology-button', function() {
  8 + $(this).parents('tr').remove();
  9 + });
  10 +
  11 +});
... ...
plugins/virtuoso/public/style.css
... ... @@ -2,7 +2,8 @@
2 2 margin: 10px 0;
3 3 }
4 4  
5   -#virtuoso-triples-management input[type="text"] {
  5 +#virtuoso-triples-management input[type="text"],
  6 +#virtuoso-triples-management-add-triple input[type="text"] {
6 7 width: 100%
7 8 }
8 9  
... ... @@ -10,7 +11,8 @@
10 11 width: 99%;
11 12 }
12 13  
13   -#virtuoso-triples-management ul {
  14 +#virtuoso-triples-management ul,
  15 +#virtuoso-triples-management-add-triple ul {
14 16 list-style-type: none;
15 17 padding: 0;
16 18 }
... ... @@ -25,3 +27,12 @@
25 27 margin-top: 20px;
26 28 padding-top: 15px;
27 29 }
  30 +
  31 +#virtuoso-triples-management #triples-list .triple-actions {
  32 + text-align: right;
  33 +}
  34 +
  35 +#virtuoso-triples-management-add-triple {
  36 + width: 500px;
  37 + border: 1px solid white;
  38 +}
... ...
plugins/virtuoso/public/triples_management.js 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +function add_triple() {
  2 + graph = jQuery("input#triple_graph").val();
  3 + subject = jQuery("input#triple_subject").val();
  4 + predicate = jQuery("input#triple_predicate").val();
  5 + object = jQuery("input#triple_object").val();
  6 +
  7 + var formData = { triple: { graph: graph, subject: subject, predicate: predicate, object: object } }
  8 +
  9 + jQuery.ajax({
  10 + cache: false,
  11 + type: 'POST',
  12 + url: '/admin/plugin/virtuoso/add_triple',
  13 + data: formData,
  14 + dataType: 'json',
  15 + success: function(data, status, ajax){
  16 + if ( !data.ok ) {
  17 + display_notice(data.error.message);
  18 + jQuery.colorbox.close();
  19 + }
  20 + else {
  21 + display_notice(data.message);
  22 + jQuery.colorbox.close();
  23 + }
  24 + },
  25 + error: function(ajax, status, errorThrown) {
  26 + alert('Send request - HTTP '+status+': '+errorThrown);
  27 + }
  28 + });
  29 +
  30 + return false;
  31 +}
  32 +
  33 +function remove_triple(triple_id) {
  34 + graph = jQuery("input#graph_uri").val();
  35 + subject = jQuery("input#triples_triple" + triple_id + "_from_subject").val();
  36 + predicate = jQuery("input#triples_triple" + triple_id + "_from_predicate").val();
  37 + object = jQuery("input#triples_triple" + triple_id + "_from_object").val();
  38 +
  39 + var formData = { triple: { graph: graph, subject: subject, predicate: predicate, object: object } }
  40 +
  41 + jQuery.ajax({
  42 + cache: false,
  43 + type: 'POST',
  44 + url: '/admin/plugin/virtuoso/remove_triple',
  45 + data: formData,
  46 + dataType: 'json',
  47 + success: function(data, status, ajax){
  48 + if ( !data.ok ) {
  49 + display_notice(data.error.message);
  50 + }
  51 + else {
  52 + display_notice(data.message);
  53 + jQuery("li#triple-" + triple_id).fadeOut(700, function() {
  54 + if (jQuery("ul#triples-list > li").length == 1) {
  55 + jQuery("form#form-triples-edit").remove();
  56 + }
  57 + else {
  58 + jQuery("li#triple-" + triple_id).remove();
  59 + }
  60 + });
  61 + }
  62 + },
  63 + error: function(ajax, status, errorThrown) {
  64 + alert('Send request - HTTP '+status+': '+errorThrown);
  65 + }
  66 + });
  67 +
  68 + return false;
  69 +}
... ...
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/test/functional/virtuoso_plugin_admin_controller_test.rb
... ... @@ -9,17 +9,26 @@ class VirtuosoPluginAdminControllerTest &lt; ActionController::TestCase
9 9 end
10 10  
11 11 attr_reader :environment
12   -
  12 +
13 13 should 'save virtuoso plugin settings' do
14   - post :index, :settings => {'virtuoso_uri' => 'http://virtuoso.noosfero.com',
15   - 'virtuoso_username' => 'username',
16   - 'virtuoso_password' => 'password',
17   - 'dspace_uri' => 'http://dspace.noosfero.com'}
  14 + post :index, :settings =>
  15 + {:virtuoso_uri=>"http://virtuoso.noosfero.com",
  16 + :virtuoso_username=>"username", :virtuoso_password=>"password",
  17 + :virtuoso_readonly_username=>"password",
  18 + :virtuoso_readonly_password=>"password",
  19 + :dspace_servers=>[
  20 + {"dspace_uri"=>"http://dspace1.noosfero.com"},
  21 + {"dspace_uri"=>"http://dspace2.noosfero.com"},
  22 + {"dspace_uri"=>"http://dspace3.noosfero.com"}
  23 + ]
  24 + }
18 25 @settings = Noosfero::Plugin::Settings.new(environment.reload, VirtuosoPlugin)
19 26 assert_equal 'http://virtuoso.noosfero.com', @settings.settings[:virtuoso_uri]
20 27 assert_equal 'username', @settings.settings[:virtuoso_username]
21 28 assert_equal 'password', @settings.settings[:virtuoso_password]
22   - assert_equal 'http://dspace.noosfero.com', @settings.settings[:dspace_uri]
  29 + assert_equal 'http://dspace1.noosfero.com', @settings.settings[:dspace_servers][0][:dspace_uri]
  30 + assert_equal 'http://dspace2.noosfero.com', @settings.settings[:dspace_servers][1][:dspace_uri]
  31 + assert_equal 'http://dspace3.noosfero.com', @settings.settings[:dspace_servers][2][:dspace_uri]
23 32 assert_redirected_to :action => 'index'
24 33 end
25 34  
... ...
plugins/virtuoso/test/functional/virtuoso_plugin_ontology_mapping_controller.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require 'test_helper'
  2 +
  3 +class VirtuosoPluginOntologyMappingControllerTest < ActionController::TestCase
  4 +
  5 + setup do
  6 + @environment = Environment.default
  7 + @plugin = VirtuosoPlugin.new(self)
  8 + login_as(create_admin_user(environment))
  9 + @ontology_mapping = [{'source' => 'title', 'target' => 'http://purl.org/dc/elements/1.1/title'},
  10 + {'source' => 'creator', 'target' => 'http://purl.org/dc/elements/1.1/creator'}]
  11 + end
  12 +
  13 + attr_reader :environment, :plugin, :ontology_mapping
  14 +
  15 + should 'list saved mappings' do
  16 + settings = plugin.settings
  17 + settings.ontology_mapping = ontology_mapping
  18 + settings.save!
  19 + get :index
  20 + assert_select "#ontology-table tr", 3 do
  21 + assert_select "input[name='ontology_mapping[][source]']"
  22 + assert_select "input[name='ontology_mapping[][target]']"
  23 + end
  24 + end
  25 +
  26 + should 'save ontology mappings' do
  27 + post :index, 'ontology_mapping' => ontology_mapping
  28 + @environment = environment.reload
  29 + assert_equivalent ontology_mapping, plugin.settings.ontology_mapping
  30 + end
  31 +
  32 +end
... ...
plugins/virtuoso/test/unit/dublin_core_metadata_test.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class DublinCoreMetadataTest < ActiveSupport::TestCase
  4 +
  5 + should 'parse default dublin core fields' do
  6 + dc = VirtuosoPlugin::DublinCoreMetadata.new(metadata)
  7 + assert_equal "Title", dc.title
  8 + assert_equal "Creator", dc.creator
  9 + assert_equal ["Subject", "Other Subject"], dc.subject
  10 + assert_equal "Description", dc.description
  11 + assert_equal "2014", dc.date
  12 + assert_equal "Type", dc.type
  13 + assert_equal "Identifier", dc.identifier
  14 + assert_equal "Language", dc.language
  15 + assert_equal "Rights", dc.rights
  16 + assert_equal "Format", dc.format
  17 + end
  18 +
  19 + should 'extract fields' do
  20 + dc = VirtuosoPlugin::DublinCoreMetadata.new(metadata)
  21 + assert_equal "Title", dc.extract_field('dc:title')
  22 + assert_equal "Creator", dc.extract_field('dc:creator')
  23 + assert_equal ["Subject", "Other Subject"], dc.extract_field('dc:subject')
  24 + end
  25 +
  26 + should 'return nil when field do not exists' do
  27 + dc = VirtuosoPlugin::DublinCoreMetadata.new(metadata)
  28 + assert_equal nil, dc.extract_field('dc:undefinedField')
  29 + end
  30 +
  31 + def metadata
  32 + REXML::Document.new('
  33 + <metadata>
  34 + <oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  35 + <dc:title>Title</dc:title>
  36 + <dc:creator>Creator</dc:creator>
  37 + <dc:subject>Subject</dc:subject>
  38 + <dc:subject>Other Subject</dc:subject>
  39 + <dc:description>Description</dc:description>
  40 + <dc:date>2014</dc:date>
  41 + <dc:type>Type</dc:type>
  42 + <dc:identifier>Identifier</dc:identifier>
  43 + <dc:language>Language</dc:language>
  44 + <dc:rights>Rights</dc:rights>
  45 + <dc:format>Format</dc:format>
  46 + </oai_dc:dc>
  47 + </metadata>
  48 + ')
  49 + end
  50 +
  51 +end
... ...
plugins/virtuoso/test/unit/virtuoso_plugin_test.rb
... ... @@ -29,4 +29,8 @@ class VirtuosoPluginTest &lt; ActiveSupport::TestCase
29 29 plugin.virtuoso_readonly_client
30 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 36 end
... ...
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, :size=> 58 } %>
  4 + <%= button_without_text(:delete, _('Delete'), "#" , :class=>"delete-server-list-row") %>
  5 + <BR><BR>
  6 +</div>
  7 +
... ...
plugins/virtuoso/views/virtuoso_plugin_admin/add_triple.html.erb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +<div id="virtuoso-triples-management-add-triple">
  2 +
  3 + <h3><%= _('Add Triple')%></h3>
  4 +
  5 + <%= form_tag do %>
  6 +
  7 + <ul>
  8 + <li>
  9 + <%= labelled_form_field(_('Graph:'), text_field_tag('triple[graph]', '') ) %>
  10 + </li>
  11 + <li>
  12 + <%= labelled_form_field(_('Subject:'), text_field_tag('triple[subject]', '') ) %>
  13 + </li>
  14 + <li>
  15 + <%= labelled_form_field(_('Predicate:'), text_field_tag('triple[predicate]', '') ) %>
  16 + </li>
  17 + <li>
  18 + <%= labelled_form_field(_('Object:'), text_field_tag('triple[object]', '') ) %>
  19 + </li>
  20 + </ul>
  21 +
  22 + <% button_bar do %>
  23 + <%= button :add, _('Add'), {}, :href => '#', :onclick => "add_triple(); return false;" %>
  24 + <%= colorbox_close_button(_('Close')) %>
  25 + <% end %>
  26 +
  27 + <% end %>
  28 +
  29 +</div>
... ...
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   - <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri) %>
9   - <%= labelled_form_field _('Virtuoso Admin Username:'), f.text_field(:virtuoso_username) %>
10   - <%= labelled_form_field _('Virtuoso Admin Password:'), f.password_field(:virtuoso_password) %>
11   - <%= labelled_form_field _('Virtuoso Read-Only Username:'), f.text_field(:virtuoso_readonly_username) %>
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) %>
  8 + <%= labelled_form_field _('Virtuoso URL:'), f.text_field(:virtuoso_uri, :size=> 60) %>
  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) %>
  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) %>
14 13 </strong>
15   -
  14 + <BR>
  15 +<div class="dspace-servers-config-box" >
  16 +
  17 + <strong><%= _('Dspace Servers\' URL:') %></strong>
  18 + <div id='edit-server-list-block'>
  19 + <div id="dropable-server-list">
  20 + <%= render :partial => 'server_list_item', :collection=>@settings.dspace_servers %>
  21 + </div>
  22 + <div id="dspace-new-template">
  23 + <div >
  24 + <%= render :partial => 'server_list_item', :locals => {:dspace_uri => "http://"} %>
  25 + </div>
  26 + </div>
  27 + <%= link_to_function(_('New Dspace Server'), 'add_new_server();', :class => 'button icon-add with-text') %>
  28 + </div>
  29 +</div>
16 30 <% button_bar do %>
17   - <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
  31 + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %>
  32 + <% end %>
18 33 <% end %>
19   -
20   -<% end %>
21   -
22   -<hr/>
23 34 <div class="harvest">
24 35 <% if @settings.last_harvest %>
25 36 <div class="date">
... ... @@ -36,12 +47,11 @@
36 47 <% end %>
37 48 </div>
38 49 </div>
39   -
40 50 <hr />
41   -
42 51 <div class="triple-management">
43 52 <div class="actions">
44   - <%= button :edit, _('Triple management'), :action => :triple_management %>
  53 + <%= button :edit, _('Triples management'), :action => :triples_management %>
45 54 <%= button :edit, _('Custom Queries'), :action => :index, :controller => 'virtuoso_plugin_custom_queries' %>
  55 + <%= button :edit, _('Ontology mapping'), :action => :index, :controller => 'virtuoso_plugin_ontology_mapping' %>
46 56 </div>
47 57 </div>
... ...
plugins/virtuoso/views/virtuoso_plugin_admin/triple_management.html.erb
1 1 <div id="virtuoso-triples-management">
2 2 <h1><%= _('Virtuoso settings &raquo; Triples Management')%></h1>
3 3  
4   - <%= form_tag('/admin/plugin/virtuoso/triple_management', :method => 'post') do %>
5   - <%= labelled_form_field(_('Default Graph IRI:'), text_field_tag(:graph_uri, @graph_uri) ) %>
  4 + <%= form_tag('/admin/plugin/virtuoso/triples_management', :method => 'post') do %>
  5 + <%= labelled_form_field(_('Graph URI:'), text_field_tag(:graph_uri, @graph_uri) ) %>
6 6 <%= labelled_form_field(_('Query SPARQL:'), text_area_tag(:query, @query, :rows => 7)) %>
7 7 <% button_bar do %>
8   - <%= submit_button(:search, _('Search')) %>
  8 + <%= submit_button(:search, _('Search triples')) %>
  9 + <%= colorbox_button('add', _('Add a triple'), { :action => 'add_triple' }) %>
9 10 <% end %>
10 11 <% end %>
11 12  
12 13 <% unless @triples.empty? %>
13 14  
14   - <%= form_tag('/admin/plugin/virtuoso/triple_update', :method => 'post') do %>
  15 + <%= form_tag('/admin/plugin/virtuoso/triple_update', :method => 'post', :id => 'form-triples-edit') do %>
15 16 <%= hidden_field_tag(:graph_uri, @graph_uri) %>
16 17  
17 18 <ul id="triples-list">
... ... @@ -20,7 +21,7 @@
20 21  
21 22 <% @triples.each { |triple| %>
22 23  
23   - <li>
  24 + <li id="triple-<%=triple_counter%>">
24 25 <ul class="triple">
25 26 <li>
26 27 <%= hidden_field_tag("triples[triple#{triple_counter}[from][subject]]", triple[:s].to_s) %>
... ... @@ -34,6 +35,9 @@
34 35 <%= hidden_field_tag("triples[triple#{triple_counter}[from][object]]", triple[:o].to_s) %>
35 36 <%= labelled_form_field(_('Object:'), text_field_tag("triples[triple#{triple_counter}[to][object]]", triple[:o].to_s) ) %>
36 37 </li>
  38 + <li class="triple-actions">
  39 + <%= button :remove, _('Remove triple'), {}, :href => '#', :onclick => "remove_triple(#{triple_counter}); return false;" %>
  40 + </li>
37 41 </ul>
38 42 </li>
39 43  
... ... @@ -52,3 +56,5 @@
52 56 <% end %>
53 57  
54 58 </div>
  59 +
  60 +<%= javascript_include_tag '/plugins/virtuoso/triples_management.js' %>
... ...
plugins/virtuoso/views/virtuoso_plugin_ontology_mapping/_ontology_mapping_item.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<tr>
  2 + <td><%= text_field_tag 'ontology_mapping[][source]', ontology_mapping_item[:source] %></td>
  3 + <td><%= text_field_tag 'ontology_mapping[][target]', ontology_mapping_item[:target], :style => 'width: 100%' %></td>
  4 + <td><%= button :remove, _('Remove'), '#', :class => "remove-ontology-button" %></td>
  5 +</tr>
... ...
plugins/virtuoso/views/virtuoso_plugin_ontology_mapping/index.html.erb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +<h1><%= _('Ontology Mapping') %></h1>
  2 +
  3 +<%= form_for :ontology_mapping do |f| %>
  4 +<table id="ontology-table">
  5 + <tr>
  6 + <th width="30%"><%= _('Source') %></th>
  7 + <th width="70%"><%= _('Target') %></th>
  8 + <th></th>
  9 + </tr>
  10 + <%= render :partial => 'ontology_mapping_item', :collection => @ontology_mapping %>
  11 +</table>
  12 +<div class="actions">
  13 + <%= button :new, _('New'), '#', :id => 'new-ontology-button' %>
  14 + <%= submit_button :save, _('Save') %>
  15 +</div>
  16 +<% end %>
  17 +
  18 +<table id="ontology-item-template" style="display: none">
  19 + <%= render :partial => 'ontology_mapping_item', :collection => [{:source => '', :target => ''}] %>
  20 +</table>
  21 +
  22 +<%= javascript_include_tag '/plugins/virtuoso/ontology_mapping.js' %>
... ...