Commit e07ff8d511f203a5491ad15aff18a711763528bf
1 parent
350d497f
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: improve triples management feature
Showing
3 changed files
with
41 additions
and
31 deletions
Show diff stats
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
| ... | ... | @@ -47,15 +47,16 @@ class VirtuosoPluginAdminController < AdminController |
| 47 | 47 | to_triple.object = params[:to_triple][:object] |
| 48 | 48 | |
| 49 | 49 | triples_management = VirtuosoPlugin::TriplesManagement.new(environment) |
| 50 | - triples_management.update_triple(from_triple, to_triple) | |
| 51 | 50 | |
| 52 | - render json: { :ok => true, :message => _('Triple succesfully updated.') } | |
| 51 | + triple_updated = triples_management.update_triple(from_triple, to_triple) | |
| 52 | + message = triple_updated ? _('Triple succesfully updated.') : _('Triple not updated.') | |
| 53 | + | |
| 54 | + render json: { :ok => triple_updated, :message => message } | |
| 53 | 55 | end |
| 54 | 56 | end |
| 55 | 57 | |
| 56 | 58 | def add_triple |
| 57 | 59 | if request.post? |
| 58 | - | |
| 59 | 60 | triple = VirtuosoPlugin::Triple.new |
| 60 | 61 | triple.graph = params[:triple][:graph] |
| 61 | 62 | triple.subject = params[:triple][:subject] |
| ... | ... | @@ -63,9 +64,11 @@ class VirtuosoPluginAdminController < AdminController |
| 63 | 64 | triple.object = params[:triple][:object] |
| 64 | 65 | |
| 65 | 66 | triples_management = VirtuosoPlugin::TriplesManagement.new(environment) |
| 66 | - triples_management.add_triple(triple) | |
| 67 | 67 | |
| 68 | - render json: { :ok => true, :message => _('Triple succesfully added.') } | |
| 68 | + triple_added = triples_management.add_triple(triple) | |
| 69 | + message = triple_added ? _('Triple succesfully added.') : _('Triple not added.') | |
| 70 | + | |
| 71 | + render json: { :ok => triple_added, :message => message } | |
| 69 | 72 | end |
| 70 | 73 | end |
| 71 | 74 | |
| ... | ... | @@ -78,9 +81,11 @@ class VirtuosoPluginAdminController < AdminController |
| 78 | 81 | triple.object = params[:triple][:object] |
| 79 | 82 | |
| 80 | 83 | triples_management = VirtuosoPlugin::TriplesManagement.new(environment) |
| 81 | - triples_management.remove_triple(triple) | |
| 82 | 84 | |
| 83 | - render json: { :ok => true, :message => _('Triple succesfully removed.') } | |
| 85 | + triple_deleted = triples_management.remove_triple(triple) | |
| 86 | + message = triple_deleted ? _('Triple succesfully removed.') : _('Triple not removed.') | |
| 87 | + | |
| 88 | + render json: { :ok => triple_deleted, :message => message } | |
| 84 | 89 | end |
| 85 | 90 | end |
| 86 | 91 | ... | ... |
plugins/virtuoso/lib/virtuoso_plugin/triples_management.rb
| ... | ... | @@ -18,17 +18,37 @@ class VirtuosoPlugin::TriplesManagement |
| 18 | 18 | def update_triple(from_triple, to_triple) |
| 19 | 19 | query = "WITH <#{from_triple.graph}> DELETE { <#{from_triple.subject}> <#{from_triple.predicate}> #{from_triple.object} } INSERT { <#{to_triple.subject}> <#{to_triple.predicate}> #{to_triple.object} }" |
| 20 | 20 | |
| 21 | - plugin.virtuoso_client.query(query) | |
| 21 | + begin | |
| 22 | + query_result = plugin.virtuoso_client.query(query)[0][:"callret-0"].to_s | |
| 23 | + rescue RDF::Virtuoso::Repository::MalformedQuery => e | |
| 24 | + query_result = e.to_s | |
| 25 | + end | |
| 26 | + | |
| 27 | + return query_result =~ /^Modify.*done$/ ? true : false | |
| 22 | 28 | end |
| 23 | 29 | |
| 24 | 30 | def add_triple(triple) |
| 25 | 31 | query = "WITH <#{triple.graph}> INSERT { <#{triple.subject}> <#{triple.predicate}> #{triple.object} }" |
| 26 | - plugin.virtuoso_client.query(query) | |
| 32 | + | |
| 33 | + begin | |
| 34 | + query_result = plugin.virtuoso_client.query(query)[0][:"callret-0"].to_s | |
| 35 | + rescue RDF::Virtuoso::Repository::MalformedQuery => e | |
| 36 | + query_result = e.to_s | |
| 37 | + end | |
| 38 | + | |
| 39 | + return query_result =~ /^Insert.*done$/ ? true : false | |
| 27 | 40 | end |
| 28 | 41 | |
| 29 | 42 | def remove_triple(triple) |
| 30 | 43 | query = "WITH <#{triple.graph}> DELETE { <#{triple.subject}> <#{triple.predicate}> #{triple.object} }" |
| 31 | - plugin.virtuoso_client.query(query) | |
| 44 | + | |
| 45 | + begin | |
| 46 | + query_result = plugin.virtuoso_client.query(query)[0][:"callret-0"].to_s | |
| 47 | + rescue RDF::Virtuoso::Repository::MalformedQuery => e | |
| 48 | + query_result = e.to_s | |
| 49 | + end | |
| 50 | + | |
| 51 | + return query_result =~ /^Delete.*done$/ ? true : false | |
| 32 | 52 | end |
| 33 | 53 | |
| 34 | 54 | end | ... | ... |
plugins/virtuoso/public/triples_management.js
| ... | ... | @@ -20,17 +20,14 @@ function update_triple(triple_id) { |
| 20 | 20 | url: '/admin/plugin/virtuoso/update_triple', |
| 21 | 21 | data: formData, |
| 22 | 22 | dataType: 'json', |
| 23 | - success: function(data, status, ajax){ | |
| 23 | + success: function(data, status, ajax) { | |
| 24 | 24 | if ( !data.ok ) { |
| 25 | - display_notice(data.error.message); | |
| 25 | + display_notice(data.message); | |
| 26 | 26 | } |
| 27 | 27 | else { |
| 28 | 28 | display_notice(data.message); |
| 29 | 29 | jQuery("input#triples_triple" + triple_id + "_from_object").val(jQuery("input#triples_triple" + triple_id + "_to_object").val()); |
| 30 | 30 | } |
| 31 | - }, | |
| 32 | - error: function(ajax, status, errorThrown) { | |
| 33 | - alert('Send request - HTTP '+status+': '+errorThrown); | |
| 34 | 31 | } |
| 35 | 32 | }); |
| 36 | 33 | |
| ... | ... | @@ -50,18 +47,9 @@ function add_triple() { |
| 50 | 47 | url: '/admin/plugin/virtuoso/add_triple', |
| 51 | 48 | data: formData, |
| 52 | 49 | dataType: 'json', |
| 53 | - success: function(data, status, ajax){ | |
| 54 | - if ( !data.ok ) { | |
| 55 | - display_notice(data.error.message); | |
| 56 | - jQuery.colorbox.close(); | |
| 57 | - } | |
| 58 | - else { | |
| 59 | - display_notice(data.message); | |
| 60 | - jQuery.colorbox.close(); | |
| 61 | - } | |
| 62 | - }, | |
| 63 | - error: function(ajax, status, errorThrown) { | |
| 64 | - alert('Send request - HTTP '+status+': '+errorThrown); | |
| 50 | + success: function(data, status, ajax) { | |
| 51 | + display_notice(data.message); | |
| 52 | + jQuery.colorbox.close(); | |
| 65 | 53 | } |
| 66 | 54 | }); |
| 67 | 55 | |
| ... | ... | @@ -84,7 +72,7 @@ function remove_triple(triple_id) { |
| 84 | 72 | dataType: 'json', |
| 85 | 73 | success: function(data, status, ajax){ |
| 86 | 74 | if ( !data.ok ) { |
| 87 | - display_notice(data.error.message); | |
| 75 | + display_notice(data.message); | |
| 88 | 76 | } |
| 89 | 77 | else { |
| 90 | 78 | display_notice(data.message); |
| ... | ... | @@ -97,9 +85,6 @@ function remove_triple(triple_id) { |
| 97 | 85 | } |
| 98 | 86 | }); |
| 99 | 87 | } |
| 100 | - }, | |
| 101 | - error: function(ajax, status, errorThrown) { | |
| 102 | - alert('Send request - HTTP '+status+': '+errorThrown); | |
| 103 | 88 | } |
| 104 | 89 | }); |
| 105 | 90 | ... | ... |