Modified: branches/wf4ever/app/controllers/relationships_controller.rb (3402 => 3403)
--- branches/wf4ever/app/controllers/relationships_controller.rb 2013-02-06 09:08:34 UTC (rev 3402)
+++ branches/wf4ever/app/controllers/relationships_controller.rb 2013-02-06 16:42:22 UTC (rev 3403)
@@ -29,12 +29,20 @@
# POST /:context_type/:context_id/relationships
def create
- subject_relative_uri = URI::decode(params[:subject])
- object_relative_uri = URI::decode(params[:object])
+ base_uri = URI.parse(@context.ro_uri)
- subject = @context.contributable_entries.find_by_relative_uri(subject_relative_uri)
- object = @context.contributable_entries.find_by_relative_uri(object_relative_uri)
+ subject_uri = base_uri.merge(params[:subject])
+ object_uri = base_uri.merge(params[:object])
+ subject = @context.contributable_entries.find_by_uri(subject_uri)
+ object = @context.contributable_entries.find_by_uri(object_uri)
+
+ if subject.nil? || object.nil?
+ @context.errors.add(params[:template], 'Relationships must refer to resources within the pack')
+ redirect_to pack_path(@context.id)
+ return
+ end
+
match = params[:predicate].match("(.*[#/])([^#/]+)")
ns1 = match[1]
@@ -42,9 +50,6 @@
session = ROSRS::Session.new(@context.ro_uri, Conf.rodl_bearer_token)
- subject_uri = "address@hidden::encode(subject.ro_local_uri)}"
- object_uri = "address@hidden::encode(object.ro_local_uri)}"
-
ao_body = <<RDF
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -61,7 +66,7 @@
code, reason, stub_uri, body_uri = session.create_internal_annotation(@context.ro_uri, subject_uri, agraph)
code, reason, stub_uri, body_uri = session.create_internal_annotation(@context.ro_uri, object_uri, agraph)
rescue ROSRS::Exception => e
- errors.add(params[:template], 'Error from remote server')
+ @context.errors.add(params[:template], 'Error from remote server')
end
flash[:notice] = "Relationship added."
Modified: branches/wf4ever/app/models/pack.rb (3402 => 3403)
--- branches/wf4ever/app/models/pack.rb 2013-02-06 09:08:34 UTC (rev 3402)
+++ branches/wf4ever/app/models/pack.rb 2013-02-06 16:42:22 UTC (rev 3403)
@@ -104,9 +104,12 @@
end
end
- def find_by_relative_uri(relative_uri)
+ def find_by_uri(relative_uri)
+
+ ro_uri = URI.parse(@pack.ro_uri)
+
@entries.each do |entry|
- return entry if entry.uri == @pack.ro_uri + relative_uri
+ return entry if ro_uri.merge(entry.uri) == ro_uri.merge(relative_uri)
end
nil