myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [3217] branches/components/lib: Added ability to


From: noreply
Subject: [myexperiment-hackers] [3217] branches/components/lib: Added ability to share with groups in the REST API
Date: Mon, 3 Dec 2012 11:54:09 +0000 (UTC)

Revision
3217
Author
fbacall
Date
2012-12-03 11:54:08 +0000 (Mon, 03 Dec 2012)

Log Message

Added ability to share with groups in the REST API

Modified Paths

Diff

Modified: branches/components/lib/rest.rb (3216 => 3217)


--- branches/components/lib/rest.rb	2012-11-28 11:12:18 UTC (rev 3216)
+++ branches/components/lib/rest.rb	2012-12-03 11:54:08 UTC (rev 3217)
@@ -955,21 +955,44 @@
 
       # handle public privileges
 
-      if permission.find_first('category/text()').to_s == 'public'
+      case permission.find_first('category/text()').to_s
+        when 'public'
+          privileges = {}
 
-        privileges = {}
+          permission.find('privilege').each do |el|
+            privileges[el['type']] = true
+          end
 
-        permission.find('privilege').each do |el|
-          privileges[el['type']] = true
-        end
+          if privileges["view"] && privileges["download"]
+            share_mode = 0
+          elsif privileges["view"]
+            share_mode = 2
+          else
+            share_mode = 7
+          end
+        when 'group'
+          id = permission.find_first('id/text()').to_s.to_i
+          privileges = {}
 
-        if privileges["view"] && privileges["download"]
-          share_mode = 0
-        elsif privileges["view"]
-          share_mode = 2
-        else
-          share_mode = 7
-        end
+          permission.find('privilege').each do |el|
+            privileges[el['type']] = true
+          end
+
+          network = Network.find_by_id(id)
+          if network.nil?
+            ob.errors.add_to_base("Couldn't share with group #{id} - Not found")
+            raise
+          else
+            Permission.create(:contributor => network,
+                              :policy => ob.contribution.policy,
+                              :view => privileges["view"],
+                              :download => privileges["download"],
+                              :edit => privileges["edit"])
+            unless (use_layout = permission.find_first('use-layout/text()')).nil?
+              ob.contribution.layout = network.layout_name if use_layout.to_s == 'true'
+              ob.contribution.save
+            end
+          end
       end
     end
 
@@ -2296,16 +2319,13 @@
 
 # Component Querying
 def get_components(opts)
-  puts "\n" * 10
-
   query = opts[:query]
-  puts query.inspect
 
-  annotations = (query['hasAnnotations'] || "").split('","').collect {|a| a.gsub('"','')} # annotations on workflow itself
+  annotations = (query['annotations'] || "").split('","').collect {|a| a.gsub('"','')} # annotations on workflow itself
   # annotations on workflow features
-  inputs = query["hasInput"] || {}#(query["inputs"] || "").split('),')
-  outputs = query["hasOutput"] || {} #(query["outputs"] || "").split('),')
-  processors = query["hasProcessor"] || {} #(query["processors"] || "").split('),')
+  inputs = query["input"] || {}#(query["inputs"] || "").split('),')
+  outputs = query["output"] || {} #(query["outputs"] || "").split('),')
+  processors = query["processor"] || {} #(query["processors"] || "").split('),')
 
 
   workflows = Workflow.all # This should be filtered first
@@ -2323,7 +2343,6 @@
       raise "Bad Syntax" unless set =~ /^("[^ ]+ [^"]+")(,"[^ ]+ [^"]+")*$/
 
       feature_annotations = set.split('","').collect {|a| a.gsub('"','')}
-      puts feature_annotations.inspect
       # "<ann1>", "<ann2>" (example)
       matching_features = feature_annotations.collect { |a|
         # Find all <features> with semantic annotation "<predicate> <object>" (example)
@@ -2379,11 +2398,6 @@
             matches_processor_requirements +
             matches_semantic_annotation_requirements
 
-  puts "\n" * 10
-  puts "Pre Matches:"
-  puts matches.inspect
-  puts "\n" * 10
-
   # Workflows that match ALL the requirements - the intersection of all the sub arrays.
   matches = matches.inject {|matches, matches_all| matches_all & matches}
 

Modified: branches/components/lib/workflow_processors/taverna2.rb (3216 => 3217)


--- branches/components/lib/workflow_processors/taverna2.rb	2012-11-28 11:12:18 UTC (rev 3216)
+++ branches/components/lib/workflow_processors/taverna2.rb	2012-12-03 11:54:08 UTC (rev 3217)
@@ -404,13 +404,17 @@
     end
 
     def create_semantic_annotations(subject, semantic_annotations)
-      g = RDF::Graph.new
-      g << RDF::Reader.for(:n3).new(semantic_annotations)
+      if semantic_annotations.type == "text/rdf+n3"
+        g = RDF::Graph.new
+        g << RDF::Reader.for(:n3).new(semantic_annotations.content)
 
-      g.each_statement do |statement|
-        predicate = statement.predicate.to_s
-        object = statement.object.to_s
-        SemanticAnnotation.create(:subject => subject, :predicate => predicate, :object => object)
+        g.each_statement do |statement|
+          predicate = statement.predicate.to_s
+          object = statement.object.to_s
+          SemanticAnnotation.create(:subject => subject, :predicate => predicate, :object => object)
+        end
+      else
+        raise "Unsupported annotation content type (#{semantic_annotations.type}) for #{subject}."
       end
     end
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]