myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3620] branches/packs: added call to Wf-RO servic


From: noreply
Subject: [myexperiment-hackers] [3620] branches/packs: added call to Wf-RO service
Date: Tue, 13 Aug 2013 13:11:02 +0000 (UTC)

Revision
3620
Author
dgc
Date
2013-08-13 13:11:01 +0000 (Tue, 13 Aug 2013)

Log Message

added call to Wf-RO service

Modified Paths

Diff

Modified: branches/packs/Gemfile (3619 => 3620)


--- branches/packs/Gemfile	2013-08-13 13:07:10 UTC (rev 3619)
+++ branches/packs/Gemfile	2013-08-13 13:11:01 UTC (rev 3620)
@@ -30,4 +30,5 @@
 gem "open_id_authentication", "~> 1.1.0"
 gem "simple-rss", "~> 1.2.3"
 gem "net-http-persistent", "~> 2.8"
+gem "wf4ever-transformation-client", "~> 0.3.0"
 

Modified: branches/packs/app/controllers/packs_controller.rb (3619 => 3620)


--- branches/packs/app/controllers/packs_controller.rb	2013-08-13 13:07:10 UTC (rev 3619)
+++ branches/packs/app/controllers/packs_controller.rb	2013-08-13 13:11:01 UTC (rev 3620)
@@ -3,6 +3,8 @@
 # Copyright (c) 2007 University of Manchester and the University of Southampton.
 # See license.txt for details.
 
+require 'wf4ever/transformation-client'
+
 class PacksController < ApplicationController
   include ApplicationHelper
   include ResearchObjectsHelper
@@ -10,6 +12,7 @@
   ## NOTE: URI must match config/default_settings.yml ro_resource_types
   WORKFLOW_DEFINITION = "http://purl.org/wf4ever/wfdesc#WorkflowDefinition"
   RO_RESOURCE = "http://purl.org/wf4ever/ro#Resource"
+  WORKFLOW_RUN = "http://purl.org/wf4ever/roterms#WorkflowRunBundle"
 
   before_filter :login_required, :except => [:index, :show, :search, :items, :download, :statistics]
   
@@ -407,7 +410,7 @@
             resource_uri = entry.uri
           end
           
-          post_process_created_resource(@pack, resource_uri, params)
+          post_process_created_resource(@pack, entry, resource_uri, params)
 
           flash[:notice] = 'Item succesfully added to pack.'
           format.html { redirect_to pack_url(@pack) }
@@ -561,28 +564,77 @@
     end
   end
 
+  def annotate_resources(resource_uris, body_graph, content_type = 'application/rdf+xml')
+    @pack.research_object.create_annotation(
+        :body_graph   => body_graph,
+        :content_type => content_type,
+        :resources    => resource_uris,
+        :creator_uri  => "/users/#{current_user.id}")
+  end
+
   def annotate_resource_type(resource_uri, type_uri)
 
     body = RDF::Graph.new
     body << [RDF::URI(resource_uri), RDF.type, RDF::URI(type_uri)]
 
-    @pack.research_object.create_annotation(:body_graph => body, :resources => [resource_uri], :creator_uri => "/users/#{current_user.id}")
+    annotate_resources([resource_uri], body)
   end
 
-  def post_process_created_resource(pack, resource_uri, params)
+  def transform_wf(resource_uri)
+      format = "application/vnd.taverna.t2flow+xml"
+      token = Conf.wf_ro_service_bearer_token
+      uri = Wf4Ever::TransformationClient.create_job(Conf.wf_ro_service_uri, resource_uri.to_s, format, @pack.research_object.uri, token)
+puts "      [Conf.wf_ro_service_uri, resource_uri, format, @pack.research_object.uri, token] = #{      [Conf.wf_ro_service_uri, resource_uri, format, @pack.research_object.uri, token].inspect}"
+      puts "################## Transforming at " + uri
 
+      uri
+  end
+  
+  def post_process_workflow_run(entry, resource_uri)
+
+    # FIXME this should work with externals too
+    return unless entry.kind_of?(PackContributableEntry)
+
+    bundle_content = entry.contributable.content_blob.data
+
+    begin
+      zip_file = Tempfile.new('workflow_run.zip.')
+      zip_file.binmode
+      zip_file.write(bundle_content)
+      zip_file.close
+      
+      Zip::ZipFile.open(zip_file.path) { |zip|
+
+        wfdesc = zip.get_entry(".ro/annotations/workflow.wfdesc.ttl").get_input_stream.read
+        wfprov = zip.get_entry("workflowrun.prov.ttl").get_input_stream.read
+
+        annotate_resources([resource_uri], wfdesc, 'text/turtle')
+        annotate_resources([resource_uri], wfprov, 'text/turtle')
+      }
+
+    rescue
+      raise unless Rails.env == "production"
+    end
+  end
+
+  def post_process_created_resource(pack, entry, resource_uri, params)
+
     ro = pack.research_object
 
     config = Conf.ro_resource_types.select { |x| x["uri"] == params[:type] }.first
 
-#   if params[:type] == WORKFLOW_DEFINITION
-#     result = transform_wf(ruri)
-#   end
+    if params[:type] == WORKFLOW_DEFINITION
+      job_uri = transform_wf(resource_uri)
+    end
 
     if params[:type] != RO_RESOURCE
       annotate_resource_type(resource_uri, params[:type])
     end
 
+    if params[:type] == WORKFLOW_RUN
+      post_process_workflow_run(entry, resource_uri)
+    end
+
     # Folder selection is performed on the following with decreasing order of
     # priority.
     #

Modified: branches/packs/app/models/research_object.rb (3619 => 3620)


--- branches/packs/app/models/research_object.rb	2013-08-13 13:07:10 UTC (rev 3619)
+++ branches/packs/app/models/research_object.rb	2013-08-13 13:11:01 UTC (rev 3620)
@@ -330,6 +330,7 @@
 
     # FIXME - these should be validations on the resource model
     throw "body_graph required"   unless opts[:body_graph]
+    throw "content_type required" unless opts[:content_type]
     throw "resources required"    unless opts[:resources]
     throw "creator_uri required"  unless opts[:creator_uri]
     
@@ -345,9 +346,9 @@
     # Create an annotation body using the provided graph
 
     ao_body = create_aggregated_resource(
-      :path         => calculate_path(opts[:slug], 'application/rdf+xml'),
+      :path         => calculate_path(opts[:slug], opts[:content_type]),
       :data         ="" data,
-      :content_type => "application/rdf+xml",
+      :content_type => opts[:content_type],
       :user_uri     => opts[:creator_uri])
 
     stub = create_annotation_stub(
@@ -357,6 +358,8 @@
 
     stub.update_graph!
 
+    update_manifest!
+
     stub
 
   end

Modified: branches/packs/app/views/packs/show.rhtml (3619 => 3620)


--- branches/packs/app/views/packs/show.rhtml	2013-08-13 13:07:10 UTC (rev 3619)
+++ branches/packs/app/views/packs/show.rhtml	2013-08-13 13:11:01 UTC (rev 3620)
@@ -161,12 +161,14 @@
           <tr>
             <th>Path</th>
             <th>Size</th>
+            <th>Content type</th>
             <th>Annotations</th>
           </tr>
           <% @pack.research_object.resources.each do |resource| %>
             <tr>
               <td><%=h resource.path -%></td>
               <td><%=h resource.size -%></td>
+              <td><%=h resource.content_type -%></td>
               <td><%=h resource.annotations.count -%></td>
             </tr>
           <% end %>

Modified: branches/packs/config/default_settings.yml (3619 => 3620)


--- branches/packs/config/default_settings.yml	2013-08-13 13:07:10 UTC (rev 3619)
+++ branches/packs/config/default_settings.yml	2013-08-13 13:11:01 UTC (rev 3620)
@@ -1494,3 +1494,6 @@
     required_statements:
     - [:resource1, "<http://purl.org/wf4ever/roterms#inputSelected>", :resource2]
 
+wf_ro_service_uri: "http://www.example.com/wf-ro/jobs"
+wf_ro_service_bearer_token: "bearer-token"
+

reply via email to

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