myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [3261] branches/wf4ever: added ability to aggrega


From: noreply
Subject: [myexperiment-hackers] [3261] branches/wf4ever: added ability to aggregate resources and show details on resources
Date: Fri, 14 Dec 2012 14:36:36 +0000 (UTC)

Revision
3261
Author
dgc
Date
2012-12-14 14:36:35 +0000 (Fri, 14 Dec 2012)

Log Message

added ability to aggregate resources and show details on resources

Modified Paths

Diff

Modified: branches/wf4ever/app/controllers/packs_controller.rb (3260 => 3261)


--- branches/wf4ever/app/controllers/packs_controller.rb	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/controllers/packs_controller.rb	2012-12-14 14:36:35 UTC (rev 3261)
@@ -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
   
@@ -79,6 +81,80 @@
       end
     end
   end
+
+  # GET /packs/:id/resources/:resource_path
+  def resource_show
+
+#   resource_object = Statement.find(:first, :conditions => {
+#       :research_object_id => @contributable.id,
+#       :predicate_text => 'http://purl.org/wf4ever/ro#name',
+#       :objekt_text => params[:path]})
+
+#   raise ActiveRecord::RecordNotFound if resource_object.nil?
+
+#   statements = Statement.find(:all, :conditions => {
+#       :subject_text => resource_object.subject_text
+#   })
+
+    # Get annotations as merged graph.  This will be pulled from cache
+    # eventually.
+
+    session = ROSRS::Session.new(@pack.ro_uri, Conf.rodl_bearer_token)
+
+    @resuri = @pack.resolve_resource_uri(params[:resource_path])
+
+    @annotations = session.get_annotation_graph(@pack.ro_uri, @resuri)
+
+    @pack.contributable_entries.manifest.query(address@hidden, nil, nil]).each do |statement|
+
+      case statement.predicate.to_s
+      when "http://purl.org/wf4ever/ro#name":      @manifest_name    = statement.object.to_s
+      when "http://purl.org/dc/terms/created":     @manifest_created = Date.parse(statement.object.to_s)
+      when "http://purl.org/dc/terms/creator":     @manifest_creator = statement.object.to_s
+      when "http://purl.org/wf4ever/ro#checksum" : @manifest_md5     = statement.object.to_s
+      when "http://purl.org/wf4ever/ro#filesize" : @manifest_size    = statement.object.to_s.to_i
+      end
+
+    end
+
+    @annotations.query(address@hidden, nil, nil]).each do |statement|
+
+      case statement.predicate.to_s
+      when "http://purl.org/dc/terms/title":       @title       = statement.object.to_s
+      when "http://purl.org/dc/terms/description": @description = statement.object.to_s
+      when "http://purl.org/dc/terms/creator":     @creator     = statement.object.to_s
+      when "http://purl.org/dc/terms/created":     @created     = Date.parse(statement.object.to_s)
+      end
+
+    end
+
+    render :resource_show
+  end
+
+  def create_resource
+
+    session = ROSRS::Session.new(@pack.ro_uri, Conf.rodl_bearer_token)
+
+    filename = File.basename(params[:data].original_filename)
+
+    if params[:commit] == "Aggregate workflow"
+
+      service_uri = "http://sandbox.wf4ever-project.org/wf-ro/jobs"
+      format = "application/vnd.taverna.t2flow+xml"
+      token = Conf.rodl_bearer_token
+      resource = "http://www.myexperiment.org/workflows/2470/download/_untitled__947103.t2flow?version=2"
+      ro = @pack.ro_uri
+
+      uri = Wf4Ever::TransformationClient.create_job(service_uri, resource, format, ro, token)
+    else
+      c, r, puri, ruri = session.aggregate_internal_resource(@pack.ro_uri, filename, { :body => params[:data].read, :ctype=> 'text/plain' })
+    end
+    respond_to do |format|
+      format.html {
+        redirect_to pack_url(@pack)
+      }
+    end
+  end
   
   # GET /packs/1;download
   def download
@@ -420,6 +496,7 @@
     action_permissions = {
       "create"           => "create",
       "create_item"      => "edit",
+      "create_resource"  => "edit",
       "destroy"          => "destroy",
       "destroy_item"     => "destroy",
       "download"         => "download",
@@ -435,6 +512,7 @@
       "resolve_link"     => "edit",
       "search"           => "view",
       "show"             => "view",
+      "resource_show"    => "view",
       "statistics"       => "view",
       "tag"              => "view",
       "update"           => "edit",

Modified: branches/wf4ever/app/models/pack.rb (3260 => 3261)


--- branches/wf4ever/app/models/pack.rb	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/models/pack.rb	2012-12-14 14:36:35 UTC (rev 3261)
@@ -10,7 +10,84 @@
 require 'tempfile'
 require 'cgi'
 
+require 'rdf'
+require 'wf4ever/rosrs_client'
 
+class ContributableEntry
+
+  attr_accessor :pack
+  attr_accessor :uri, :name, :created, :creator, :checksum, :size
+
+  def available?
+    true
+  end
+    
+  def local?
+    false
+  end
+
+  def comment
+    nil
+  end
+
+  def user_id
+    pack.contributor_id
+  end
+
+  def created_at
+    Time.parse(created)
+  end
+  
+  def ro_local_uri
+    if @uri.starts_with?(pack.ro_uri)
+      @uri[pack.ro_uri.length..-1]
+    else
+      @uri
+    end
+  end
+
+end
+
+class ContributableEntries
+
+  attr_accessor :pack
+  attr_accessor :manifest
+
+  def initialize(pack)
+    self.pack = pack
+    session = ROSRS::Session.new(self.pack.ro_uri, Conf.rodl_bearer_token)
+    manifest_uri, @manifest = session.get_manifest(self.pack.ro_uri)
+
+    @entries = []
+
+    @manifest.query([RDF::URI.parse(self.pack.ro_uri), RDF::ORE.aggregates, nil]).select do |aggregate|
+      @manifest.query([aggregate.object, RDF.type, RDF::RO.Resource]).count > 0 &&
+      @manifest.query([nil, RDF::AO.body, aggregate.object]).count == 0
+    end.each do |resource|
+      ce = ContributableEntry.new
+
+      ce.pack     = pack
+      ce.uri      = resource.object.to_s
+      ce.name     = @manifest.graph.first_value([resource.object,  RDF::URI.parse("http://purl.org/wf4ever/ro#name"), nil])
+      ce.created  = @manifest.graph.first_value([resource.object,  RDF::DC.created,  nil])
+      ce.creator  = @manifest.graph.first_object([resource.object, RDF::DC.creator,  nil])
+      ce.checksum = @manifest.graph.first_object([resource.object, RDF::RO.checksum, nil])
+      ce.size     = @manifest.graph.first_value([resource.object,  RDF::RO.filesize, nil])
+       
+      @entries << ce
+    end
+  end
+    
+  def count
+    @entries.count
+  end
+  
+  def each(&blk)
+    @entries.each(&blk)
+  end
+
+end
+
 class Pack < ActiveRecord::Base
 
   acts_as_site_entity :owner_text => 'Creator'
@@ -32,11 +109,11 @@
                :boost => "rank",
                :include => [ :comments ]) if Conf.solr_enable
   
-  has_many :contributable_entries,
-           :class_name => "PackContributableEntry",
-           :foreign_key => :pack_id,
-           :order => "created_at DESC",
-           :dependent => :destroy
+# has_many :contributable_entries,
+#          :class_name => "PackContributableEntry",
+#          :foreign_key => :pack_id,
+#          :order => "created_at DESC",
+#          :dependent => :destroy
   
   has_many :remote_entries,
            :class_name => "PackRemoteEntry",
@@ -44,6 +121,10 @@
            :order => "created_at DESC",
            :dependent => :destroy
   
+  def contributable_entries
+    @contributable_entries ||= ContributableEntries.new(self)
+  end
+
   def items_count
     return contributable_entries.count + remote_entries.count
   end
@@ -631,6 +712,10 @@
     APIStatistics.statistics(self)
   end
  
+  def resolve_resource_uri(resource_uri)
+    RDF::URI.parse(ro_uri).join(RDF::URI.parse(resource_uri))
+  end
+
   protected
   
   # produces html string containing the required messaged, enclosed within left-padded P tag, belonging to 'none_text' class

Modified: branches/wf4ever/app/models/pack_contributable_entry.rb (3260 => 3261)


--- branches/wf4ever/app/models/pack_contributable_entry.rb	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/models/pack_contributable_entry.rb	2012-12-14 14:36:35 UTC (rev 3261)
@@ -70,6 +70,10 @@
     return (self.contributable != nil)
   end
 
+  def local?
+    true
+  end
+
   def item_as_list
     return [contributable]
   end

Modified: branches/wf4ever/app/views/packs/_items.rhtml (3260 => 3261)


--- branches/wf4ever/app/views/packs/_items.rhtml	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/views/packs/_items.rhtml	2012-12-14 14:36:35 UTC (rev 3261)
@@ -11,90 +11,96 @@
 			
 			<!-- Contributable Item Entries -->
 			<% pack.contributable_entries.each do |e| %>
-				<% show = e.available? ? Authorization.check("view", e.contributable, current_user) : false -%>
-				<li>
-					<table>
-						<tr>
-							<td class="icon">
-								<% if show -%>
-									<%= icon(e.contributable_type.to_s, nil, 'Internal item', nil, nil) -%>
-								<% else -%>
-									<%= icon('denied', nil, 'Item unavailable to view', nil, nil) -%>
-								<% end -%>
-							</td>
-							<td>
-								<a name='<%= "item_contributable_#{e.id}" -%>'></a>
-								<p>
-									<% if mine?(pack) -%>
-										<%= remove_item_button(pack.id, "contributable", e.id) -%>
-									<% end -%>
-									
-									<% if show and authorised_to_edit -%>
-										<%= edit_item_button(pack.id, "contributable", e.id) -%>
-									<% end -%>
-									
-									<% if show -%>
-									
-										<b><%= visible_name(e.contributable_type) -%>:</b>
-										<% unless e.contributable_version.blank? -%>
-											<% # HACK: only workflows are versioned at the moment -%>
-											<%= versioned_workflow_link e.contributable_id, e.contributable_version, false -%>
-											<% if false %><span style="color: #666666;">(version <%= e.contributable_version -%>)</span><% end %>
-										<% else -%>
-											<%= contributable(e.contributable_id, e.contributable_type) %>
-										<% end -%>
-										<small>(<%= contributor e.contributable.contribution.contributor_id, e.contributable.contribution.contributor_type -%>)</small>
-										
-									<% else -%>
-										
-										<% if not e.available? -%>
-											<font class="none_text">
-												The item this entry points to is not available. It may have been deleted.
-											</font>
-										<% else -%>
-											<font class="denied_text">
-												You are not authorised to view the item this entry points to.
-											</font>
-										<% end -%>
-										
-									<% end -%>
-								</p>
-								<div class="inner">
-									<% unless e.comment.blank? -%> 
-										<% if show or not e.available? -%>
-											<div class="comment">
-												<table>
-													<tr>
-														<td style="width: 20px; vertical-align: top;"><%= icon('comment', nil, nil, nil, nil) -%></td>
-														<td><%= simple_format(h(e.comment)) -%></td>
-													</tr>
-												</table>
-											</div>
-										<% end -%>
-									<% else -%>
-										<% if authorised_to_edit -%>
-											<p><small>[ <%= link_to "Add a comment here", edit_item_link(pack.id, "contributable", e.id) -%> ]</small></p>
-										<% end -%>
-									<% end -%>
-									<p class="user">
-										<%= user_and_created_at_bit(e) -%>
-									</p>
-								</div>
-								<% if show -%>
-									<p style="margin-top: 0; text-align: right;">
-										<%= link_to_function "<span style='padding-right: 0.3em;'>more</span>" + expand_image("0"), 
-																				 visual_effect(:toggle_blind, "contributable_entry_#{e.id}", :duration => 0.2),
-																				 :title => tooltip_title_attrib("Click to show/hide additional metadata that has been found for this item") -%>
-									</p>
-									<div id="contributable_entry_<%= e.id -%>" class="box_standout" style="display: none; margin-top: 0.3em;">
-										<p><b>Description:</b></p>
-										<%= contributable_entry_description(e) -%>
-									</div>
-								<% end -%>								
-							</td>
-						</tr>
-					</table>
-				</li>
+        <% if e.local? %>
+          <% show = e.available? ? Authorization.check("view", e.contributable, current_user) : false -%>
+          <li>
+            <table>
+              <tr>
+                <td class="icon">
+                  <% if show -%>
+                    <%= icon(e.contributable_type.to_s, nil, 'Internal item', nil, nil) -%>
+                  <% else -%>
+                    <%= icon('denied', nil, 'Item unavailable to view', nil, nil) -%>
+                  <% end -%>
+                </td>
+                <td>
+                  <a name='<%= "item_contributable_#{e.id}" -%>'></a>
+                  <p>
+                    <% if mine?(pack) -%>
+                      <%= remove_item_button(pack.id, "contributable", e.id) -%>
+                    <% end -%>
+                    
+                    <% if show and authorised_to_edit -%>
+                      <%= edit_item_button(pack.id, "contributable", e.id) -%>
+                    <% end -%>
+                    
+                    <% if show -%>
+                    
+                      <b><%= visible_name(e.contributable_type) -%>:</b>
+                      <% unless e.contributable_version.blank? -%>
+                        <% # HACK: only workflows are versioned at the moment -%>
+                        <%= versioned_workflow_link e.contributable_id, e.contributable_version, false -%>
+                        <% if false %><span style="color: #666666;">(version <%= e.contributable_version -%>)</span><% end %>
+                      <% else -%>
+                        <%= contributable(e.contributable_id, e.contributable_type) %>
+                      <% end -%>
+                      <small>(<%= contributor e.contributable.contribution.contributor_id, e.contributable.contribution.contributor_type -%>)</small>
+                      
+                    <% else -%>
+                      
+                      <% if not e.available? -%>
+                        <font class="none_text">
+                          The item this entry points to is not available. It may have been deleted.
+                        </font>
+                      <% else -%>
+                        <font class="denied_text">
+                          You are not authorised to view the item this entry points to.
+                        </font>
+                      <% end -%>
+                      
+                    <% end -%>
+                  </p>
+                  <div class="inner">
+                    <% unless e.comment.blank? -%> 
+                      <% if show or not e.available? -%>
+                        <div class="comment">
+                          <table>
+                            <tr>
+                              <td style="width: 20px; vertical-align: top;"><%= icon('comment', nil, nil, nil, nil) -%></td>
+                              <td><%= simple_format(h(e.comment)) -%></td>
+                            </tr>
+                          </table>
+                        </div>
+                      <% end -%>
+                    <% else -%>
+                      <% if authorised_to_edit -%>
+                        <p><small>[ <%= link_to "Add a comment here", edit_item_link(pack.id, "contributable", e.id) -%> ]</small></p>
+                      <% end -%>
+                    <% end -%>
+                    <p class="user">
+                      <%= user_and_created_at_bit(e) -%>
+                    </p>
+                  </div>
+                  <% if show -%>
+                    <p style="margin-top: 0; text-align: right;">
+                      <%= link_to_function "<span style='padding-right: 0.3em;'>more</span>" + expand_image("0"), 
+                                           visual_effect(:toggle_blind, "contributable_entry_#{e.id}", :duration => 0.2),
+                                           :title => tooltip_title_attrib("Click to show/hide additional metadata that has been found for this item") -%>
+                    </p>
+                    <div id="contributable_entry_<%= e.id -%>" class="box_standout" style="display: none; margin-top: 0.3em;">
+                      <p><b>Description:</b></p>
+                      <%= contributable_entry_description(e) -%>
+                    </div>
+                  <% end -%>								
+                </td>
+              </tr>
+            </table>
+          </li>
+        <% else %>
+          <% if e && e.name %>
+            <li><%= link_to(e.ro_local_uri, pack_resources_path(pack) + '/' + e.ro_local_uri) -%></li>
+          <% end %>
+        <% end %>
 			<% end -%>
 			
 			<!-- Remote Item Entries -->

Modified: branches/wf4ever/app/views/packs/_tags_from_items.rhtml (3260 => 3261)


--- branches/wf4ever/app/views/packs/_tags_from_items.rhtml	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/views/packs/_tags_from_items.rhtml	2012-12-14 14:36:35 UTC (rev 3261)
@@ -1,3 +1,4 @@
+<% if false %>
 <% tags_collection = unique_tags_from_items(items) %>
 <div class="contribution_section_box">
 	<p class="heading">
@@ -10,4 +11,5 @@
 	<% else -%>
 		<p class="none_text">None</p>
 	<% end -%>
-</div>
\ No newline at end of file
+</div>
+<% end %>

Modified: branches/wf4ever/app/views/packs/show.rhtml (3260 => 3261)


--- branches/wf4ever/app/views/packs/show.rhtml	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/app/views/packs/show.rhtml	2012-12-14 14:36:35 UTC (rev 3261)
@@ -120,6 +120,13 @@
 					<%= info_icon_with_tooltip("This section provides various ways of adding items to this pack") %>
 					Add an Item
 				</h3>
+        <p>
+        <% form_tag(create_resource_pack_path(@pack), :multipart => true, :method => :post) do %>
+          <%= file_field_tag :data -%>
+          <%= submit_tag("Aggregate resource") -%>
+          <%= submit_tag("Aggregate workflow") -%>
+        <% end %>
+        </p>
 				<a name="add_item"></a>
 				<%= render :partial => "add_item", :locals => { :pack => @pack } -%>
 			<% end -%>

Modified: branches/wf4ever/config/routes.rb (3260 => 3261)


--- branches/wf4ever/config/routes.rb	2012-12-14 12:56:18 UTC (rev 3260)
+++ branches/wf4ever/config/routes.rb	2012-12-14 14:36:35 UTC (rev 3261)
@@ -99,11 +99,16 @@
                  :download => :get,
                  :quick_add => :post,
                  :resolve_link => :post,
+                 :create_resource => :post,
+                 :destroy_resource => :delete,
                  :items => :get } do |pack|
     pack.resources :comments, :collection => { :timeline => :get }
     pack.resources :relationships, :collection => { :edit_relationships => :get }
   end
     
+  map.pack_resources '/packs/:id/resources', :controller => 'packs', :action ="" 'resource_index', :conditions => { :method => :get }
+  map.pack_resource  '/packs/:id/resources/:resource_path', :controller => 'packs', :action ="" 'resource_show',  :conditions => { :method => :get }, :requirements => { :resource_path => /.*/ }
+
   # workflows (downloadable)
   map.resources :workflows, 
     :collection => { :search => :get }, 

reply via email to

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