myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3205] branches/wf4ever: added ro support to work


From: noreply
Subject: [myexperiment-hackers] [3205] branches/wf4ever: added ro support to workflows with annotation editor
Date: Mon, 26 Nov 2012 14:22:26 +0000 (UTC)

Revision
3205
Author
dgc
Date
2012-11-26 14:22:26 +0000 (Mon, 26 Nov 2012)

Log Message

added ro support to workflows with annotation editor

Modified Paths

Diff

Modified: branches/wf4ever/app/controllers/workflows_controller.rb (3204 => 3205)


--- branches/wf4ever/app/controllers/workflows_controller.rb	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/app/controllers/workflows_controller.rb	2012-11-26 14:22:26 UTC (rev 3205)
@@ -3,6 +3,9 @@
 # Copyright (c) 2007 University of Manchester and the University of Southampton.
 # See license.txt for details.
 
+require 'rdf'
+require 'wf4ever/rosrs_client'
+
 class WorkflowsController < ApplicationController
 
   include ApplicationHelper
@@ -19,7 +22,7 @@
   before_filter :check_file_size, : [:create, :create_version]
   before_filter :check_custom_workflow_type, : [:create, :create_version]
   
-  before_filter :check_is_owner, : [:edit, :update]
+  before_filter :check_is_owner, : [:edit, :update, :edit_annotations, :update_annotations]
 
   # declare sweepers and which actions should invoke them
   cache_sweeper :workflow_sweeper, : [ :create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
@@ -230,6 +233,11 @@
   
   # GET /workflows/1
   def show
+
+    session = ROSRS::Session.new(@workflow.ro_uri, Conf.rodl_bearer_token)
+
+    @annotations = session.get_annotation_graph(@workflow.ro_uri, workflow_url(@workflow))
+
     if allow_statistics_logging(@viewing_version)
       @viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
     end
@@ -666,6 +674,65 @@
     render :partial => 'contributions/autocomplete_list', :locals => { :contributions => wfs }
   end
 
+  def edit_annotations
+
+    session = ROSRS::Session.new(@workflow.ro_uri, Conf.rodl_bearer_token)
+
+    @annotations = session.get_annotation_graphs(@workflow.ro_uri, workflow_url(@workflow))
+  end
+
+  def update_annotations
+     
+    session = ROSRS::Session.new(@workflow.ro_uri, Conf.rodl_bearer_token)
+
+    resource_uri = workflow_url(@workflow)
+
+    if params[:commit] == 'Add' || params[:commit] == 'Edit'
+
+      case params[:template]
+      when "Title"
+        ao_body = @workflow.create_annotation_body(resource_uri,
+            LibXML::XML::Node.new('dct:title', params[:value]),
+            { "dct" => "http://purl.org/dc/terms/" })
+      when "Creator"
+        ao_body = @workflow.create_annotation_body(resource_uri,
+            LibXML::XML::Node.new('dct:creator', params[:value]),
+            { "dct" => "http://purl.org/dc/terms/" })
+      when "Contributor"
+        ao_body = @workflow.create_annotation_body(resource_uri,
+            LibXML::XML::Node.new('dct:contributor', params[:value]),
+            { "dct" => "http://purl.org/dc/terms/" })
+      when "Description"
+        ao_body = @workflow.create_annotation_body(resource_uri,
+            LibXML::XML::Node.new('dct:description', params[:value]),
+            { "dct" => "http://purl.org/dc/terms/" })
+      end
+    end
+
+    if params[:commit] == 'Add'
+      if ao_body
+        agraph = ROSRS::RDFGraph.new(:data ="" ao_body.to_s, :format => :xml)
+
+        code, reason, stub_uri, body_uri = session.create_internal_annotation(@workflow.ro_uri, resource_uri, agraph)
+      end
+    end
+
+    if params[:commit] == 'Edit'
+      if ao_body
+        agraph = ROSRS::RDFGraph.new(:data ="" ao_body.to_s, :format => :xml)
+
+        c, r, body_uri = session.update_internal_annotation(@workflow.ro_uri, params[:stub_uri], resource_uri, agraph)
+      end
+    end
+
+    if params[:commit] == 'Delete'
+      c, r, h, d = session.do_request("DELETE", params[:stub_uri], {} )
+      c, r, h, d = session.do_request("DELETE", params[:body_uri], {} )
+    end
+
+    redirect_to edit_annotations_workflow_path(@workflow)
+  end
+
 protected
 
   def store_callback
@@ -704,6 +771,7 @@
       "destroy_version"         => "edit",
       "download"                => "download",
       "edit"                    => "edit",
+      "edit_annotations"        => "edit",
       "edit_version"            => "edit",
       "favourite"               => "view",
       "favourite_delete"        => "view",
@@ -722,6 +790,7 @@
       "tag"                     => "view",
       "tag_suggestions"         => "view",
       "update"                  => "edit",
+      "update_annotations"      => "edit",
       "update_version"          => "edit",
     }
 

Modified: branches/wf4ever/app/models/workflow.rb (3204 => 3205)


--- branches/wf4ever/app/models/workflow.rb	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/app/models/workflow.rb	2012-11-26 14:22:26 UTC (rev 3205)
@@ -15,6 +15,9 @@
 require 'scufl/model'
 require 'scufl/parser'
 
+require 'rdf'
+require 'wf4ever/rosrs_client'
+
 class Workflow < ActiveRecord::Base
   
   has_many :citations, 
@@ -340,4 +343,74 @@
     APIStatistics.statistics(self)
   end
 
+  def create_annotation_body(resource_uri, body, namespaces)
+
+    namespaces["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+
+    doc = LibXML::XML::Document.new
+    doc.root = LibXML::XML::Node.new("rdf:RDF")
+    doc.root["xml:base"] = ro_uri
+
+    namespaces.each do |name, uri|
+      doc.root["xmlns:#{name}"] = uri
+    end
+
+    description = LibXML::XML::Node.new("rdf:Description")
+    description["rdf:about"] = resource_uri
+    description << body
+    doc.root << description
+
+    doc
+  end
+
+  def set_simple_annotation(resource_uri, predicate, namespaces, term, new_value)
+
+    session = ROSRS::Session.new(ro_uri, Conf.rodl_bearer_token)
+
+    # Remove existing annotations of the same structure
+
+    annotations = session.get_annotation_graphs(ro_uri, resource_uri)
+
+    annotations.each do |annotation|
+
+      next unless annotation[:body].count == 1
+      next unless annotation[:body].query(:predicate => predicate).count == 1
+
+      c, r, h, d = session.do_request("DELETE", annotation[:stub], {} )
+      c, r, h, d = session.do_request("DELETE", annotation[:body_uri], {} )
+    end
+
+    # Create the new annotation
+
+    annotation_body = create_annotation_body(resource_uri,
+        LibXML::XML::Node.new(term, new_value),
+        namespaces)
+
+    agraph = ROSRS::RDFGraph.new(:data ="" annotation_body.to_s, :format => :xml)
+
+    code, reason, stub_uri, body_uri = session.create_internal_annotation(ro_uri, resource_uri, agraph)
+  end
+
+  def get_simple_annotations(annotations, predicate)
+    annotations.select do |annotation|
+      annotation[:body].count == 1 && annotation[:body].query(:predicate => predicate).count == 1
+    end
+  end
+
+  def set_dc_title(resource_uri, value)
+    set_simple_annotation(resource_uri,
+        RDF::DC.title,
+        { "dct" => "http://purl.org/dc/terms/" },
+        "dct:title",
+        value)
+  end
+
+  def set_dc_description(resource_uri, value)
+    set_simple_annotation(resource_uri,
+        RDF::DC.description,
+        { "dct" => "http://purl.org/dc/terms/" },
+        "dct:description",
+        value)
+  end
+
 end

Modified: branches/wf4ever/app/views/workflows/show.rhtml (3204 => 3205)


--- branches/wf4ever/app/views/workflows/show.rhtml	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/app/views/workflows/show.rhtml	2012-11-26 14:22:26 UTC (rev 3205)
@@ -1,5 +1,8 @@
-<% t "#{h @workflow.title} (#{h @workflow.contributor_name}) [#{h(@workflow.type_display_name)} Workflow]" -%>
+<% title = @workflow.title %>
+<% @annotations.query([RDF::URI.parse(workflow_url(@workflow)), RDF::DC.title, nil]).each do |s, p, o| title = o.to_s end %>
 
+<% t "#{h title} (#{h @workflow.contributor_name}) [#{h(@workflow.type_display_name)} Workflow]" -%>
+
 <ul class="sectionIcons">
 	<% if @authorised_to_edit -%>
 		<li><%= icon('new', new_version_workflow_path(@workflow), nil, nil, 'Upload New Version')%></li>
@@ -15,7 +18,7 @@
 </ul>
 
 <h1 class="contribution_title">
-	Workflow Entry: <%=h @workflow.title %>
+	Workflow Entry: <%=h title %>
 </h1>
 
 <%= render :partial => "contributions/datetime_info", :locals => { :contributable => @workflow } -%>
@@ -79,7 +82,7 @@
 		<div class="contribution_version_inner_box">
 			<p>
 				<b>Title:</b>
-				<span class="title"><%= h @viewing_version.title %></span>
+				<span class="title"><%= h title %></span>
 			</p>
 			
 			<p>
@@ -89,16 +92,29 @@
 			
 			<br/>
 			
+      <% creators     = @annotations.query([RDF::URI.parse(workflow_url(@workflow)), RDF::DC.creator, nil]) %>
+      <% contributors = @annotations.query([RDF::URI.parse(workflow_url(@workflow)), RDF::DC.contributor, nil]) %>
+
+      <% if creators.count > 0 || contributors.count > 0 %>
+
+        <h3>
+          <%= info_icon_with_tooltip("This section shows the creators and contributors of the Workflow") %>
+          Credit
+        </h3>
+			
+        <ul>
+          <% creators.each do |s, p, o| %><li><%=h o.to_s -%> (creator)</li><% end %>
+          <% contributors.each do |s, p, o| %><li><%=h o.to_s -%> (contributor)</li><% end %>
+        </ul>
+      <% end %>
+
 			<h3>
 				<%= info_icon_with_tooltip("This section shows the preview of this version of the Workflow (click on the image to expand)") %>
 				Preview
 			</h3>
 			
 			<% unless @viewing_version.image.nil? && @viewing_version.svg.nil? %>
-				<p style="font-size: 85%; font-weight: normal; margin-bottom: 0.5em; text-align: center;">
-					 (Click on the image to get the full size)
-				</p>
-				<div class="contribution_preview" style="width: 100%;">
+				<div class="contribution_preview" style="width: 100px;">
 					<center>
 						<%= link_to image_tag(workflow_version_preview_path(@workflow, @viewing_version.version, 'medium')), workflow_version_preview_path(@workflow, @viewing_version.version, 'full'), :popup => true %>
 					</center>
@@ -117,35 +133,108 @@
 			<% end %>
 			
 			<br/>
-			
-			<% unless @viewing_version.svg.nil? %>
-				<ul class="sectionIcons">
-					<li style="margin-left: 0;"><%= icon('picture', workflow_version_preview_path(@workflow, @viewing_version.version, 'svg'), nil, nil, 'Download Scalable Diagram (SVG)') %></li>
-				</ul>
-			<% end %>
-			
-			<br/>
-			
+
 			<h3>
 				<%= info_icon_with_tooltip("This section shows the overall description for this version of the Workflow") %>
 				Description
 			</h3>
 			
-			<% unless @viewing_version.body.blank? %>
+      <% @annotations.query([RDF::URI.parse(workflow_url(@workflow)), RDF::DC.description, nil]).each do |s, p, o| %>
 				<div class="contribution_description">
-					<%= @viewing_version.body_html %>
+					<p><%=h o.to_s %></p>
 				</div>
-				<% if @authorised_to_edit %>
-					<p style="text-align: right; color: #666666;">[ <%= link_to "edit", workflow_version_edit_url(@workflow.id, @viewing_version.version) %> ]</p>
-				<% end %>
-			<% else %>
-				<p class="none_text">
-					Not set
-				</p>
-			<% end %>
-			
+      <% end %>
+
+      <% subjects = @annotations.query([RDF::URI.parse(workflow_url(@workflow)), RDF::DC.subject, nil]) %>
+
+      <% if subjects.count > 0 %>
+        <div class="tag_list">
+          <ul>
+            <% subjects.each do |s, p, o| %>
+              <li><%=h o.to_s -%></li>
+            <% end %>
+          </ul>
+        </div>
+      <% end %>
+
 			<br/>
-			
+
+      <h3>
+				<%= info_icon_with_tooltip("This section provides example data sets (workflow inputs and outputs) to this workflow") %>
+        Example data sets
+      </h3>
+
+<%
+workflow_uri = RDF::URI.parse(workflow_url(@workflow))
+
+inputs = RDF::Query.new do
+  pattern [workflow_uri, RDF::DON.hasExampleDataSet, :data_set]
+  pattern [:data_set, RDF::DON.hasInput, :input]
+  pattern [:input, RDF::DC.title, :title]
+  pattern [:input, RDF::DON.value, :value]
+end.execute(@annotations).map do |result|
+  {
+    :data_set => result.data_set,
+    :type     => :input,
+    :label    => result.title,
+    :value    => result.value
+  }
+end
+
+outputs = RDF::Query.new do
+  pattern [workflow_uri, RDF::DON.hasExampleDataSet, :data_set]
+  pattern [:data_set, RDF::DON.hasOutput, :output]
+  pattern [:output, RDF::DC.title, :title]
+  pattern [:output, RDF::DON.value, :value]
+end.execute(@annotations).map do |result|
+  {
+    :data_set => result.data_set,
+    :type     => :output,
+    :label    => result.title,
+    :value    => result.value
+  }
+end
+
+data_sets = (inputs + outputs).group_by do |item| item[:data_sets] end
+%>
+
+      <% if data_sets.length == 0 %>
+        <p class="none_text">
+          There are no data sets with this workflow.
+        </p>
+      <% else %>
+        <% data_sets.each do |data_set| %>
+
+          <% inputs  = data_set[1].select do |item| item[:type] == :input  end %>
+          <% outputs = data_set[1].select do |item| item[:type] == :output end %>
+
+          <% if inputs.length > 0 && outputs.length > 0 %>
+            <table class="simple">
+              <tr>
+                <th>Input / Output</th>
+                <th>Example</th>
+              </tr>
+              <% if inputs.length > 0 %>
+                <% inputs.each do |input| %>
+                  <tr>
+                    <td>Input: <%=h input[:label] -%></td>
+                    <td><%=h input[:value] -%></td>
+                  </tr>
+                <% end %>
+              <% end %>
+              <% if outputs.length > 0 %>
+                <% outputs.each do |output| %>
+                  <tr>
+                    <td>Output: <%=h output[:label] -%></td>
+                    <td><%=h output[:value] -%></td>
+                  </tr>
+                <% end %>
+              <% end %>
+            </table>
+          <% end %>
+        <% end %>
+      <% end %>
+
       <% if @workflow.show_download_section? %>
 
         <h3>
@@ -205,7 +294,7 @@
 			<% end %>
 		
 			<br/>
-			
+<% if false %>			
       <% statements = research_object_statements(@workflow) %>
 
       <% if statements.length > 0 %>
@@ -233,6 +322,7 @@
       </div>
 
       <% end %>
+<% end %>
 
 			<h3>
 				<%= info_icon_with_tooltip("This section shows the internal components of this workflow version") %>

Modified: branches/wf4ever/config/routes.rb (3204 => 3205)


--- branches/wf4ever/config/routes.rb	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/config/routes.rb	2012-11-26 14:22:26 UTC (rev 3205)
@@ -120,6 +120,8 @@
                  :edit_version => :get, 
                  :update_version => :put, 
                  :process_tag_suggestions => :post,
+                 :edit_annotations => :get,
+                 :update_annotations => :post,
                  :tag_suggestions => :get } do |workflow|
     # workflows have nested citations
     workflow.resources :citations
@@ -192,8 +194,8 @@
   # research_objects
   map.resources :research_objects
 
-  map.research_object_resources '/research_objects/:id/resources',       :controller => 'research_objects', :action ="" 'resource_index', :conditions => { :method => :get }
-  map.research_object_resource  '/research_objects/:id/resources/:path', :controller => 'research_objects', :action ="" 'resource_show',  :conditions => { :method => :get }, :requirements => { :path => /.*/ }
+  map.research_object_resources '/research_objects/:id/resources', :controller => 'research_objects', :action ="" 'resource_index', :conditions => { :method => :get }
+  map.research_object_resource  '/research_objects/:id/resources/:resource_path', :controller => 'research_objects', :action ="" 'resource_show',  :conditions => { :method => :get }, :requirements => { :resource_path => /.*/ }
 
   # content_types
   map.resources :content_types

Modified: branches/wf4ever/lib/conf.rb (3204 => 3205)


--- branches/wf4ever/lib/conf.rb	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/lib/conf.rb	2012-11-26 14:22:26 UTC (rev 3205)
@@ -206,6 +206,10 @@
     self.fetch_entry('research_object_endpoints')
   end
 
+  # Temporary config option for RODL access
+  def self.rodl_bearer_token
+    self.fetch_entry('rodl_bearer_token')
+  end
   # This method is required to create an administrator in the test fixtures
 
   def self.admins=(value)

Modified: branches/wf4ever/public/stylesheets/styles.css (3204 => 3205)


--- branches/wf4ever/public/stylesheets/styles.css	2012-11-26 14:07:48 UTC (rev 3204)
+++ branches/wf4ever/public/stylesheets/styles.css	2012-11-26 14:22:26 UTC (rev 3205)
@@ -2404,3 +2404,21 @@
   list-style-image: url('/images/famfamfam_silk/page.png');
 }
 
+DIV.tag_list {
+  margin-top: 16px;
+  margin-bottom: 16px;
+}
+
+DIV.tag_list UL {
+  margin: 0;
+}
+
+DIV.tag_list LI {
+	display: inline-block;
+	list-style: none;
+  border-bottom: 1px SOLID #a0a0c0;
+  background-color: #d0d0f0;
+  padding-left: 4px;
+  padding-right: 4px;
+}
+

reply via email to

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