myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2994] branches/showcase48: initial research obje


From: noreply
Subject: [myexperiment-hackers] [2994] branches/showcase48: initial research objects tab
Date: Wed, 16 May 2012 16:07:30 +0000 (UTC)

Revision
2994
Author
dgc
Date
2012-05-16 16:07:30 +0000 (Wed, 16 May 2012)

Log Message

initial research objects tab

Modified Paths

Added Paths

Diff

Added: branches/showcase48/app/controllers/research_objects_controller.rb (0 => 2994)


--- branches/showcase48/app/controllers/research_objects_controller.rb	                        (rev 0)
+++ branches/showcase48/app/controllers/research_objects_controller.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,161 @@
+# myExperiment: app/controllers/research_objects_controller.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'curl'
+
+class ResearchObjectsController < ApplicationController
+
+  include ApplicationHelper
+
+  before_filter :find_research_object,  : [:show, :edit, :update]
+  before_filter :find_research_objects, : [:all]
+  
+  # GET /research_objects
+  def index
+    respond_to do |format|
+      format.html {
+        @pivot_options = pivot_options
+
+        begin
+          expr = parse_filter_expression(params["filter"]) if params["filter"]
+        rescue Exception => ex
+          puts "ex = #{ex.inspect}"
+          flash.now[:error] = "Problem with query _expression_: #{ex}"
+          expr = nil
+        end
+
+        @pivot = contributions_list(Contribution, params, current_user,
+            :lock_filter => { 'CATEGORY' => 'ResearchObject' },
+            :filters     => expr)
+
+        @query = params[:query]
+        @query_type = 'research_objects'
+
+        # index.rhtml
+      }
+    end
+  end
+  
+  # GET /research_objects/1
+  def show
+    respond_to do |format|
+      format.html # show.rhtml
+    end
+  end
+
+  # GET /research_objects/new
+  def new
+    @research_object = ResearchObject.new
+  end
+  
+  # GET /research_objects/1/edit
+  def edit
+    @research_object = @contributable
+  end
+
+  # POST /research_objects
+  def create
+
+    if !params[:research_object].is_a?(Hash)
+      error("Research Object is invalid", "is invalid")
+      return
+    end
+
+    ro_params = params[:research_object]
+
+    # get url (if provided)
+    url = "" if ro_params[:url].is_a?(String) && !ro_params[:url].empty?
+
+    # get uploaded file (if provided)
+    file = ro_params[:data].read if ro_params[:data].respond_to?(:read)
+
+    if !url && !file
+      error("You must either specify a URL or upload a Research Object", "not found")
+      return
+    end
+
+    if url && file
+      error("You specified a URL and uploaded a Research Object", "is invalid")
+      return
+    end
+
+    if url
+      begin
+        curl = Curl::Easy.http_get(url)
+        throw Exception if curl.response_code != 200
+        research_object = curl.body_str
+      rescue
+        error("Problem retrieving content from URL (HTTP status #{curl.response_code})",
+            "is invalid")
+        return
+      end
+    else
+      research_object = file
+    end
+
+    @research_object = ResearchObject.create(
+        :contributor  => current_user,
+        :title        => ro_params[:title],
+        :description  => ro_params[:description],
+        :content_blob => ContentBlob.new(:data ="" research_object))
+
+    respond_to do |format|
+      format.html {
+        if @research_object.new_record?
+          render :action ="" "new"
+        else
+          redirect_to(@research_object)
+        end
+      }
+    end
+  end
+  
+  # PUT /research_objects/1
+  def update
+  end
+
+  # DELETE /research_objects/1
+  def destroy
+  end
+
+  protected
+  
+  def find_research_objects
+    @contributables = ResearchObject.find(:all, 
+                       :order => "created_at DESC",
+                       :page => { :size => 20, 
+                       :current => params[:page] })
+  end
+  
+  def find_research_object
+    begin
+      research_object = ResearchObject.find(params[:id])
+      
+      @contributable = research_object
+      
+      @contributable_entry_url = url_for : false,
+                          :host => base_host,
+                          :id => @contributable.id
+
+      @contributable_label                = @contributable.title
+      @contributable_path                 = research_object_path(@contributable)
+
+    rescue ActiveRecord::RecordNotFound
+      error("Research Object not found", "is invalid")
+    end
+  end
+  
+  private
+  
+  def error(notice, message, attr=:id)
+    flash[:error] = notice
+     (err = ResearchObject.new.errors).add(attr, message)
+    
+    respond_to do |format|
+      format.html { redirect_to research_objects_url }
+    end
+  end
+end
+

Modified: branches/showcase48/app/helpers/application_helper.rb (2993 => 2994)


--- branches/showcase48/app/helpers/application_helper.rb	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/app/helpers/application_helper.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -876,7 +876,7 @@
     if (entity.instance_of?(String))
       name = entity
     elsif (entity.class == Class)
-      name = entity.to_s
+      name = entity.name.underscore.split("_").map do |bit| bit.capitalize end.join(" ")
     else
       name = entity.class.to_s
     end

Added: branches/showcase48/app/models/research_object.rb (0 => 2994)


--- branches/showcase48/app/models/research_object.rb	                        (rev 0)
+++ branches/showcase48/app/models/research_object.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,110 @@
+# myExperiment: app/models/research_object.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+require 'lib/acts_as_site_entity'
+require 'lib/acts_as_contributable'
+
+require 'curl'
+require 'xml/libxml'
+require 'zip/zip'
+require 'rdf'
+require 'rdf/raptor'
+
+class ResearchObject < ActiveRecord::Base
+
+  acts_as_site_entity
+  acts_as_contributable
+
+  belongs_to :content_blob, :dependent => :destroy
+
+  validates_presence_of :title
+  validates_presence_of :content_blob
+
+  format_attribute :description
+
+  def load_graph
+
+    begin
+
+      filename = "tmp/ro.#{Process.pid}.zip"
+
+      File.open(filename, "w") do |f|
+        f.write(content_blob.data)
+      end
+
+      zip = Zip::ZipFile.open(filename)
+
+      metadata = zip.read(".ro/manifest.rdf")
+
+      # close files
+
+      zip.close
+      FileUtils.rm_rf(filename)
+
+      # create RDF graph
+
+      manifest_name = "tmp/manifest.#{Process.pid}.rdf"
+
+      File.open(manifest_name, "w") do |f|
+        f.write(metadata)
+      end
+
+      graph = RDF::Graph.load(manifest_name)
+
+      FileUtils.rm_rf(manifest_name)
+
+      graph
+    end
+  end
+
+  def self.related_research_objects_to_t2(uuid)
+
+    self.related_research_objects("
+
+      PREFIX ro: <http://purl.org/wf4ever/ro#>
+      PREFIX dcterms: <http://purl.org/dc/terms/>
+      PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+
+      SELECT ?resource ?creator ?created
+      WHERE {
+         ?resource a ro:ResearchObject ;
+           dcterms:created ?created ;
+             dcterms:creator ?creator .
+      }
+      ORDER BY DESC(?created)
+
+      LIMIT 10")
+
+  end
+
+  def self.related_research_objects(query)
+
+    Conf.research_object_endpoints.each do |endpoint|
+
+      begin
+
+        url = ""
+
+        curl = Curl::Easy.http_get(url)
+
+        if curl.response_code == 200
+
+          ns  = { :s => 'http://www.w3.org/2005/sparql-results#' }
+
+          doc = LibXML::XML::Parser.string(curl.body_str).parse
+          
+          doc.root.find('/s:sparql/s:results/s:result/s:address@hidden"resource"]/s:uri', ns).each do |uri|
+            puts uri.content
+          end
+
+          return curl.body_str
+        end
+        
+      end
+    end
+  end
+
+end
+

Modified: branches/showcase48/app/views/content/_index.rhtml (2993 => 2994)


--- branches/showcase48/app/views/content/_index.rhtml	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/app/views/content/_index.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -109,7 +109,7 @@
       <div class="results">
         <% @pivot[:results].each do |ob| %>
           <% thing = ob.class == SearchResult ? ob.result : ob.contributable -%>
-          <%= render :partial => "#{thing.class.name.pluralize.downcase}/table", :locals => { :collection => [thing] } -%>
+          <%= render :partial => "#{thing.class.name.pluralize.underscore}/table", :locals => { :collection => [thing] } -%>
         <% end %>
       </div>
     <% end %>

Added: branches/showcase48/app/views/research_objects/_breadcrumbs.rhtml (0 => 2994)


--- branches/showcase48/app/views/research_objects/_breadcrumbs.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/_breadcrumbs.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,16 @@
+<% unless controller.action_name.to_s == "index" %>
+  <li><%= link_to 'Research Objects', research_objects_path %></li>
+<% end %>
+
+<% case controller.action_name.to_s; when "show" %>
+  <li>&gt;</li>
+  <li><%= h(@contributable.label) %></li>
+<% when "search" %>  
+  <li>&gt;</li>
+  <li>Search Results</li>
+<% when "index" %>
+  <li>Research objects</li>
+<% else %>
+  <!-- no breadcrumb -->
+<% end %>
+

Added: branches/showcase48/app/views/research_objects/_subnav.rhtml ( => )


Added: branches/showcase48/app/views/research_objects/_table.rhtml
===================================================================
--- branches/showcase48/app/views/research_objects/_table.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/_table.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,46 @@
+<% query ||= false -%>
+<% odd_row = false -%>
+
+<% unless collection.empty? %>
+
+<table class="alt_table">
+	<% for research_object in collection %>
+    <tr class="<%= (odd_row = !odd_row) ? "odd_row" : "even_row" %>">
+      <% cache(:controller => 'research_objects_cache', :action ="" 'listing', :id => research_object.id) do -%>
+        <td style="width: 100px;">
+          <p style="margin-top:0; padding-top:0; text-align: center; margin-top: 1em;"><b>Submitter:</b></p>
+          <center><%= contributor(research_object.contribution.contributor_id, research_object.contribution.contributor_type, true, 60) %></center>
+        </td>
+        <td style="text-align: left;">
+
+          <p class="title">
+            <%= icon "research_object", nil, nil, nil, '' %>
+            <% title = h(research_object.title) %>
+            <%= link_to(query ? highlight_all(title, query) : title, research_object_path(research_object)) %>
+          </p>
+					
+          <p style="font-size: 85%; margin-top: 0; padding-top: 0;">
+            <b>Created at:</b> <%= datetime(research_object.created_at, false) %>
+						<% unless research_object.created_at == research_object.updated_at %>
+						  <b>Last updated at:</b> <%= datetime(research_object.updated_at, false) -%>
+						<% end %>
+          </p>
+					
+					<div class="desc" style="font-size: 85%;">
+            <% unless research_object.description.blank? -%>
+              <% desc = truncate(strip_html(research_object.description), :length => 500) -%>
+              <%= query ? highlight_all(desc, query) : desc %>
+            <% else -%>
+              <span class="none_text">No description</span>                     
+            <% end -%>
+          </div>
+					
+        </td>
+      <% end %>
+        
+    </tr>
+	<% end %>
+</table>
+
+<% end %>
+

Added: branches/showcase48/app/views/research_objects/edit.rhtml (0 => 2994)


--- branches/showcase48/app/views/research_objects/edit.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/edit.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,61 @@
+<% t "Manage" -%>
+
+<%= _javascript__include_tag "fckeditor/fckeditor.js" %>
+
+<h1>Manage: <%=h @contributable.title -%></h1>
+
+<% form_for(:research_object, :url ="" research_object_path(@contributable), :html => { :method => :put }) do |f| %>
+
+  <%= f.error_messages %>
+
+<% if false %>
+  <p style="text-align: center;">
+    <strong>RO to upload: </strong>
+    <%= f.file_field :data %>
+  </p>
+  
+  <br/>
+  
+  <p style="text-align: center;">
+  	<strong>RODL URL: </strong>
+		<br/>
+		<%= f.text_field :url, :size => 60 -%>
+  </p>
+	
+	<br/>
+<% end %>
+
+  <p style="text-align: center;">
+  	<strong>Title: </strong>
+		<br/>
+		<%= f.text_field :title, :size => 60 -%>
+  </p>
+	
+	<br/>
+  
+  <p style="text-align: center;">
+  	<strong>Description: </strong>
+	</p>
+
+	<center>
+    <%= f.text_area :description -%>
+
+    <script type="text/_javascript_">
+    //<![CDATA[
+    var oFCKeditor = new FCKeditor('research_object_description', '600px', '300px', 'Simple');
+    oFCKeditor.BasePath = "/_javascript_s/fckeditor/"
+    oFCKeditor.Config['CustomConfigurationsPath'] = '/_javascript_s/fckcustom.js';
+    oFCKeditor.ReplaceTextarea();
+
+    //]]>
+    </script>
+
+	</center>
+
+  <br />
+
+  <p style="text-align: center;">
+    <%= f.submit "Submit", :disable_with => "Submitting..." %>
+  </p>
+<% end %>
+

Added: branches/showcase48/app/views/research_objects/index.rhtml (0 => 2994)


--- branches/showcase48/app/views/research_objects/index.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/index.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,4 @@
+<h1>Research Objects</h1>
+
+<%= render :partial => "content/index" -%>
+

Added: branches/showcase48/app/views/research_objects/new.rhtml (0 => 2994)


--- branches/showcase48/app/views/research_objects/new.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/new.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,58 @@
+<% t "New" -%>
+
+<%= _javascript__include_tag "fckeditor/fckeditor.js" %>
+
+<h1>Submit Research Object</h1>
+
+<%= error_messages_for :research_object %>
+
+<% form_tag({:action ="" :create}, :multipart => true) do %>
+
+  <p style="text-align: center;">
+    <strong>RO to upload: </strong>
+    <%= file_field :research_object, :data %>
+  </p>
+  
+  <br/>
+  
+  <p style="text-align: center;">
+  	<strong>RODL URL: </strong>
+		<br/>
+		<%= text_field_tag "research_object[url]", nil, :size => 60 %>
+  </p>
+	
+	<br/>
+
+  <p style="text-align: center;">
+  	<strong>Title: </strong>
+		<br/>
+		<%= text_field_tag "research_object[title]", nil, :size => 60 %>
+  </p>
+	
+	<br/>
+  
+  <p style="text-align: center;">
+  	<strong>Description: </strong>
+	</p>
+	<center>
+
+    <textarea id='research_object__description_editor'   name='research_object[description]'></textarea>
+    <script type="text/_javascript_">
+    //<![CDATA[
+    var oFCKeditor = new FCKeditor('research_object__description_editor', '600px', '300px', 'Simple');
+    oFCKeditor.BasePath = "/_javascript_s/fckeditor/"
+    oFCKeditor.Config['CustomConfigurationsPath'] = '/_javascript_s/fckcustom.js';
+    oFCKeditor.ReplaceTextarea();
+
+    //]]>
+    </script>
+
+	</center>
+
+  <br />
+
+  <p style="text-align: center;">
+    <%= submit_tag "Submit", :disable_with => "Submitting..." %>
+  </p>
+<% end %>
+

Added: branches/showcase48/app/views/research_objects/show.rhtml (0 => 2994)


--- branches/showcase48/app/views/research_objects/show.rhtml	                        (rev 0)
+++ branches/showcase48/app/views/research_objects/show.rhtml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,38 @@
+<h1>Research Object: <%=h @contributable.title -%></h1>
+
+<table class="simple">
+
+  <tr>
+    <td>created_at</td>
+    <td><%=h @contributable.created_at -%></td>
+  </tr>
+
+  <tr>
+    <td>updated_at</td>
+    <td><%=h @contributable.updated_at -%></td>
+  </tr>
+
+  <tr>
+    <td>title</td>
+    <td><%=h @contributable.title -%></td>
+  </tr>
+
+  <tr>
+    <td>description</td>
+    <td><%= @contributable.description_html -%></td>
+  </tr>
+
+</table>
+
+<h2>Triples</h2>
+
+<table>
+  <% @contributable.load_graph.query([nil, nil, nil]).each do |s, p, o| %>
+    <tr>
+      <td><%=h s.to_s -%></td>
+      <td><%=h p.to_s -%></td>
+      <td><%=h o.to_s -%></td>
+    </tr>
+  <% end %>
+</table>
+

Modified: branches/showcase48/config/default_settings.yml (2993 => 2994)


--- branches/showcase48/config/default_settings.yml	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/config/default_settings.yml	2012-05-16 16:07:30 UTC (rev 2994)
@@ -41,7 +41,7 @@
 # contributable_models - These are the models for the things that myExperiment
 #                        contributors can contribute.
 
-contributable_models: [Workflow, Blob, Pack, Blog]
+contributable_models: [Workflow, Blob, Pack, Blog, ResearchObject]
 
 # page_template - This is the page template for all the pages except for
 #                 the front page of the web site.
@@ -168,7 +168,11 @@
   - label:      Topics
     link:       /topics
     controller: topics
-	
+
+  - label:      Research
+    link:       /research_objects
+    controller: research_objects
+
 # new_menu - Set "new_menu" with the details of each kind of thing to appear in
 #            the New/Upload gadget.
 #
@@ -208,6 +212,10 @@
     link:       /files/new
     controller: blobs
 
+  - label:      Research Ob
+    link:       /research_objects/new
+    controller: research_objects
+
   - label:      Pack
     link:       /packs/new
     controller: packs
@@ -506,3 +514,7 @@
 #         - styles
 #         - custom_stylesheet
 #       layout: layouts/myexperiment
+
+research_object_endpoints:
+
+  - http://sandbox.wf4ever-project.org/rosrs5/sparql

Modified: branches/showcase48/config/routes.rb (2993 => 2994)


--- branches/showcase48/config/routes.rb	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/config/routes.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -180,6 +180,9 @@
   # services
   map.resources :services, :collection => { :search => :get }
   
+  # research_objects
+  map.resources :research_objects
+
   # content_types
   map.resources :content_types
 

Added: branches/showcase48/db/migrate/20120508145518_create_research_objects.rb (0 => 2994)


--- branches/showcase48/db/migrate/20120508145518_create_research_objects.rb	                        (rev 0)
+++ branches/showcase48/db/migrate/20120508145518_create_research_objects.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -0,0 +1,24 @@
+# myExperiment: db/migrate/20120508145518_create_research_objects.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateResearchObjects < ActiveRecord::Migration
+  def self.up
+    create_table "research_objects", :force => true do |t|
+      t.string   "title"
+      t.text     "description"
+      t.text     "description_html"
+      t.text     "url"
+      t.datetime "created_at"
+      t.datetime "updated_at"
+      t.integer  "content_blob_id"
+      t.integer  "contributor_id"
+      t.string   "contributor_type"
+    end
+  end
+
+  def self.down
+    drop_table :research_objects
+  end
+end

Modified: branches/showcase48/lib/acts_as_contributable.rb (2993 => 2994)


--- branches/showcase48/lib/acts_as_contributable.rb	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/lib/acts_as_contributable.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -29,7 +29,20 @@
           include Mib::Acts::Contributable::InstanceMethods
           
           before_create do |c|
-            c.contribution = Contribution.new(:contributor_id => c.contributor_id, :contributor_type => c.contributor_type, :contributable => c)
+
+            # If not specified, create a contribution record and / or policy
+            # record.
+
+            if c.contribution.nil?
+              c.contribution = Contribution.new(
+                  :contributor   => c.contributor,
+                  :contributable => c)
+            end
+
+            if c.contribution.policy.nil?
+              c.contribution.policy = create_default_policy(c.contributor)
+            end
+
           end
         end
       end

Modified: branches/showcase48/lib/conf.rb (2993 => 2994)


--- branches/showcase48/lib/conf.rb	2012-05-16 16:00:51 UTC (rev 2993)
+++ branches/showcase48/lib/conf.rb	2012-05-16 16:07:30 UTC (rev 2994)
@@ -186,6 +186,10 @@
     layouts.delete_if {|k,v| v["environment"] && (v["environment"] != ENV["RAILS_ENV"])}
   end
 
+  def self.research_object_endpoints
+    self.fetch_entry('research_object_endpoints')
+  end
+
   # This method is required to create an administrator in the test fixtures
 
   def self.admins=(value)

reply via email to

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