Diff
Deleted: trunk/lib/api/resources/blobs.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/blobs.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/blobs.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,147 +0,0 @@
-# myExperiment: lib/api/resources/blobs.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def file_aux(action, opts = {})
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a file") unless Authorization.check('create', Blob, opts[:user], nil)
- if opts[:query]['id']
- ob, error = obtain_rest_resource('Blob', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- ob = Blob.new(:contributor => opts[:user])
- end
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Blob', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- return rest_response(400, :reason => "Cannot delete individual versions") if opts[:query]['version']
-
- ob.destroy
-
- else
-
- data = ""
-
- title = parse_element(data, :text, '/file/title')
- description = parse_element(data, :text, '/file/description')
- license_type = parse_element(data, :text, '/file/license-type')
- type = parse_element(data, :text, '/file/type')
- filename = parse_element(data, :text, '/file/filename')
- content_type = parse_element(data, :text, '/file/content-type')
- content = parse_element(data, :binary, '/file/content')
- revision_comment = parse_element(data, :text, '/file/revision-comment')
-
- permissions = data.find_first('/file/permissions')
-
- # build the contributable
-
- ob.title = title if title
- ob.body = description if description
-
- if license_type
- if license_type == ""
- ob.license = nil
- else
- ob.license = License.find_by_unique_name(license_type)
-
- if ob.license.nil?
- ob.errors.add("License type")
- return rest_response(400, :object => ob)
- end
- end
- end
-
- # file name
-
- if filename && !filename.blank?
- ob.local_name = filename
- else
- if ob.local_name.blank?
- ob.errors.add("Filename", "missing")
- return rest_response(400, :object => ob)
- end
- end
-
- # handle type
-
- if type
-
- ob.content_type = ContentType.find_by_title(type)
-
- if ob.content_type.nil?
- ob.errors.add("Type")
- return rest_response(400, :object => ob)
- end
-
- elsif content_type
-
- content_types = ContentType.find_all_by_mime_type(content_type)
-
- if content_types.length == 1
- ob.content_type = content_types.first
- else
- if content_types.empty?
- ob.errors.add("Content type")
- else
- ob.errors.add("Content type", "matches more than one registered content type")
- end
-
- return rest_response(400, :object => ob)
- end
- end
-
- ob.content_blob = ContentBlob.new(:data ="" content) if content
-
- new_version = action == 'create' && opts[:query]['id'] != nil
- edit_version = action == 'edit' && opts[:query]['version'] != nil
-
- if new_version
- ob[:revision_comments] = revision_comment
- end
-
- success = ob.save
-
- if success
- case "#{action} #{new_version || edit_version}"
- when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
- when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
- when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
- when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.blob)
- end
- end
-
- return rest_response(400, :object => ob) unless success
-
- if opts[:query]['version'].nil?
- update_permissions(ob, permissions, opts[:user])
- end
- end
-
- ob = ob.versioned_resource if ob.respond_to?("versioned_resource")
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_file(opts)
- file_aux('create', opts)
-end
-
-def put_file(opts)
- file_aux('edit', opts)
-end
-
-def delete_file(opts)
- file_aux('destroy', opts)
-end
-
Copied: trunk/lib/api/resources/blobs.rb (from rev 3683, branches/component-api/lib/api/resources/blobs.rb) (0 => 3685)
--- trunk/lib/api/resources/blobs.rb (rev 0)
+++ trunk/lib/api/resources/blobs.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,147 @@
+# myExperiment: lib/api/resources/blobs.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def file_aux(action, opts = {})
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a file") unless Authorization.check('create', Blob, opts[:user], nil)
+ if opts[:query]['id']
+ ob, error = obtain_rest_resource('Blob', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ ob = Blob.new(:contributor => opts[:user])
+ end
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Blob', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ return rest_response(400, :reason => "Cannot delete individual versions") if opts[:query]['version']
+
+ ob.destroy
+
+ else
+
+ data = ""
+
+ title = parse_element(data, :text, '/file/title')
+ description = parse_element(data, :text, '/file/description')
+ license_type = parse_element(data, :text, '/file/license-type')
+ type = parse_element(data, :text, '/file/type')
+ filename = parse_element(data, :text, '/file/filename')
+ content_type = parse_element(data, :text, '/file/content-type')
+ content = parse_element(data, :binary, '/file/content')
+ revision_comment = parse_element(data, :text, '/file/revision-comment')
+
+ permissions = data.find_first('/file/permissions')
+
+ # build the contributable
+
+ ob.title = title if title
+ ob.body = description if description
+
+ if license_type
+ if license_type == ""
+ ob.license = nil
+ else
+ ob.license = License.find_by_unique_name(license_type)
+
+ if ob.license.nil?
+ ob.errors.add("License type")
+ return rest_response(400, :object => ob)
+ end
+ end
+ end
+
+ # file name
+
+ if filename && !filename.blank?
+ ob.local_name = filename
+ else
+ if ob.local_name.blank?
+ ob.errors.add("Filename", "missing")
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ # handle type
+
+ if type
+
+ ob.content_type = ContentType.find_by_title(type)
+
+ if ob.content_type.nil?
+ ob.errors.add("Type")
+ return rest_response(400, :object => ob)
+ end
+
+ elsif content_type
+
+ content_types = ContentType.find_all_by_mime_type(content_type)
+
+ if content_types.length == 1
+ ob.content_type = content_types.first
+ else
+ if content_types.empty?
+ ob.errors.add("Content type")
+ else
+ ob.errors.add("Content type", "matches more than one registered content type")
+ end
+
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ ob.content_blob = ContentBlob.new(:data ="" content) if content
+
+ new_version = action == 'create' && opts[:query]['id'] != nil
+ edit_version = action == 'edit' && opts[:query]['version'] != nil
+
+ if new_version
+ ob[:revision_comments] = revision_comment
+ end
+
+ success = ob.save
+
+ if success
+ case "#{action} #{new_version || edit_version}"
+ when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
+ when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
+ when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
+ when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.blob)
+ end
+ end
+
+ return rest_response(400, :object => ob) unless success
+
+ if opts[:query]['version'].nil?
+ update_permissions(ob, permissions, opts[:user])
+ end
+ end
+
+ ob = ob.versioned_resource if ob.respond_to?("versioned_resource")
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_file(opts)
+ file_aux('create', opts)
+end
+
+def put_file(opts)
+ file_aux('edit', opts)
+end
+
+def delete_file(opts)
+ file_aux('destroy', opts)
+end
+
Deleted: trunk/lib/api/resources/comments.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/comments.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/comments.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,139 +0,0 @@
-# myExperiment: lib/api/resources/comments.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def comment_aux(action, opts)
-
- unless action == "destroy"
-
- data = ""
-
- comment = parse_element(data, :text, '/comment/comment')
- subject = parse_element(data, :resource, '/comment/subject')
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a comment") unless Authorization.check('create', Comment, opts[:user], subject)
-
- ob = Comment.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Comment', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- ob.comment = comment if comment
-
- if subject
- return rest_response(400, :reason => "Specified resource does not support comments") unless [Blob, Network, Pack, Workflow].include?(subject.class)
- return rest_response(401, :reason => "Not authorised to add a comment to the specified resource") unless Authorization.check(action, Comment, opts[:user], subject)
- ob.commentable = subject
- end
-
- # Start of curation hack
-
- def match_tag_name(name)
-
- name.sub!(/^c:/, '')
-
- matches = []
-
- Conf.curation_types.each do |type|
- matches.push type if type.starts_with?(name)
- end
-
- return matches[0] if matches.length == 1
- end
-
- if comment[0..1].downcase == 'c:' && opts[:user] && subject &&
- Conf.curators.include?(opts[:user].username)
-
- comment = comment[2..-1].strip
-
- lines = comment.split("\n")
- events = []
- failed = false
-
- lines.each do |line|
-
- line.strip!
-
- bits = line.split(";")
-
- if bits.length > 1
- details = bits[1..-1].join(";")
- else
- details = nil
- end
-
- if bits.length > 0
- bits[0].split(",").each do |bit|
-
- bit.downcase!
- bit.strip!
-
- curation_type = match_tag_name(bit)
-
- if curation_type
- events.push(CurationEvent.new(:category => curation_type,
- :object => subject, :user => opts[:user], :details => details))
- else
- failed = true
- end
- end
- end
- end
-
- if failed
- return rest_response(400, :reason => 'Unrecognised curation term')
- end
-
- events.each do |event|
- event.save
- end
-
- subject.solr_index
-
- return rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
- end
-
- # End of curation hack
-
- success = ob.save
-
- if success
- case action
- when "create"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob)
- when "edit"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob)
- end
- end
-
- return rest_response(400, :object => ob) unless success
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_comment(opts)
- comment_aux('create', opts)
-end
-
-def put_comment(opts)
- comment_aux('edit', opts)
-end
-
-def delete_comment(opts)
- comment_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/comments.rb (from rev 3683, branches/component-api/lib/api/resources/comments.rb) (0 => 3685)
--- trunk/lib/api/resources/comments.rb (rev 0)
+++ trunk/lib/api/resources/comments.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,139 @@
+# myExperiment: lib/api/resources/comments.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def comment_aux(action, opts)
+
+ unless action == "destroy"
+
+ data = ""
+
+ comment = parse_element(data, :text, '/comment/comment')
+ subject = parse_element(data, :resource, '/comment/subject')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a comment") unless Authorization.check('create', Comment, opts[:user], subject)
+
+ ob = Comment.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Comment', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ ob.comment = comment if comment
+
+ if subject
+ return rest_response(400, :reason => "Specified resource does not support comments") unless [Blob, Network, Pack, Workflow].include?(subject.class)
+ return rest_response(401, :reason => "Not authorised to add a comment to the specified resource") unless Authorization.check(action, Comment, opts[:user], subject)
+ ob.commentable = subject
+ end
+
+ # Start of curation hack
+
+ def match_tag_name(name)
+
+ name.sub!(/^c:/, '')
+
+ matches = []
+
+ Conf.curation_types.each do |type|
+ matches.push type if type.starts_with?(name)
+ end
+
+ return matches[0] if matches.length == 1
+ end
+
+ if comment[0..1].downcase == 'c:' && opts[:user] && subject &&
+ Conf.curators.include?(opts[:user].username)
+
+ comment = comment[2..-1].strip
+
+ lines = comment.split("\n")
+ events = []
+ failed = false
+
+ lines.each do |line|
+
+ line.strip!
+
+ bits = line.split(";")
+
+ if bits.length > 1
+ details = bits[1..-1].join(";")
+ else
+ details = nil
+ end
+
+ if bits.length > 0
+ bits[0].split(",").each do |bit|
+
+ bit.downcase!
+ bit.strip!
+
+ curation_type = match_tag_name(bit)
+
+ if curation_type
+ events.push(CurationEvent.new(:category => curation_type,
+ :object => subject, :user => opts[:user], :details => details))
+ else
+ failed = true
+ end
+ end
+ end
+ end
+
+ if failed
+ return rest_response(400, :reason => 'Unrecognised curation term')
+ end
+
+ events.each do |event|
+ event.save
+ end
+
+ subject.solr_index
+
+ return rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+ end
+
+ # End of curation hack
+
+ success = ob.save
+
+ if success
+ case action
+ when "create"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob)
+ when "edit"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob)
+ end
+ end
+
+ return rest_response(400, :object => ob) unless success
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_comment(opts)
+ comment_aux('create', opts)
+end
+
+def put_comment(opts)
+ comment_aux('edit', opts)
+end
+
+def delete_comment(opts)
+ comment_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/components.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/components.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/components.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,349 +0,0 @@
-# myExperiment: lib/api/resources/components.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-# Extensions to the REST API for dealing with components
-
-##
-# Retrieve a list of component URIs that match a given (restricted) SPARQL query
-def get_components(opts)
- return rest_response(404) if TripleStore.instance.nil?
-
- sparql_prefixes = CGI.unescape(opts[:query]["prefixes"] || '')
- sparql_query = CGI.unescape(opts[:query]["query"] || '')
-
- # Prevent subversion of SELECT template
- if sparql_prefixes.downcase.include?("select")
- return rest_response(400, :reason => "Invalid prefix syntax")
- end
-
- template = %(
- PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
- PREFIX wfdesc:<http://purl.org/wf4ever/wfdesc#>
- PREFIX wf4ever:<http://purl.org/wf4ever/wf4ever#>
- #{sparql_prefixes}
-
- SELECT DISTINCT ?workflow_uri WHERE {
- GRAPH ?workflow_uri {
- ?w a wfdesc:Workflow .
- #{sparql_query}
- }
- })
-
- # Perform query
- begin
- sparql_results = TripleStore.instance.query(template)
- rescue Sesame::QueryException => e
- return rest_response(400, :reason => "SPARQL Error: #{e.message}")
- end
-
- # Map the returned URIs to actual workflow objects
- results = sparql_results.map { |r| resource_from_uri(r[:workflow_uri]) }.compact
-
- results = results.select do |workflow|
- # Check workflow is a component and that the user can view it
- workflow.component? && Authorization.check("view", workflow, opts[:user])
- end
-
- # Filter by component family, if given
- component_family_uri = opts[:query]['component-family']
- if component_family_uri
- component_family = resource_from_uri(component_family_uri)
- if component_family.nil?
- return rest_response(404, :reason => 'Component family not found')
- elsif !component_family.is_a?(Pack) || !component_family.component_family?
- return rest_response(400, :reason => "No valid component family found at #{component_family_uri}")
- else
- # Take the intersection of the current list of components and the components in the family
- results = results & component_family.contributable_entries.map { |e| e.contributable }
- end
- end
-
- # Render results
- produce_rest_list(opts[:uri], opts[:rules], opts[:query], results, "workflows", [], opts[:user])
-end
-
-
-##
-# Retrieve a component
-def get_component(opts)
- #opts[:query]['all_elements'] = "yes"
- rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
- {'Model Entity' => 'workflow',
- 'Permission' => 'view'},
- opts[:user], opts[:query])
-end
-
-
-##
-# Create a new component in the specified family
-def post_component(opts)
- # Check if posting a new version of an existing component (id present)
- id = opts[:query]['id']
- if id
- component = Workflow.find_by_id(id.to_i)
- unless component && component.component?
- return rest_response(404, :reason => "Component not found")
- end
- else # Otherwise, we're creating a new component
- data = ""
-
- # Get the component family
- component_family_uri = parse_element(data, :text, '/workflow/component-family')
- family = resource_from_uri(component_family_uri)
- if family.nil?
- return rest_response(404, :reason => 'Component family not found')
- elsif !family.is_a?(Pack) || !family.component_family?
- return rest_response(400, :reason => "No valid component family found at #{component_family_uri}")
- elsif !Authorization.check('edit', family, opts[:user])
- return rest_response(401, :reason => "You are not authorized to add components to this component family")
- end
- end
-
- # Create the component or version
- response = workflow_aux('create', opts)
-
- # If we created a new component, we need to tag it and add it to the family
- unless id
- # Awful hack to get the newly created component
- component = resource_from_uri(response[:xml].find_first('//workflow')['resource'])
-
- # Add the component to the family
- PackContributableEntry.create(:pack => family, :contributable => component, :user => opts[:user])
-
- # Add the tag
- tag = Tag.find_or_create_by_name('component')
- Tagging.create(:tag => tag, :taggable => component, :user => opts[:user])
- end
-
- rest_get_request(component, opts[:user], { "id" => component.id.to_s })
-end
-
-
-##
-# Retrieve an XML representation of a component family
-#
-# Can filter by component profile, by specifying the component profile URI in the component-profile parameter
-# e.g. GET component-families.xml?component-profile=""
-def get_component_families(opts)
- # Find all component family packs
- families = Pack.component_families
-
- # Filter by component profile, if given
- component_profile_uri = opts[:query]['component-profile']
- if component_profile_uri
- component_profile = resource_from_uri(component_profile_uri)
- if component_profile.nil?
- return rest_response(404, :reason => 'Component profile not found')
- else
- # Check for the given component profile in the set of families
- families = families.select { |family| family.component_profile == component_profile }
- end
- end
-
- # Authorization
- families = families.select { |r| Authorization.check("view", r, opts[:user]) }
-
- # Render results
- produce_rest_list(opts[:uri], opts[:rules], opts[:query], families, "component-families", [], opts[:user])
-end
-
-
-##
-# Retrieve an XML representation of a component family
-def get_component_family(opts)
- opts[:query]['all_elements'] = "yes"
- rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
- {'Model Entity' => 'pack',
- 'Permission' => 'view'},
- opts[:user], opts[:query])
-end
-
-
-##
-# Create a new component family
-def post_component_family(opts)
- # Get the component profile
- data = ""
- component_profile_uri = parse_element(data, :text, '/pack/component-profile')
-
- unless component_profile_uri
- return rest_response(400, :reason => "Missing component profile URI")
- end
-
- component_profile = resource_from_uri(component_profile_uri)
-
- if component_profile.nil?
- return rest_response(404, :reason => "No component profile found at: #{component_profile_uri}")
- elsif !component_profile.is_a?(Blob) && !component_profile.is_a?(BlobVersion)
- return rest_response(400, :reason => "#{component_profile_uri} is not a valid component profile (not a file)")
- elsif component_profile.content_type.mime_type != 'application/vnd.taverna.component-profile+xml'
- return rest_response(400, :reason => "#{component_profile_uri} is not a valid component profile (wrong MIME type)")
- end
-
- # Create the component family
- response = pack_aux('create', opts)
-
- # Awful hack to get the newly created component family
- family = resource_from_uri(response[:xml].find_first('//pack')['resource'])
-
- # Add the profile
- if component_profile.is_a?(Blob)
- PackContributableEntry.create(:pack => family, :contributable => component_profile, :user => opts[:user])
- elsif component_profile.is_a?(BlobVersion)
- PackContributableEntry.create(:pack => family, :contributable => component_profile.blob,
- :contributable_version => component_profile.version, :user => opts[:user])
- end
-
- # Add the tag
- tag = Tag.find_or_create_by_name('component family')
- Tagging.create(:tag => tag, :taggable => family, :user => opts[:user])
-
- # Return resource
- rest_get_request(family, opts[:user], { "id" => family.id.to_s })
-end
-
-
-##
-# Delete a component family and all components inside it
-def delete_component_family(opts)
- # Find the family
- id = opts[:query]['id']
- family = Pack.find_by_id(id)
- if family.nil? || !family.component_family?
- return rest_response(404, :reason => "Couldn't find a valid component family with the given ID")
- end
-
- # Check if user has permission to delete the family
- unless Authorization.check('destroy', family, opts[:user])
- family.errors.add_to_base("You don't have permission to delete this component family.")
- return rest_response(401, :object => family)
- end
-
- # Check if can delete ALL components in family
- component_entries = family.contributable_entries.select { |e| e.contributable_type == 'Workflow' && e.contributable.component? }
- components = component_entries.map { |e| e.contributable }
- undeletable_components = components.select { |c| !Authorization.check('destroy', c, opts[:user]) }
- if undeletable_components.size == 0
- # Delete all components
- components.each { |c| c.destroy }
-
- # Delete family
- family.destroy
-
- rest_get_request(family, opts[:user], opts[:query])
- else
- family.errors.add_to_base("You don't have permission to delete #{undeletable_components.size} components in this component family.")
- rest_response(401, :object => family)
- end
-end
-
-
-##
-# Retrieve a list of component profiles
-def get_component_profiles(opts)
- profiles = Blob.component_profiles
-
- # Authorization
- profiles = profiles.select { |r| Authorization.check("view", r, opts[:user]) }
-
- # Render results
- produce_rest_list(opts[:uri], opts[:rules], opts[:query], profiles, "component-profiles", [], opts[:user])
-end
-
-
-##
-# Retrieve a component profile
-def get_component_profile(opts)
- rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
- {'Model Entity' => 'blob',
- 'Permission' => 'view'},
- opts[:user], opts[:query])
-end
-
-
-##
-# Create a new component profile
-def post_component_profile(opts)
- response = file_aux('create', opts)
-
- # Return error from creation attempt, if any
- return response if response[:status] && response[:status][0] != '2'
-
- # Awful hack to get the newly created profile object
- profile = ""
-
- # Add the tag
- tag = Tag.find_or_create_by_name('component profile')
- Tagging.create(:tag => tag, :taggable => profile, :user => opts[:user])
-
- # Return resource
- rest_get_request(profile, opts[:user], { "id" => profile.id.to_s })
-end
-
-
-##
-# Delete a component profile
-def delete_component_profile(opts)
- # Find the profile
- id = opts[:query]['id']
- profile = ""
- if profile.nil? || !profile.component_profile?
- return rest_response(404, :reason => "Couldn't find a valid component profile with the given ID")
- end
-
- # Check if profile is used in any component families
- families = PackContributableEntry.find_all_by_contributable_type_and_contributable_id('Blob', profile.id).select do |e|
- e.pack.component_family?
- end
- if families.size == 0
- # Delete profile
- profile.destroy
-
- rest_get_request(profile, opts[:user], opts[:query])
- else
- profile.errors.add_to_base("This component profile is used by #{families.size} component families and may not be deleted.")
- rest_response(400, :object => profile)
- end
-end
-
-private
-
-# Checks if a given URI is a resource from THIS application
-def internal_resource_uri?(uri)
- uri = URI.parse(uri) if uri.is_a?(String)
- base_uri = URI.parse(Conf.base_uri)
-
- uri.relative? || uri.host == base_uri.host && uri.port == base_uri.port
-end
-
-# Gets an internal resource from a given URI
-def resource_from_uri(uri)
- if uri.is_a?(String)
- uri = URI.parse(uri)
- end
-
- resource = nil
-
- if internal_resource_uri?(uri)
- begin
- route = ActionController::Routing::Routes.recognize_path(uri.path, :method => :get)
- if route[:action] == "show"
- resource = Object.const_get(route[:controller].camelize.singularize).find_by_id(route[:id].to_i)
- else
- nil
- end
-
- resource = resource.find_version(route[:version].to_i) if route[:version]
- rescue ActionController::RoutingError
- logger.warn("Unrecognized resource URI: #{uri}")
- nil
- rescue ActiveRecord::RecordNotFound
- logger.warn("Couldn't find version #{route[:version]} for URI: #{uri}")
- nil
- end
- end
-
- resource
-end
Copied: trunk/lib/api/resources/components.rb (from rev 3683, branches/component-api/lib/api/resources/components.rb) (0 => 3685)
--- trunk/lib/api/resources/components.rb (rev 0)
+++ trunk/lib/api/resources/components.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,349 @@
+# myExperiment: lib/api/resources/components.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+# Extensions to the REST API for dealing with components
+
+##
+# Retrieve a list of component URIs that match a given (restricted) SPARQL query
+def get_components(opts)
+ return rest_response(404) if TripleStore.instance.nil?
+
+ sparql_prefixes = CGI.unescape(opts[:query]["prefixes"] || '')
+ sparql_query = CGI.unescape(opts[:query]["query"] || '')
+
+ # Prevent subversion of SELECT template
+ if sparql_prefixes.downcase.include?("select")
+ return rest_response(400, :reason => "Invalid prefix syntax")
+ end
+
+ template = %(
+ PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+ PREFIX wfdesc:<http://purl.org/wf4ever/wfdesc#>
+ PREFIX wf4ever:<http://purl.org/wf4ever/wf4ever#>
+ #{sparql_prefixes}
+
+ SELECT DISTINCT ?workflow_uri WHERE {
+ GRAPH ?workflow_uri {
+ ?w a wfdesc:Workflow .
+ #{sparql_query}
+ }
+ })
+
+ # Perform query
+ begin
+ sparql_results = TripleStore.instance.query(template)
+ rescue Sesame::QueryException => e
+ return rest_response(400, :reason => "SPARQL Error: #{e.message}")
+ end
+
+ # Map the returned URIs to actual workflow objects
+ results = sparql_results.map { |r| resource_from_uri(r[:workflow_uri]) }.compact
+
+ results = results.select do |workflow|
+ # Check workflow is a component and that the user can view it
+ workflow.component? && Authorization.check("view", workflow, opts[:user])
+ end
+
+ # Filter by component family, if given
+ component_family_uri = opts[:query]['component-family']
+ if component_family_uri
+ component_family = resource_from_uri(component_family_uri)
+ if component_family.nil?
+ return rest_response(404, :reason => 'Component family not found')
+ elsif !component_family.is_a?(Pack) || !component_family.component_family?
+ return rest_response(400, :reason => "No valid component family found at #{component_family_uri}")
+ else
+ # Take the intersection of the current list of components and the components in the family
+ results = results & component_family.contributable_entries.map { |e| e.contributable }
+ end
+ end
+
+ # Render results
+ produce_rest_list(opts[:uri], opts[:rules], opts[:query], results, "workflows", [], opts[:user])
+end
+
+
+##
+# Retrieve a component
+def get_component(opts)
+ #opts[:query]['all_elements'] = "yes"
+ rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
+ {'Model Entity' => 'workflow',
+ 'Permission' => 'view'},
+ opts[:user], opts[:query])
+end
+
+
+##
+# Create a new component in the specified family
+def post_component(opts)
+ # Check if posting a new version of an existing component (id present)
+ id = opts[:query]['id']
+ if id
+ component = Workflow.find_by_id(id.to_i)
+ unless component && component.component?
+ return rest_response(404, :reason => "Component not found")
+ end
+ else # Otherwise, we're creating a new component
+ data = ""
+
+ # Get the component family
+ component_family_uri = parse_element(data, :text, '/workflow/component-family')
+ family = resource_from_uri(component_family_uri)
+ if family.nil?
+ return rest_response(404, :reason => 'Component family not found')
+ elsif !family.is_a?(Pack) || !family.component_family?
+ return rest_response(400, :reason => "No valid component family found at #{component_family_uri}")
+ elsif !Authorization.check('edit', family, opts[:user])
+ return rest_response(401, :reason => "You are not authorized to add components to this component family")
+ end
+ end
+
+ # Create the component or version
+ response = workflow_aux('create', opts)
+
+ # If we created a new component, we need to tag it and add it to the family
+ unless id
+ # Awful hack to get the newly created component
+ component = resource_from_uri(response[:xml].find_first('//workflow')['resource'])
+
+ # Add the component to the family
+ PackContributableEntry.create(:pack => family, :contributable => component, :user => opts[:user])
+
+ # Add the tag
+ tag = Tag.find_or_create_by_name('component')
+ Tagging.create(:tag => tag, :taggable => component, :user => opts[:user])
+ end
+
+ rest_get_request(component, opts[:user], { "id" => component.id.to_s })
+end
+
+
+##
+# Retrieve an XML representation of a component family
+#
+# Can filter by component profile, by specifying the component profile URI in the component-profile parameter
+# e.g. GET component-families.xml?component-profile=""
+def get_component_families(opts)
+ # Find all component family packs
+ families = Pack.component_families
+
+ # Filter by component profile, if given
+ component_profile_uri = opts[:query]['component-profile']
+ if component_profile_uri
+ component_profile = resource_from_uri(component_profile_uri)
+ if component_profile.nil?
+ return rest_response(404, :reason => 'Component profile not found')
+ else
+ # Check for the given component profile in the set of families
+ families = families.select { |family| family.component_profile == component_profile }
+ end
+ end
+
+ # Authorization
+ families = families.select { |r| Authorization.check("view", r, opts[:user]) }
+
+ # Render results
+ produce_rest_list(opts[:uri], opts[:rules], opts[:query], families, "component-families", [], opts[:user])
+end
+
+
+##
+# Retrieve an XML representation of a component family
+def get_component_family(opts)
+ opts[:query]['all_elements'] = "yes"
+ rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
+ {'Model Entity' => 'pack',
+ 'Permission' => 'view'},
+ opts[:user], opts[:query])
+end
+
+
+##
+# Create a new component family
+def post_component_family(opts)
+ # Get the component profile
+ data = ""
+ component_profile_uri = parse_element(data, :text, '/pack/component-profile')
+
+ unless component_profile_uri
+ return rest_response(400, :reason => "Missing component profile URI")
+ end
+
+ component_profile = resource_from_uri(component_profile_uri)
+
+ if component_profile.nil?
+ return rest_response(404, :reason => "No component profile found at: #{component_profile_uri}")
+ elsif !component_profile.is_a?(Blob) && !component_profile.is_a?(BlobVersion)
+ return rest_response(400, :reason => "#{component_profile_uri} is not a valid component profile (not a file)")
+ elsif component_profile.content_type.mime_type != 'application/vnd.taverna.component-profile+xml'
+ return rest_response(400, :reason => "#{component_profile_uri} is not a valid component profile (wrong MIME type)")
+ end
+
+ # Create the component family
+ response = pack_aux('create', opts)
+
+ # Awful hack to get the newly created component family
+ family = resource_from_uri(response[:xml].find_first('//pack')['resource'])
+
+ # Add the profile
+ if component_profile.is_a?(Blob)
+ PackContributableEntry.create(:pack => family, :contributable => component_profile, :user => opts[:user])
+ elsif component_profile.is_a?(BlobVersion)
+ PackContributableEntry.create(:pack => family, :contributable => component_profile.blob,
+ :contributable_version => component_profile.version, :user => opts[:user])
+ end
+
+ # Add the tag
+ tag = Tag.find_or_create_by_name('component family')
+ Tagging.create(:tag => tag, :taggable => family, :user => opts[:user])
+
+ # Return resource
+ rest_get_request(family, opts[:user], { "id" => family.id.to_s })
+end
+
+
+##
+# Delete a component family and all components inside it
+def delete_component_family(opts)
+ # Find the family
+ id = opts[:query]['id']
+ family = Pack.find_by_id(id)
+ if family.nil? || !family.component_family?
+ return rest_response(404, :reason => "Couldn't find a valid component family with the given ID")
+ end
+
+ # Check if user has permission to delete the family
+ unless Authorization.check('destroy', family, opts[:user])
+ family.errors.add_to_base("You don't have permission to delete this component family.")
+ return rest_response(401, :object => family)
+ end
+
+ # Check if can delete ALL components in family
+ component_entries = family.contributable_entries.select { |e| e.contributable_type == 'Workflow' && e.contributable.component? }
+ components = component_entries.map { |e| e.contributable }
+ undeletable_components = components.select { |c| !Authorization.check('destroy', c, opts[:user]) }
+ if undeletable_components.size == 0
+ # Delete all components
+ components.each { |c| c.destroy }
+
+ # Delete family
+ family.destroy
+
+ rest_get_request(family, opts[:user], opts[:query])
+ else
+ family.errors.add_to_base("You don't have permission to delete #{undeletable_components.size} components in this component family.")
+ rest_response(401, :object => family)
+ end
+end
+
+
+##
+# Retrieve a list of component profiles
+def get_component_profiles(opts)
+ profiles = Blob.component_profiles
+
+ # Authorization
+ profiles = profiles.select { |r| Authorization.check("view", r, opts[:user]) }
+
+ # Render results
+ produce_rest_list(opts[:uri], opts[:rules], opts[:query], profiles, "component-profiles", [], opts[:user])
+end
+
+
+##
+# Retrieve a component profile
+def get_component_profile(opts)
+ rest_crud_request(opts[:req_uri], opts[:query]['id'], opts[:format],
+ {'Model Entity' => 'blob',
+ 'Permission' => 'view'},
+ opts[:user], opts[:query])
+end
+
+
+##
+# Create a new component profile
+def post_component_profile(opts)
+ response = file_aux('create', opts)
+
+ # Return error from creation attempt, if any
+ return response if response[:status] && response[:status][0] != '2'
+
+ # Awful hack to get the newly created profile object
+ profile = ""
+
+ # Add the tag
+ tag = Tag.find_or_create_by_name('component profile')
+ Tagging.create(:tag => tag, :taggable => profile, :user => opts[:user])
+
+ # Return resource
+ rest_get_request(profile, opts[:user], { "id" => profile.id.to_s })
+end
+
+
+##
+# Delete a component profile
+def delete_component_profile(opts)
+ # Find the profile
+ id = opts[:query]['id']
+ profile = ""
+ if profile.nil? || !profile.component_profile?
+ return rest_response(404, :reason => "Couldn't find a valid component profile with the given ID")
+ end
+
+ # Check if profile is used in any component families
+ families = PackContributableEntry.find_all_by_contributable_type_and_contributable_id('Blob', profile.id).select do |e|
+ e.pack.component_family?
+ end
+ if families.size == 0
+ # Delete profile
+ profile.destroy
+
+ rest_get_request(profile, opts[:user], opts[:query])
+ else
+ profile.errors.add_to_base("This component profile is used by #{families.size} component families and may not be deleted.")
+ rest_response(400, :object => profile)
+ end
+end
+
+private
+
+# Checks if a given URI is a resource from THIS application
+def internal_resource_uri?(uri)
+ uri = URI.parse(uri) if uri.is_a?(String)
+ base_uri = URI.parse(Conf.base_uri)
+
+ uri.relative? || uri.host == base_uri.host && uri.port == base_uri.port
+end
+
+# Gets an internal resource from a given URI
+def resource_from_uri(uri)
+ if uri.is_a?(String)
+ uri = URI.parse(uri)
+ end
+
+ resource = nil
+
+ if internal_resource_uri?(uri)
+ begin
+ route = ActionController::Routing::Routes.recognize_path(uri.path, :method => :get)
+ if route[:action] == "show"
+ resource = Object.const_get(route[:controller].camelize.singularize).find_by_id(route[:id].to_i)
+ else
+ nil
+ end
+
+ resource = resource.find_version(route[:version].to_i) if route[:version]
+ rescue ActionController::RoutingError
+ logger.warn("Unrecognized resource URI: #{uri}")
+ nil
+ rescue ActiveRecord::RecordNotFound
+ logger.warn("Couldn't find version #{route[:version]} for URI: #{uri}")
+ nil
+ end
+ end
+
+ resource
+end
Deleted: trunk/lib/api/resources/content_types.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/content_types.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/content_types.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,15 +0,0 @@
-# myExperiment: lib/api/resources/content_types.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def content_type_count(opts)
-
- root = LibXML::XML::Node.new('type-count')
- root << ContentType.count.to_s
-
- doc = LibXML::XML::Document.new
- doc.root = root
-
- { :xml => doc }
-end
Copied: trunk/lib/api/resources/content_types.rb (from rev 3683, branches/component-api/lib/api/resources/content_types.rb) (0 => 3685)
--- trunk/lib/api/resources/content_types.rb (rev 0)
+++ trunk/lib/api/resources/content_types.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,15 @@
+# myExperiment: lib/api/resources/content_types.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def content_type_count(opts)
+
+ root = LibXML::XML::Node.new('type-count')
+ root << ContentType.count.to_s
+
+ doc = LibXML::XML::Document.new
+ doc.root = root
+
+ { :xml => doc }
+end
Deleted: trunk/lib/api/resources/favourites.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/favourites.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/favourites.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,64 +0,0 @@
-# myExperiment: lib/api/resources/favourites.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def favourite_aux(action, opts)
-
- unless action == "destroy"
-
- data = ""
-
- target = parse_element(data, :resource, '/favourite/object')
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a favourite") unless Authorization.check('create', Bookmark, opts[:user], target)
-
- ob = Bookmark.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Bookmark', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- if target
- return rest_response(400, :reason => "Specified resource is not a valid favourite target") unless [Blob, Pack, Workflow].include?(target.class)
- return rest_response(401, :reason => "Not authorised to create the favourite") unless Authorization.check(action, Bookmark, opts[:user], target)
- ob.bookmarkable = target
- end
-
- success = ob.save
-
- if success
- Activity.create(:subject => current_user, :action ="" 'create', :objekt => ob)
- end
-
- return rest_response(400, :object => ob) unless success
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_favourite(opts)
- favourite_aux('create', opts)
-end
-
-def put_favourite(opts)
- favourite_aux('edit', opts)
-end
-
-def delete_favourite(opts)
- favourite_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/favourites.rb (from rev 3683, branches/component-api/lib/api/resources/favourites.rb) (0 => 3685)
--- trunk/lib/api/resources/favourites.rb (rev 0)
+++ trunk/lib/api/resources/favourites.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,64 @@
+# myExperiment: lib/api/resources/favourites.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def favourite_aux(action, opts)
+
+ unless action == "destroy"
+
+ data = ""
+
+ target = parse_element(data, :resource, '/favourite/object')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a favourite") unless Authorization.check('create', Bookmark, opts[:user], target)
+
+ ob = Bookmark.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Bookmark', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ if target
+ return rest_response(400, :reason => "Specified resource is not a valid favourite target") unless [Blob, Pack, Workflow].include?(target.class)
+ return rest_response(401, :reason => "Not authorised to create the favourite") unless Authorization.check(action, Bookmark, opts[:user], target)
+ ob.bookmarkable = target
+ end
+
+ success = ob.save
+
+ if success
+ Activity.create(:subject => current_user, :action ="" 'create', :objekt => ob)
+ end
+
+ return rest_response(400, :object => ob) unless success
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_favourite(opts)
+ favourite_aux('create', opts)
+end
+
+def put_favourite(opts)
+ favourite_aux('edit', opts)
+end
+
+def delete_favourite(opts)
+ favourite_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/networks.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/networks.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/networks.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,15 +0,0 @@
-# myExperiment: lib/api/resources/networks.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def group_count(opts)
-
- root = LibXML::XML::Node.new('group-count')
- root << Network.count.to_s
-
- doc = LibXML::XML::Document.new
- doc.root = root
-
- { :xml => doc }
-end
Copied: trunk/lib/api/resources/networks.rb (from rev 3683, branches/component-api/lib/api/resources/networks.rb) (0 => 3685)
--- trunk/lib/api/resources/networks.rb (rev 0)
+++ trunk/lib/api/resources/networks.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,15 @@
+# myExperiment: lib/api/resources/networks.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def group_count(opts)
+
+ root = LibXML::XML::Node.new('group-count')
+ root << Network.count.to_s
+
+ doc = LibXML::XML::Document.new
+ doc.root = root
+
+ { :xml => doc }
+end
Deleted: trunk/lib/api/resources/ontologies.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/ontologies.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/ontologies.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,60 +0,0 @@
-# myExperiment: lib/api/resources/ontologies.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def ontology_aux(action, opts)
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create an ontology") unless Authorization.check('create', Ontology, opts[:user], nil)
- ob = Ontology.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Ontology', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- data = ""
-
- title = parse_element(data, :text, '/ontology/title')
- description = parse_element(data, :text, '/ontology/description')
- uri = parse_element(data, :text, '/ontology/uri')
- prefix = parse_element(data, :text, '/ontology/prefix')
-
- # build the contributable
-
- ob.title = title if title
- ob.description = description if description
- ob.uri = uri if uri
- ob.prefix = prefix if prefix
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_ontology(opts)
- ontology_aux('create', opts)
-end
-
-def put_ontology(opts)
- ontology_aux('edit', opts)
-end
-
-def delete_ontology(opts)
- ontology_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/ontologies.rb (from rev 3683, branches/component-api/lib/api/resources/ontologies.rb) (0 => 3685)
--- trunk/lib/api/resources/ontologies.rb (rev 0)
+++ trunk/lib/api/resources/ontologies.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,60 @@
+# myExperiment: lib/api/resources/ontologies.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def ontology_aux(action, opts)
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create an ontology") unless Authorization.check('create', Ontology, opts[:user], nil)
+ ob = Ontology.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Ontology', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ data = ""
+
+ title = parse_element(data, :text, '/ontology/title')
+ description = parse_element(data, :text, '/ontology/description')
+ uri = parse_element(data, :text, '/ontology/uri')
+ prefix = parse_element(data, :text, '/ontology/prefix')
+
+ # build the contributable
+
+ ob.title = title if title
+ ob.description = description if description
+ ob.uri = uri if uri
+ ob.prefix = prefix if prefix
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_ontology(opts)
+ ontology_aux('create', opts)
+end
+
+def put_ontology(opts)
+ ontology_aux('edit', opts)
+end
+
+def delete_ontology(opts)
+ ontology_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/packs.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/packs.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/packs.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,243 +0,0 @@
-# myExperiment: lib/api/resources/packs.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def pack_aux(action, opts = {})
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a pack") unless Authorization.check('create', Pack, opts[:user], nil)
- if id = opts[:query]['id']
- ob = Pack.find_by_id(id)
- if ob.nil?
- return rest_response(404, :reason => "Couldn't find a Pack with id #{id}")
- else
- if Authorization.check('edit', ob, opts[:user])
- ob.snapshot!
- return rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
- else
- return rest_response(401, :reason => "Not authorised to snapshot pack #{id}")
- end
- end
- else
- ob = Pack.new(:contributor => opts[:user])
- end
-
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Pack', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- data = ""
-
- title = parse_element(data, :text, '/pack/title')
- description = parse_element(data, :text, '/pack/description')
-
- permissions = data.find_first('/pack/permissions')
-
- if license_type = parse_element(data, :text, '/pack/license-type')
- if license_type == ""
- ob.license = nil
- else
- ob.license = License.find_by_unique_name(license_type)
-
- if ob.license.nil?
- ob.errors.add("License type")
- return rest_response(400, :object => ob)
- end
- end
- end
-
- # build the contributable
-
- ob.title = title if title
- ob.description = description if description
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
-
- update_permissions(ob, permissions, opts[:user])
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_pack(opts)
- pack_aux('create', opts)
-end
-
-def put_pack(opts)
- pack_aux('edit', opts)
-end
-
-def delete_pack(opts)
- pack_aux('destroy', opts)
-end
-
-def pack_count(opts)
-
- packs = Pack.find(:all).select do |p|
- Authorization.check('view', p, opts[:user])
- end
-
- root = LibXML::XML::Node.new('pack-count')
- root << packs.length.to_s
-
- doc = LibXML::XML::Document.new
- doc.root = root
-
- { :xml => doc }
-end
-
-def external_pack_item_aux(action, opts = {})
-
- unless action == 'destroy'
-
- data = ""
-
- pack = parse_element(data, :resource, '/external-pack-item/pack')
- title = parse_element(data, :text, '/external-pack-item/title')
- uri = parse_element(data, :text, '/external-pack-item/uri')
- alternate_uri = parse_element(data, :text, '/external-pack-item/alternate-uri')
- comment = parse_element(data, :text, '/external-pack-item/comment')
- end
-
- # Obtain object
-
- case action
- when 'create';
-
- return rest_response(401, :reason => "Not authorised to create an external pack item") unless Authorization.check('create', PackRemoteEntry, opts[:user], pack)
- return rest_response(400, :reason => "Pack not found") if pack.nil?
- return rest_response(401, :reason => "Not authorised to change the specified pack") unless Authorization.check('edit', pack, opts[:user])
-
- ob = PackRemoteEntry.new(:user => opts[:user],
- :pack => pack,
- :title => title,
- :uri => uri,
- :alternate_uri => alternate_uri,
- :comment => comment)
-
- when 'view', 'edit', 'destroy';
-
- ob, error = obtain_rest_resource('PackRemoteEntry', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
-
- if ob
- return rest_response(401, :reason => "Not authorised to change the specified pack") unless Authorization.check('edit', ob.pack, opts[:user])
- end
-
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- ob.title = title if title
- ob.uri = uri if uri
- ob.alternate_uri = alternate_uri if alternate_uri
- ob.comment = comment if comment
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_external_pack_item(opts)
- external_pack_item_aux('create', opts)
-end
-
-def put_external_pack_item(opts)
- external_pack_item_aux('edit', opts)
-end
-
-def delete_external_pack_item(opts)
- external_pack_item_aux('destroy', opts)
-end
-
-def internal_pack_item_aux(action, opts = {})
-
- unless action == 'destroy'
-
- data = ""
-
- pack = parse_element(data, :resource, '/internal-pack-item/pack')
- item = parse_element(data, :resource, '/internal-pack-item/item')
- comment = parse_element(data, :text, '/internal-pack-item/comment')
-
- version_node = data.find_first('/internal-pack-item/item/@version')
- version = version_node ? version_node.value.to_i : nil
- end
-
- # Obtain object
-
- case action
- when 'create';
-
- return rest_response(401, :reason => "Not authorised to create an internal pack item") unless Authorization.check('create', PackContributableEntry, opts[:user], pack)
- return rest_response(400, :reason => "Pack not found") if pack.nil?
-
- ob = PackContributableEntry.new(:user => opts[:user],
- :pack => pack,
- :contributable => item,
- :comment => comment,
- :contributable_version => version)
-
- when 'view', 'edit', 'destroy';
-
- ob, error = obtain_rest_resource('PackContributableEntry', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
-
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- ob.comment = comment if comment
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_internal_pack_item(opts)
- internal_pack_item_aux('create', opts)
-end
-
-def put_internal_pack_item(opts)
- internal_pack_item_aux('edit', opts)
-end
-
-def delete_internal_pack_item(opts)
- internal_pack_item_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/packs.rb (from rev 3683, branches/component-api/lib/api/resources/packs.rb) (0 => 3685)
--- trunk/lib/api/resources/packs.rb (rev 0)
+++ trunk/lib/api/resources/packs.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,243 @@
+# myExperiment: lib/api/resources/packs.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def pack_aux(action, opts = {})
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a pack") unless Authorization.check('create', Pack, opts[:user], nil)
+ if id = opts[:query]['id']
+ ob = Pack.find_by_id(id)
+ if ob.nil?
+ return rest_response(404, :reason => "Couldn't find a Pack with id #{id}")
+ else
+ if Authorization.check('edit', ob, opts[:user])
+ ob.snapshot!
+ return rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+ else
+ return rest_response(401, :reason => "Not authorised to snapshot pack #{id}")
+ end
+ end
+ else
+ ob = Pack.new(:contributor => opts[:user])
+ end
+
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Pack', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ data = ""
+
+ title = parse_element(data, :text, '/pack/title')
+ description = parse_element(data, :text, '/pack/description')
+
+ permissions = data.find_first('/pack/permissions')
+
+ if license_type = parse_element(data, :text, '/pack/license-type')
+ if license_type == ""
+ ob.license = nil
+ else
+ ob.license = License.find_by_unique_name(license_type)
+
+ if ob.license.nil?
+ ob.errors.add("License type")
+ return rest_response(400, :object => ob)
+ end
+ end
+ end
+
+ # build the contributable
+
+ ob.title = title if title
+ ob.description = description if description
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+
+ update_permissions(ob, permissions, opts[:user])
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_pack(opts)
+ pack_aux('create', opts)
+end
+
+def put_pack(opts)
+ pack_aux('edit', opts)
+end
+
+def delete_pack(opts)
+ pack_aux('destroy', opts)
+end
+
+def pack_count(opts)
+
+ packs = Pack.find(:all).select do |p|
+ Authorization.check('view', p, opts[:user])
+ end
+
+ root = LibXML::XML::Node.new('pack-count')
+ root << packs.length.to_s
+
+ doc = LibXML::XML::Document.new
+ doc.root = root
+
+ { :xml => doc }
+end
+
+def external_pack_item_aux(action, opts = {})
+
+ unless action == 'destroy'
+
+ data = ""
+
+ pack = parse_element(data, :resource, '/external-pack-item/pack')
+ title = parse_element(data, :text, '/external-pack-item/title')
+ uri = parse_element(data, :text, '/external-pack-item/uri')
+ alternate_uri = parse_element(data, :text, '/external-pack-item/alternate-uri')
+ comment = parse_element(data, :text, '/external-pack-item/comment')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+
+ return rest_response(401, :reason => "Not authorised to create an external pack item") unless Authorization.check('create', PackRemoteEntry, opts[:user], pack)
+ return rest_response(400, :reason => "Pack not found") if pack.nil?
+ return rest_response(401, :reason => "Not authorised to change the specified pack") unless Authorization.check('edit', pack, opts[:user])
+
+ ob = PackRemoteEntry.new(:user => opts[:user],
+ :pack => pack,
+ :title => title,
+ :uri => uri,
+ :alternate_uri => alternate_uri,
+ :comment => comment)
+
+ when 'view', 'edit', 'destroy';
+
+ ob, error = obtain_rest_resource('PackRemoteEntry', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+
+ if ob
+ return rest_response(401, :reason => "Not authorised to change the specified pack") unless Authorization.check('edit', ob.pack, opts[:user])
+ end
+
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ ob.title = title if title
+ ob.uri = uri if uri
+ ob.alternate_uri = alternate_uri if alternate_uri
+ ob.comment = comment if comment
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_external_pack_item(opts)
+ external_pack_item_aux('create', opts)
+end
+
+def put_external_pack_item(opts)
+ external_pack_item_aux('edit', opts)
+end
+
+def delete_external_pack_item(opts)
+ external_pack_item_aux('destroy', opts)
+end
+
+def internal_pack_item_aux(action, opts = {})
+
+ unless action == 'destroy'
+
+ data = ""
+
+ pack = parse_element(data, :resource, '/internal-pack-item/pack')
+ item = parse_element(data, :resource, '/internal-pack-item/item')
+ comment = parse_element(data, :text, '/internal-pack-item/comment')
+
+ version_node = data.find_first('/internal-pack-item/item/@version')
+ version = version_node ? version_node.value.to_i : nil
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+
+ return rest_response(401, :reason => "Not authorised to create an internal pack item") unless Authorization.check('create', PackContributableEntry, opts[:user], pack)
+ return rest_response(400, :reason => "Pack not found") if pack.nil?
+
+ ob = PackContributableEntry.new(:user => opts[:user],
+ :pack => pack,
+ :contributable => item,
+ :comment => comment,
+ :contributable_version => version)
+
+ when 'view', 'edit', 'destroy';
+
+ ob, error = obtain_rest_resource('PackContributableEntry', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ ob.comment = comment if comment
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_internal_pack_item(opts)
+ internal_pack_item_aux('create', opts)
+end
+
+def put_internal_pack_item(opts)
+ internal_pack_item_aux('edit', opts)
+end
+
+def delete_internal_pack_item(opts)
+ internal_pack_item_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/policies.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/policies.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/policies.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,18 +0,0 @@
-# myExperiment: lib/api/resources/policies.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def get_policies(opts)
- policies = []
-
- if opts[:user].is_a?(User)
- if opts[:query]["type"] == 'group'
- policies = opts[:user].group_policies
- else
- policies = opts[:user].policies + opts[:user].group_policies
- end
- end
-
- produce_rest_list(opts[:uri], opts[:rules], opts[:query], policies, "policies", [], opts[:user])
-end
Copied: trunk/lib/api/resources/policies.rb (from rev 3683, branches/component-api/lib/api/resources/policies.rb) (0 => 3685)
--- trunk/lib/api/resources/policies.rb (rev 0)
+++ trunk/lib/api/resources/policies.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,18 @@
+# myExperiment: lib/api/resources/policies.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def get_policies(opts)
+ policies = []
+
+ if opts[:user].is_a?(User)
+ if opts[:query]["type"] == 'group'
+ policies = opts[:user].group_policies
+ else
+ policies = opts[:user].policies + opts[:user].group_policies
+ end
+ end
+
+ produce_rest_list(opts[:uri], opts[:rules], opts[:query], policies, "policies", [], opts[:user])
+end
Deleted: trunk/lib/api/resources/predicates.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/predicates.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/predicates.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,66 +0,0 @@
-# myExperiment: lib/api/resources/predicates.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def predicate_aux(action, opts)
-
- if action != "destroy"
-
- data = ""
-
- title = parse_element(data, :text, '/predicate/title')
- :resource, '/predicate/ontology')
- description = parse_element(data, :text, '/predicate/description')
- phrase = parse_element(data, :text, '/predicate/phrase')
- equivalent_to = parse_element(data, :text, '/predicate/equivalent-to')
-
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a predicate") unless Authorization.check('create', Predicate, opts[:user], ontology)
- ob = Predicate.new
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Predicate', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- # build it
-
- ob.title = title if title
- ob.description = description if description
- ob.phrase = phrase if phrase
- ob.equivalent_to = equivalent_to if equivalent_to
- ob. if ontology
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_predicate(opts)
- predicate_aux('create', opts)
-end
-
-def put_predicate(opts)
- predicate_aux('edit', opts)
-end
-
-def delete_predicate(opts)
- predicate_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/predicates.rb (from rev 3683, branches/component-api/lib/api/resources/predicates.rb) (0 => 3685)
--- trunk/lib/api/resources/predicates.rb (rev 0)
+++ trunk/lib/api/resources/predicates.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,66 @@
+# myExperiment: lib/api/resources/predicates.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def predicate_aux(action, opts)
+
+ if action != "destroy"
+
+ data = ""
+
+ title = parse_element(data, :text, '/predicate/title')
+ :resource, '/predicate/ontology')
+ description = parse_element(data, :text, '/predicate/description')
+ phrase = parse_element(data, :text, '/predicate/phrase')
+ equivalent_to = parse_element(data, :text, '/predicate/equivalent-to')
+
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a predicate") unless Authorization.check('create', Predicate, opts[:user], ontology)
+ ob = Predicate.new
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Predicate', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ # build it
+
+ ob.title = title if title
+ ob.description = description if description
+ ob.phrase = phrase if phrase
+ ob.equivalent_to = equivalent_to if equivalent_to
+ ob. if ontology
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_predicate(opts)
+ predicate_aux('create', opts)
+end
+
+def put_predicate(opts)
+ predicate_aux('edit', opts)
+end
+
+def delete_predicate(opts)
+ predicate_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/ratings.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/ratings.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/ratings.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,67 +0,0 @@
-# myExperiment: lib/api/resources/ratings.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def rating_aux(action, opts)
-
- unless action == "destroy"
-
- data = ""
-
- rating = parse_element(data, :text, '/rating/rating')
- subject = parse_element(data, :resource, '/rating/subject')
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a rating") unless Authorization.check('create', Rating, opts[:user], subject)
-
- ob = Rating.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Rating', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- ob.rating = rating if rating
-
- if subject
- return rest_response(400, :reason => "Specified resource does not support ratings") unless [Blob, Network, Pack, Workflow].include?(subject.class)
- return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Rating, opts[:user], subject)
- ob.rateable = subject
- end
-
- success = ob.save
-
- if success
- Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
- end
-
- return rest_response(400, :object => ob) unless success
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_rating(opts)
- rating_aux('create', opts)
-end
-
-def put_rating(opts)
- rating_aux('edit', opts)
-end
-
-def delete_rating(opts)
- rating_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/ratings.rb (from rev 3683, branches/component-api/lib/api/resources/ratings.rb) (0 => 3685)
--- trunk/lib/api/resources/ratings.rb (rev 0)
+++ trunk/lib/api/resources/ratings.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,67 @@
+# myExperiment: lib/api/resources/ratings.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def rating_aux(action, opts)
+
+ unless action == "destroy"
+
+ data = ""
+
+ rating = parse_element(data, :text, '/rating/rating')
+ subject = parse_element(data, :resource, '/rating/subject')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a rating") unless Authorization.check('create', Rating, opts[:user], subject)
+
+ ob = Rating.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Rating', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ ob.rating = rating if rating
+
+ if subject
+ return rest_response(400, :reason => "Specified resource does not support ratings") unless [Blob, Network, Pack, Workflow].include?(subject.class)
+ return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Rating, opts[:user], subject)
+ ob.rateable = subject
+ end
+
+ success = ob.save
+
+ if success
+ Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
+ end
+
+ return rest_response(400, :object => ob) unless success
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_rating(opts)
+ rating_aux('create', opts)
+end
+
+def put_rating(opts)
+ rating_aux('edit', opts)
+end
+
+def delete_rating(opts)
+ rating_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/relationships.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/relationships.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/relationships.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,63 +0,0 @@
-# myExperiment: lib/api/resources/relationships.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def relationship_aux(action, opts)
-
- if action != "destroy"
-
- data = ""
-
- subject = parse_element(data, :resource, '/relationship/subject')
- predicate = parse_element(data, :resource, '/relationship/predicate')
- objekt = parse_element(data, :resource, '/relationship/object')
- context = parse_element(data, :resource, '/relationship/context')
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a relationship") unless Authorization.check('create', Relationship, opts[:user], context)
- ob = Relationship.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Relationship', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- # build it
-
- ob.subject = subject if subject
- ob.predicate = predicate if predicate
- ob.objekt = objekt if objekt
- ob.context = context if context
-
- if not ob.save
- return rest_response(400, :object => ob)
- end
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_relationship(opts)
- relationship_aux('create', opts)
-end
-
-def put_relationship(opts)
- relationship_aux('edit', opts)
-end
-
-def delete_relationship(opts)
- relationship_aux('destroy', opts)
-end
Copied: trunk/lib/api/resources/relationships.rb (from rev 3683, branches/component-api/lib/api/resources/relationships.rb) (0 => 3685)
--- trunk/lib/api/resources/relationships.rb (rev 0)
+++ trunk/lib/api/resources/relationships.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,63 @@
+# myExperiment: lib/api/resources/relationships.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def relationship_aux(action, opts)
+
+ if action != "destroy"
+
+ data = ""
+
+ subject = parse_element(data, :resource, '/relationship/subject')
+ predicate = parse_element(data, :resource, '/relationship/predicate')
+ objekt = parse_element(data, :resource, '/relationship/object')
+ context = parse_element(data, :resource, '/relationship/context')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a relationship") unless Authorization.check('create', Relationship, opts[:user], context)
+ ob = Relationship.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Relationship', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ # build it
+
+ ob.subject = subject if subject
+ ob.predicate = predicate if predicate
+ ob.objekt = objekt if objekt
+ ob.context = context if context
+
+ if not ob.save
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_relationship(opts)
+ relationship_aux('create', opts)
+end
+
+def put_relationship(opts)
+ relationship_aux('edit', opts)
+end
+
+def delete_relationship(opts)
+ relationship_aux('destroy', opts)
+end
Deleted: trunk/lib/api/resources/taggings.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/taggings.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/taggings.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,116 +0,0 @@
-# myExperiment: lib/api/resources/taggings.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def tagging_aux(action, opts)
-
- unless action == "destroy"
-
- data = ""
-
- subject = parse_element(data, :resource, '/tagging/subject')
- label = parse_element(data, :text, '/tagging/label')
- tag = parse_element(data, :resource, '/tagging/tag')
- end
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a tagging") unless Authorization.check('create', Tagging, opts[:user], subject)
-
- ob = Tagging.new(:user => opts[:user])
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Tagging', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- ob.destroy
-
- else
-
- ob.label = label if label
- ob.tag = tag if tag
-
- if subject
- return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Tagging, opts[:user], subject)
- ob.taggable = subject
- end
-
- success = ob.save
-
- if success && action == "create"
- Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
- end
-
- return rest_response(400, :object => ob) unless success
- end
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_tagging(opts)
- tagging_aux('create', opts)
-end
-
-def delete_tagging(opts)
- tagging_aux('destroy', opts)
-end
-
-def get_tagged(opts)
-
- return rest_response(400, :reason => "Did not specify a tag") if opts[:query]['tag'].nil?
-
- tag = Tag.find_by_name(opts[:query]['tag'])
-
- obs = tag ? tag.tagged : []
-
- # filter out ones they are not allowed to get
- obs = (obs.select do |c| c.respond_to?('contribution') == false or Authorization.check("view", c, opts[:user]) end)
-
- produce_rest_list("tagged", opts[:rules], opts[:query], obs, 'tagged', [], opts[:user])
-end
-
-def tag_cloud(opts)
-
- num = 25
- type = nil
-
- if opts[:query]['num']
- if opts[:query]['num'] == 'all'
- num = nil
- else
- num = opts[:query]['num'].to_i
- end
- end
-
- if opts[:query]['type'] and opts[:query]['type'] != 'all'
- type = opts[:query]['type'].camelize
-
- type = 'Network' if type == 'Group'
- type = 'Blob' if type == 'File'
- end
-
- tags = Tag.find_by_tag_count(num, type)
-
- doc = LibXML::XML::Document.new()
-
- root = LibXML::XML::Node.new('tag-cloud')
- doc.root = root
-
- root['type'] = opts[:query]['type'] ? opts[:query]['type'] : 'all'
-
- tags.each do |tag|
- tag_node = rest_reference(tag, opts[:query])
- tag_node['count'] = tag.taggings_count.to_s
- root << tag_node
- end
-
- { :xml => doc }
-end
Copied: trunk/lib/api/resources/taggings.rb (from rev 3683, branches/component-api/lib/api/resources/taggings.rb) (0 => 3685)
--- trunk/lib/api/resources/taggings.rb (rev 0)
+++ trunk/lib/api/resources/taggings.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,116 @@
+# myExperiment: lib/api/resources/taggings.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def tagging_aux(action, opts)
+
+ unless action == "destroy"
+
+ data = ""
+
+ subject = parse_element(data, :resource, '/tagging/subject')
+ label = parse_element(data, :text, '/tagging/label')
+ tag = parse_element(data, :resource, '/tagging/tag')
+ end
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a tagging") unless Authorization.check('create', Tagging, opts[:user], subject)
+
+ ob = Tagging.new(:user => opts[:user])
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Tagging', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ ob.destroy
+
+ else
+
+ ob.label = label if label
+ ob.tag = tag if tag
+
+ if subject
+ return rest_response(401, :reason => "Not authorised for the specified resource") unless Authorization.check(action, Tagging, opts[:user], subject)
+ ob.taggable = subject
+ end
+
+ success = ob.save
+
+ if success && action == "create"
+ Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => subject)
+ end
+
+ return rest_response(400, :object => ob) unless success
+ end
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_tagging(opts)
+ tagging_aux('create', opts)
+end
+
+def delete_tagging(opts)
+ tagging_aux('destroy', opts)
+end
+
+def get_tagged(opts)
+
+ return rest_response(400, :reason => "Did not specify a tag") if opts[:query]['tag'].nil?
+
+ tag = Tag.find_by_name(opts[:query]['tag'])
+
+ obs = tag ? tag.tagged : []
+
+ # filter out ones they are not allowed to get
+ obs = (obs.select do |c| c.respond_to?('contribution') == false or Authorization.check("view", c, opts[:user]) end)
+
+ produce_rest_list("tagged", opts[:rules], opts[:query], obs, 'tagged', [], opts[:user])
+end
+
+def tag_cloud(opts)
+
+ num = 25
+ type = nil
+
+ if opts[:query]['num']
+ if opts[:query]['num'] == 'all'
+ num = nil
+ else
+ num = opts[:query]['num'].to_i
+ end
+ end
+
+ if opts[:query]['type'] and opts[:query]['type'] != 'all'
+ type = opts[:query]['type'].camelize
+
+ type = 'Network' if type == 'Group'
+ type = 'Blob' if type == 'File'
+ end
+
+ tags = Tag.find_by_tag_count(num, type)
+
+ doc = LibXML::XML::Document.new()
+
+ root = LibXML::XML::Node.new('tag-cloud')
+ doc.root = root
+
+ root['type'] = opts[:query]['type'] ? opts[:query]['type'] : 'all'
+
+ tags.each do |tag|
+ tag_node = rest_reference(tag, opts[:query])
+ tag_node['count'] = tag.taggings_count.to_s
+ root << tag_node
+ end
+
+ { :xml => doc }
+end
Deleted: trunk/lib/api/resources/users.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/users.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/users.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,17 +0,0 @@
-# myExperiment: lib/api/resources/users.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def user_count(opts)
-
- users = User.find(:all).select do |user| user.activated? end
-
- root = LibXML::XML::Node.new('user-count')
- root << users.length.to_s
-
- doc = LibXML::XML::Document.new
- doc.root = root
-
- { :xml => doc }
-end
Copied: trunk/lib/api/resources/users.rb (from rev 3683, branches/component-api/lib/api/resources/users.rb) (0 => 3685)
--- trunk/lib/api/resources/users.rb (rev 0)
+++ trunk/lib/api/resources/users.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,17 @@
+# myExperiment: lib/api/resources/users.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def user_count(opts)
+
+ users = User.find(:all).select do |user| user.activated? end
+
+ root = LibXML::XML::Node.new('user-count')
+ root << users.length.to_s
+
+ doc = LibXML::XML::Document.new
+ doc.root = root
+
+ { :xml => doc }
+end
Deleted: trunk/lib/api/resources/workflows.rb (3683 => 3685)
--- branches/component-api/lib/api/resources/workflows.rb 2013-09-06 13:07:03 UTC (rev 3683)
+++ trunk/lib/api/resources/workflows.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -1,204 +0,0 @@
-# myExperiment: lib/api/resources/workflows.rb
-#
-# Copyright (c) 2013 University of Manchester and the University of Southampton.
-# See license.txt for details.
-
-def workflow_aux(action, opts = {})
-
- # Obtain object
-
- case action
- when 'create';
- return rest_response(401, :reason => "Not authorised to create a workflow") unless Authorization.check('create', Workflow, opts[:user], nil)
- if opts[:query]['id']
- ob, error = obtain_rest_resource('Workflow', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- ob = Workflow.new(:contributor => opts[:user])
- end
- when 'view', 'edit', 'destroy';
- ob, error = obtain_rest_resource('Workflow', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
- else
- raise "Invalid action '#{action}'"
- end
-
- return error if ob.nil? # appropriate rest response already given
-
- if action == "destroy"
-
- return rest_response(400, :reason => "Cannot delete individual versions") if opts[:query]['version']
-
- ob.destroy
-
- else
-
- data = ""
-
- title = parse_element(data, :text, '/workflow/title')
- description = parse_element(data, :text, '/workflow/description')
- license_type = parse_element(data, :text, '/workflow/license-type')
- type = parse_element(data, :text, '/workflow/type')
- content_type = parse_element(data, :text, '/workflow/content-type')
- content = parse_element(data, :binary, '/workflow/content')
- preview = parse_element(data, :binary, '/workflow/preview')
- svg = parse_element(data, :text, '/workflow/svg')
- revision_comment = parse_element(data, :text, '/workflow/revision-comment')
-
- permissions = data.find_first('/workflow/permissions')
-
- # build the contributable
-
- if license_type
- if license_type == ""
- ob.license = nil
- else
- ob.license = License.find_by_unique_name(license_type)
-
- if ob.license.nil?
- ob.errors.add("License type")
- return rest_response(400, :object => ob)
- end
- end
- end
-
- # handle workflow type
-
- if type
-
- ob.content_type = ContentType.find_by_title(type)
-
- if ob.content_type.nil?
- ob.errors.add("Type")
- return rest_response(400, :object => ob)
- end
-
- elsif content_type
-
- content_types = ContentType.find_all_by_mime_type(content_type)
-
- if content_types.length == 1
- ob.content_type = content_types.first
- else
- if content_types.empty?
- ob.errors.add("Content type")
- else
- ob.errors.add("Content type", "matches more than one registered content type")
- end
-
- return rest_response(400, :object => ob)
- end
- end
-
- ob.content_blob_id = ContentBlob.create(:data ="" content).id if content
-
- # Handle versioned metadata. Priority:
- #
- # 1st = elements in REST request
- # 2nd = extracted metadata from workflow processor
- # 3rd = values from previous version
-
- metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
-
- if title
- ob.title = title
- elsif metadata["title"]
- ob.title = metadata["title"]
- end
-
- if description
- ob.body = description
- elsif metadata["description"]
- ob.body = metadata["description"]
- end
-
- # Handle the preview and svg images. If there's a preview supplied, use
- # it. Otherwise auto-generate one if we can.
-
- begin
- if preview.nil? and content
- metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
- preview = metadata["image"].read if metadata["image"]
- end
-
- if preview
- ob.image = preview
- end
-
- if svg.nil? and content
- metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
- svg = metadata["image"].read if metadata["image"]
- end
-
- if svg
- ob.svg = svg
- end
-
- rescue
- return rest_response(500, :reason => "Unable to extract metadata")
- end
-
- new_version = action == 'create' && opts[:query]['id'] != nil
- edit_version = action == 'edit' && opts[:query]['version'] != nil
-
- if new_version
- ob.preview = nil
- ob[:revision_comments] = revision_comment
- end
-
- success = ob.save
-
- if success
- case "#{action} #{new_version || edit_version}"
- when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
- when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
- when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
- when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.workflow)
- end
- end
-
- return rest_response(400, :object => ob) unless success
-
- # Elements to update if we're not dealing with a workflow version
-
- if opts[:query]['version'].nil?
- update_permissions(ob, permissions, opts[:user])
- end
-
- # Extract internals and stuff
- if ob.is_a?(WorkflowVersion)
- ob.workflow.extract_metadata
- else
- ob.extract_metadata
- end
- end
-
- ob = ob.versioned_resource if ob.respond_to?("versioned_resource")
-
- rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
-end
-
-def post_workflow(opts)
- workflow_aux('create', opts)
-end
-
-def put_workflow(opts)
- workflow_aux('edit', opts)
-end
-
-def delete_workflow(opts)
- workflow_aux('destroy', opts)
-end
-
-def workflow_count(opts)
-
- workflows = Workflow.find(:all).select do |w|
- Authorization.check('view', w, opts[:user])
- end
-
- root = LibXML::XML::Node.new('workflow-count')
- root << workflows.length.to_s
-
- doc = LibXML::XML::Document.new
- doc.root = root
-
- { :xml => doc }
-end
Copied: trunk/lib/api/resources/workflows.rb (from rev 3683, branches/component-api/lib/api/resources/workflows.rb) (0 => 3685)
--- trunk/lib/api/resources/workflows.rb (rev 0)
+++ trunk/lib/api/resources/workflows.rb 2013-09-06 13:43:32 UTC (rev 3685)
@@ -0,0 +1,204 @@
+# myExperiment: lib/api/resources/workflows.rb
+#
+# Copyright (c) 2013 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+def workflow_aux(action, opts = {})
+
+ # Obtain object
+
+ case action
+ when 'create';
+ return rest_response(401, :reason => "Not authorised to create a workflow") unless Authorization.check('create', Workflow, opts[:user], nil)
+ if opts[:query]['id']
+ ob, error = obtain_rest_resource('Workflow', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ ob = Workflow.new(:contributor => opts[:user])
+ end
+ when 'view', 'edit', 'destroy';
+ ob, error = obtain_rest_resource('Workflow', opts[:query]['id'], opts[:query]['version'], opts[:user], action)
+ else
+ raise "Invalid action '#{action}'"
+ end
+
+ return error if ob.nil? # appropriate rest response already given
+
+ if action == "destroy"
+
+ return rest_response(400, :reason => "Cannot delete individual versions") if opts[:query]['version']
+
+ ob.destroy
+
+ else
+
+ data = ""
+
+ title = parse_element(data, :text, '/workflow/title')
+ description = parse_element(data, :text, '/workflow/description')
+ license_type = parse_element(data, :text, '/workflow/license-type')
+ type = parse_element(data, :text, '/workflow/type')
+ content_type = parse_element(data, :text, '/workflow/content-type')
+ content = parse_element(data, :binary, '/workflow/content')
+ preview = parse_element(data, :binary, '/workflow/preview')
+ svg = parse_element(data, :text, '/workflow/svg')
+ revision_comment = parse_element(data, :text, '/workflow/revision-comment')
+
+ permissions = data.find_first('/workflow/permissions')
+
+ # build the contributable
+
+ if license_type
+ if license_type == ""
+ ob.license = nil
+ else
+ ob.license = License.find_by_unique_name(license_type)
+
+ if ob.license.nil?
+ ob.errors.add("License type")
+ return rest_response(400, :object => ob)
+ end
+ end
+ end
+
+ # handle workflow type
+
+ if type
+
+ ob.content_type = ContentType.find_by_title(type)
+
+ if ob.content_type.nil?
+ ob.errors.add("Type")
+ return rest_response(400, :object => ob)
+ end
+
+ elsif content_type
+
+ content_types = ContentType.find_all_by_mime_type(content_type)
+
+ if content_types.length == 1
+ ob.content_type = content_types.first
+ else
+ if content_types.empty?
+ ob.errors.add("Content type")
+ else
+ ob.errors.add("Content type", "matches more than one registered content type")
+ end
+
+ return rest_response(400, :object => ob)
+ end
+ end
+
+ ob.content_blob_id = ContentBlob.create(:data ="" content).id if content
+
+ # Handle versioned metadata. Priority:
+ #
+ # 1st = elements in REST request
+ # 2nd = extracted metadata from workflow processor
+ # 3rd = values from previous version
+
+ metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
+
+ if title
+ ob.title = title
+ elsif metadata["title"]
+ ob.title = metadata["title"]
+ end
+
+ if description
+ ob.body = description
+ elsif metadata["description"]
+ ob.body = metadata["description"]
+ end
+
+ # Handle the preview and svg images. If there's a preview supplied, use
+ # it. Otherwise auto-generate one if we can.
+
+ begin
+ if preview.nil? and content
+ metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
+ preview = metadata["image"].read if metadata["image"]
+ end
+
+ if preview
+ ob.image = preview
+ end
+
+ if svg.nil? and content
+ metadata = Workflow.extract_metadata(:type => ob.content_type.title, :data ="" content)
+ svg = metadata["image"].read if metadata["image"]
+ end
+
+ if svg
+ ob.svg = svg
+ end
+
+ rescue
+ return rest_response(500, :reason => "Unable to extract metadata")
+ end
+
+ new_version = action == 'create' && opts[:query]['id'] != nil
+ edit_version = action == 'edit' && opts[:query]['version'] != nil
+
+ if new_version
+ ob.preview = nil
+ ob[:revision_comments] = revision_comment
+ end
+
+ success = ob.save
+
+ if success
+ case "#{action} #{new_version || edit_version}"
+ when "create false"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob, :auth => ob)
+ when "create true"; Activity.create(:subject => opts[:user], :action ="" 'create', :objekt => ob.versions.last, :auth => ob)
+ when "edit false"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :auth => ob)
+ when "edit true"; Activity.create(:subject => opts[:user], :action ="" 'edit', :objekt => ob, :extra => ob.version, :auth => ob.workflow)
+ end
+ end
+
+ return rest_response(400, :object => ob) unless success
+
+ # Elements to update if we're not dealing with a workflow version
+
+ if opts[:query]['version'].nil?
+ update_permissions(ob, permissions, opts[:user])
+ end
+
+ # Extract internals and stuff
+ if ob.is_a?(WorkflowVersion)
+ ob.workflow.extract_metadata
+ else
+ ob.extract_metadata
+ end
+ end
+
+ ob = ob.versioned_resource if ob.respond_to?("versioned_resource")
+
+ rest_get_request(ob, opts[:user], { "id" => ob.id.to_s })
+end
+
+def post_workflow(opts)
+ workflow_aux('create', opts)
+end
+
+def put_workflow(opts)
+ workflow_aux('edit', opts)
+end
+
+def delete_workflow(opts)
+ workflow_aux('destroy', opts)
+end
+
+def workflow_count(opts)
+
+ workflows = Workflow.find(:all).select do |w|
+ Authorization.check('view', w, opts[:user])
+ end
+
+ root = LibXML::XML::Node.new('workflow-count')
+ root << workflows.length.to_s
+
+ doc = LibXML::XML::Document.new
+ doc.root = root
+
+ { :xml => doc }
+end