myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2176] trunk: removal of multi purposed content t


From: noreply
Subject: [myexperiment-hackers] [2176] trunk: removal of multi purposed content type field
Date: Fri, 24 Apr 2009 10:32:03 -0400 (EDT)

Revision
2176
Author
dgc
Date
2009-04-24 10:32:02 -0400 (Fri, 24 Apr 2009)

Log Message

removal of multi purposed content type field

Modified Paths

Added Paths

Diff

Modified: trunk/app/controllers/blobs_controller.rb (2175 => 2176)


--- trunk/app/controllers/blobs_controller.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/controllers/blobs_controller.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -42,9 +42,9 @@
       @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
     end
     
-    send_data(@blob.content_blob.data, :filename => @blob.local_name, :type => @blob.content_type)
+    send_data(@blob.content_blob.data, :filename => @blob.local_name, :type => @blob.content_type.mime_type)
     
-    #send_file("#{RAILS_ROOT}/#{controller_name}/address@hidden/address@hidden/address@hidden", :filename => @blob.local_name, :type => @blob.content_type)
+    #send_file("#{RAILS_ROOT}/#{controller_name}/address@hidden/address@hidden/address@hidden", :filename => @blob.local_name, :type => @blob.content_type.mime_type)
   end
 
   # GET /files/:id/download/:name
@@ -103,7 +103,7 @@
     else
       data = ""
       params[:blob][:local_name] = params[:blob][:data].original_filename
-      params[:blob][:content_type] = params[:blob][:data].content_type
+      content_type = params[:blob][:data].content_type
       params[:blob].delete('data')
 
       params[:blob][:contributor_type], params[:blob][:contributor_id] = "User", current_user.id
@@ -111,6 +111,12 @@
       @blob = Blob.new(params[:blob])
       @blob.content_blob = ContentBlob.new(:data ="" data)
 
+      @blob.content_type = ContentType.find_by_mime_type(content_type)
+
+      if @blob.content_type.nil?
+        @blob.content_type = ContentType.create(:user_id => current_user.id, :mime_type => content_type, :title => content_type)
+      end
+
       respond_to do |format|
         if @blob.save
           if params[:blob][:tag_list]
@@ -150,7 +156,7 @@
     
     # remove protected columns
     if params[:blob]
-      [:contributor_id, :contributor_type, :content_type, :local_name, :created_at, :updated_at].each do |column_name|
+      [:contributor_id, :contributor_type, :content_type, :content_type_id, :local_name, :created_at, :updated_at].each do |column_name|
         params[:blob].delete(column_name)
       end
     end
@@ -289,7 +295,7 @@
   
   def find_blobs
     found = Blob.find(:all, 
-                       :order => "content_type ASC, local_name ASC, created_at DESC",
+                       :order => "updated_at DESC, created_at DESC",
                        :page => { :size => 20, 
                        :current => params[:page] })
     

Modified: trunk/app/controllers/jobs_controller.rb (2175 => 2176)


--- trunk/app/controllers/jobs_controller.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/controllers/jobs_controller.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -59,7 +59,7 @@
     if params[:runnable_id] 
       runnable = Workflow.find(:first, :conditions => ["id = ?", params[:runnable_id]])
       if runnable 
-        if runnable.content_type != WorkflowProcessors::TavernaScufl.content_type
+        if runnable.processor_class != WorkflowProcessors::TavernaScufl
           flash[:error] = "Note that the workflow specified to run in this job is currently not supported and will prevent the job from being created. Specify a Taverna 1 workflow instead."
         end
         
@@ -92,7 +92,7 @@
     # Check that the runnable object is allowed to be run.
     # At the moment: only Taverna 1 workflows are allowed.
     if runnable 
-      if runnable.content_type != WorkflowProcessors::TavernaScufl.content_type
+      if runnable.processor_class != WorkflowProcessors::TavernaScufl
         success = false
         err_msg = "The workflow specified to run in this job not supported. Please specify a Taverna 1 workflow instead."
       end

Modified: trunk/app/controllers/search_controller.rb (2175 => 2176)


--- trunk/app/controllers/search_controller.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/controllers/search_controller.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -74,7 +74,7 @@
       markup += "<pubDate>" + time_string(w.created_at) + "</pubDate>";
       markup += "<media:content url="" + w.named_download_url + "\"";
       markup += " fileSize=\"" + w.content_blob.data.length.to_s + "\"" +
-                " type=\"" + w.content_type + "\"/>";
+                " type=\"" + w.content_type.title + "\"/>";
       markup += "<media:thumbnail url="" + file_column_url(w, "image/thumb") +
           "\"/>";
 #markup += "height=\"120\" width=\"160\"/>";

Modified: trunk/app/controllers/workflows_controller.rb (2175 => 2176)


--- trunk/app/controllers/workflows_controller.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/controllers/workflows_controller.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -162,7 +162,7 @@
       @download = Download.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
     end
     
-    send_data(@viewing_version.content_blob.data, :filename => @workflow.filename(@viewing_version_number), :type => @workflow.content_type)
+    send_data(@viewing_version.content_blob.data, :filename => @workflow.filename(@viewing_version_number), :type => @workflow.content_type.mime_type)
   end
   
   # GET /workflows/:id/download/:name
@@ -179,7 +179,7 @@
   # GET /workflows/:id/launch.whip
   def launch
     # Only allow for Taverna 1 workflows.
-    if @workflow.content_type == WorkflowProcessors::TavernaScufl.content_type
+    if @workflow.processor_class == WorkflowProcessors::TavernaScufl
       wwf = Whip::WhipWorkflow.new()
   
       wwf.title       = @viewing_version.title
@@ -353,11 +353,11 @@
     
     wrong_type_err = false
     
-    if WorkflowTypesHandler.processor_class_for_content_type(@workflow.content_type).nil?
+    if @workflow.processor_class.nil?
       # Just need to check file extension matches
       wrong_type_err = true unless file_ext == @workflow.file_ext 
     else
-      wrong_type_err = true unless workflow_file_matches_content_type_if_supported?(file, @workflow.content_type)
+      wrong_type_err = true unless workflow_file_matches_content_type_if_supported?(file, @workflow)
     end
     
     if wrong_type_err
@@ -430,7 +430,7 @@
   def update
     # remove protected columns
     if params[:workflow]
-      [:contribution, :contributor_id, :contributor_type, :image, :svg, :created_at, :updated_at, :current_version, :content_type, :file_ext, :content_blob_id].each do |column_name|
+      [:contribution, :contributor_id, :contributor_type, :image, :svg, :created_at, :updated_at, :current_version, :content_type, :content_type_id, :file_ext, :content_blob_id].each do |column_name|
         params[:workflow].delete(column_name)
       end
     end
@@ -824,7 +824,7 @@
           workflow_to_set.title = processor_instance.get_title
           workflow_to_set.body = processor_instance.get_description
           
-          workflow_to_set.content_type = processor_class.content_type
+          workflow_to_set.content_type = ContentType.find_by_title(processor_class.display_name)
           
           # Set the internal unique name for this particular workflow (or workflow_version).
           workflow_to_set.set_unique_name
@@ -860,17 +860,16 @@
       wf_type = params[:workflow][:type]
     
       if wf_type.downcase == 'other'
-        wf_type = params[:workflow][:type_other]
+        workflow_to_set.content_type = ContentType.create(:user_id => current_user.id,
+            :mime_type => file.content_type, :title => params[:workflow][:type_other])
       else
-        wf_type = WorkflowTypesHandler.content_type_for_type_display_name(wf_type)
+        workflow_to_set.content_type = ContentType.find_by_title(wf_type)
       end
-      
-      workflow_to_set.content_type = wf_type
     end
     
     # Check that the file uploaded is valid for the content type chosen (if supported by a workflow processor).
     # This is to ensure that the correct content type is being assigned to the workflow file uploaded.
-    return false unless workflow_file_matches_content_type_if_supported?(file, workflow_to_set.content_type)
+    return false unless workflow_file_matches_content_type_if_supported?(file, workflow_to_set)
     
     # Preview image
     # TODO: kept getting permission denied errors from the file_column and rmagick code, so disable for windows, for now.
@@ -884,16 +883,16 @@
     return worked
   end
   
-  # This method checks to to see if the file specified is a valid one for the workflow content_type specified,
-  # but only if the workflow content_type specified has a supporting processor.
+  # This method checks to to see if the file specified is a valid one for the existing workflow specified,
+  # but only if the existing workflow specified has a supporting processor.
   # If no supporting processor is found then validity cannot be determined so we assume the file is valid for the content type.
   #
   # Note: this will check whether the file extension is supported and, if the processor allows for it, 
   # checks if the file is "recognised" by the processor as a valid workflow of that type.
-  def workflow_file_matches_content_type_if_supported?(file, content_type)
+  def workflow_file_matches_content_type_if_supported?(file, existing_workflow)
     ok = true
     
-    proc_class = WorkflowTypesHandler.processor_class_for_content_type(content_type)
+    proc_class = existing_workflow.processor_class
       
     if proc_class
       # Check that the file extension of the file specified is supported by the processor.

Modified: trunk/app/models/blob.rb (2175 => 2176)


--- trunk/app/models/blob.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/models/blob.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -25,14 +25,23 @@
   acts_as_attributor
   acts_as_attributable
   
-  acts_as_solr(:fields => [:title, :local_name, :body, :content_type, :uploader],
+  acts_as_solr(:fields => [:title, :local_name, :body, :type, :uploader],
                :include => [ :comments ]) if Conf.solr_enable
+
   belongs_to :content_blob
+  belongs_to :content_type
 
   # :dependent => :destroy is not supported in belongs_to in rails 1.2.6
   after_destroy { |b| b.content_blob.destroy }
 
   validates_inclusion_of :license, :in => [ "by-nd", "by-sa", "by" ]
   
+  validates_presence_of :content_blob
+  validates_presence_of :content_type
+
   format_attribute :body
+
+  def type
+    content_type.title
+  end
 end

Modified: trunk/app/models/content_blob.rb (2175 => 2176)


--- trunk/app/models/content_blob.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/models/content_blob.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -1,3 +1,8 @@
+# myExperiment: app/models/content_blob.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
 class ContentBlob < ActiveRecord::Base
   validates_presence_of :data
 end

Added: trunk/app/models/content_type.rb (0 => 2176)


--- trunk/app/models/content_type.rb	                        (rev 0)
+++ trunk/app/models/content_type.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -0,0 +1,11 @@
+# myExperiment: app/models/content_type.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class ContentType < ActiveRecord::Base
+  format_attribute :description
+
+  validates_presence_of :title
+  validates_uniqueness_of :title
+end

Modified: trunk/app/models/workflow.rb (2175 => 2176)


--- trunk/app/models/workflow.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/models/workflow.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -22,6 +22,8 @@
            :dependent => :destroy
 
   belongs_to :content_blob
+  belongs_to :content_type
+
   
   # need to destroy the workflow versions and their content blobs to avoid orphaned records
   before_destroy { |w| w.versions.each do |wv|
@@ -65,6 +67,10 @@
     format_attribute :body
     
     belongs_to :content_blob
+    belongs_to :content_type
+
+    validates_presence_of :content_blob
+    validates_presence_of :content_type
     
     # :dependent => :destroy is not supported in belongs_to in rails 1.2.6
     after_destroy { |wv| wv.content_blob.destroy if wv.content_blob }
@@ -80,7 +86,7 @@
   
 # acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, { :rating => :integer } ],
 
-  acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, :type_display_name, :get_all_search_terms ],
+  acts_as_solr(:fields => [ :title, :body, :tag_list, :contributor_name, :type, :get_all_search_terms ],
                :include => [ :comments ]) if Conf.solr_enable
 
   acts_as_runnable
@@ -158,7 +164,9 @@
   end
 
   def processor_class
-    @processor_class ||= WorkflowTypesHandler.processor_class_for_content_type(self.content_type)
+    if self.content_type
+        @processor_class ||= WorkflowTypesHandler.processor_class_for_type_display_name(self.content_type.title)
+    end
   end
   
   def can_infer_metadata_for_this_type?
@@ -168,7 +176,7 @@
   end
   
   def type_display_name
-    WorkflowTypesHandler.type_display_name_for_content_type(self.content_type)  
+    content_type.title
   end
   
   def display_data_format
@@ -240,7 +248,14 @@
   end
 
   def components
-    processor_class.new(content_blob.data).get_components
+    if processor_class
+      processor_class.new(content_blob.data).get_components
+    else
+      XML::Node.new('components')
+    end
   end
 
+  def type
+    content_type.title
+  end
 end

Modified: trunk/app/views/blobs/_blob.rhtml (2175 => 2176)


--- trunk/app/views/blobs/_blob.rhtml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/views/blobs/_blob.rhtml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -9,7 +9,7 @@
 	      
 	      <p>
 	        <strong>File type:</strong><br />
-	        <%=h blob.content_type %>
+	        <%=h blob.content_type.title %>
 	      </p>
 	      
 	      <p>

Modified: trunk/app/views/blobs/_table.rhtml (2175 => 2176)


--- trunk/app/views/blobs/_table.rhtml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/views/blobs/_table.rhtml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -72,7 +72,7 @@
 							<% end %>
 						</div>
 						
-						<p style="font-size:85%;"><b>File type: </b><%= h blob.content_type %></p>
+						<p style="font-size:85%;"><b>File type: </b><%= h blob.content_type.title %></p>
 						
 						<p style="font-size: 85%;">
 							<a href="" file_path(blob) + '#ratings' -%>"><b>Rating: </b><%= number_with_precision(blob.rating, 1) %> / 5 (<%= pluralize blob.ratings_count, 'rating' %>)</a> |

Modified: trunk/app/views/blobs/show.rhtml (2175 => 2176)


--- trunk/app/views/blobs/show.rhtml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/views/blobs/show.rhtml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -57,7 +57,7 @@
 			
 			<p>
 			    <b>File type:</b>
-			    <%=h @blob.content_type %>
+			    <%=h @blob.content_type.title %>
 			</p>
 			
 			<br/>

Modified: trunk/app/views/mashup/api.rhtml (2175 => 2176)


--- trunk/app/views/mashup/api.rhtml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/views/mashup/api.rhtml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -25,7 +25,7 @@
 
 <div class="try_it_out_box">
   <p><b>Input:</b></p>
-  <textarea id="input" cols="100" style="font-size: 0.9em" rows="4"></textarea><br /><br />
+  <textarea id="input" cols="100" style="font-size: 0.9em" rows="10"></textarea><br /><br />
 </div>
 
 <div class="try_it_out_box">

Modified: trunk/app/views/workflows/index.rhtml (2175 => 2176)


--- trunk/app/views/workflows/index.rhtml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/app/views/workflows/index.rhtml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -1,6 +1,6 @@
 <div class="box_standout" style="text-align: center; margin-bottom: 1em; font-weight: bold; line-height: 1.5em;">
-	<% Workflow.count(:all, :group => 'content_type').sort{|x,y| y[1] <=> x[1]}.each do |arr| %>
-		| <%= pluralize(arr[1], (h(WorkflowTypesHandler.type_display_name_for_content_type(arr[0]) + " workflow"))) %>
+	<% Workflow.count(:all, :group => 'content_type_id').sort{|x,y| y[1] <=> x[1]}.each do |arr| %>
+		| <%= pluralize(arr[1], (h(ContentType.find_by_id(arr[0]).title + " workflow"))) %>
 	<% end %>
 	|
 </div>
@@ -14,4 +14,4 @@
 	<%= render :partial => "workflows/all_tags" %>
 <% end -%>
 
-<%= render :partial => "contributions/most_tabs", :locals => { :type => "Workflow" } %>
\ No newline at end of file
+<%= render :partial => "contributions/most_tabs", :locals => { :type => "Workflow" } %>

Modified: trunk/config/tables.xml


(Binary files differ)

Added: trunk/db/migrate/076_create_content_types.rb (0 => 2176)


--- trunk/db/migrate/076_create_content_types.rb	                        (rev 0)
+++ trunk/db/migrate/076_create_content_types.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -0,0 +1,126 @@
+# myExperiment: db/migrate/076_create_content_types.rb
+#
+# Copyright (c) 2009 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class CreateContentTypes < ActiveRecord::Migration
+  def self.up
+    create_table :content_types do |t|
+      t.column :user_id, :integer
+      t.column :title, :string
+      t.column :description, :text
+      t.column :description_html, :text
+      t.column :mime_type, :string
+      t.column :created_at, :datetime
+      t.column :updated_at, :datetime
+    end
+
+    add_column :workflows,         :content_type_id, :integer
+    add_column :workflow_versions, :content_type_id, :integer
+    add_column :blobs,             :content_type_id, :integer
+
+    # Create ContentType records for myExperiment
+
+    u = User.find_by_username(Conf.admins.first)
+
+    if u != nil
+
+      # Create ContentType entries for the existing workflows
+
+      workflow_type_to_content_type_id = {}
+
+      Workflow.find(:all).map do |w|
+        w.attributes["content_type"] end.uniq.each do |entry|
+
+        mime_type = 'application/octet-stream'
+        title     = nil
+
+        if entry == 'application/vnd.taverna.scufl+xml'
+
+          mime_type = 'application/vnd.taverna.scufl+xml'
+          title     = 'Taverna 1'
+
+        elsif entry == 'taverna2beta'
+
+          title = 'Taverna 2 beta'
+
+        elsif entry == 'trident_opc'
+
+          title = 'Trident (Package)'
+
+        elsif entry == 'application/xaml+xml'
+
+          title     = 'Trident (XOML)'
+          mime_type = 'application/xaml+xml'
+
+        elsif entry == 'Excel 2007 Macro-Enabled Workbook'
+
+          title     = 'Excel 2007 Macro-Enabled Workbook'
+          mime_type = 'application/vnd.ms-excel.sheet.macroEnabled.12.xlsm'
+
+        elsif entry == 'Makefile'
+
+          title     = 'Makefile'
+          mime_type = 'text/x-makefile'
+
+        else
+
+          title = entry
+
+        end
+
+        ft = ContentType.create(:user_id => u.id,
+          :mime_type => mime_type,
+          :title     => title)
+
+        workflow_type_to_content_type_id[entry] = ft.id
+
+      end
+
+      # Create ContentType entries for the existing blobs
+
+      blob_type_to_content_type_id = {}
+
+      Blob.find(:all).map do |b|
+        b.attributes["content_type"].strip end.uniq.each do |entry|
+        if !blob_type_to_content_type_id[entry]
+          ft = ContentType.create(:user_id => u.id, :mime_type => entry, :title => entry)
+
+          blob_type_to_content_type_id[entry] = ft.id
+        end
+      end
+
+      # Set the content_type_id for the existing workflows and blobs
+
+      Workflow.find(:all).each do |w|
+        execute("UPDATE workflows SET content_type_id = #{workflow_type_to_content_type_id[w.attributes["content_type"]]} WHERE id = #{w.id}")
+
+        w.versions.each do |v|
+          execute("UPDATE workflow_versions SET content_type_id = #{workflow_type_to_content_type_id[v.attributes["content_type"]]} WHERE id = #{v.id}")
+        end
+      end
+
+      Blob.find(:all).each do |b|
+        execute("UPDATE blobs SET content_type_id = #{blob_type_to_content_type_id[b.attributes["content_type"].strip]} WHERE id = #{b.id}")
+      end
+    end
+
+    remove_column :workflows,         :content_type
+    remove_column :workflow_versions, :content_type
+    remove_column :blobs,             :content_type
+  end
+
+  def self.down
+   
+    add_column :workflows,         :content_type, :string
+    add_column :workflow_versions, :content_type, :string
+    add_column :blobs,             :content_type, :string
+
+    remove_column :workflows,         :content_type_id
+    remove_column :workflow_versions, :content_type_id
+    remove_column :blobs,             :content_type_id
+
+    drop_table :content_types
+  end
+end
+

Modified: trunk/lib/rest.rb (2175 => 2176)


--- trunk/lib/rest.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/rest.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -530,7 +530,7 @@
     when 'PackRemoteEntry';        return "#{base}/external-pack-item.xml?id=#{ob.id}"
     when 'Tagging';                return "#{base}/tagging.xml?id=#{ob.id}"
 
-    when 'Creditation';     return nil
+    when 'Creditation';     return "#{base}/credit.xml?id=#{ob.id}"
     when 'Attribution';     return nil
 
     when 'Workflow::Version'; return "#{base}/workflow.xml?id=#{ob.workflow.id}&version=#{ob.version}"
@@ -547,7 +547,7 @@
     when 'Blob';                   return 'file'
     when 'Network';                return 'group'
     when 'Rating';                 return 'rating'
-    when 'Creditation';            return 'creditation'
+    when 'Creditation';            return 'credit'
     when 'Citation';               return 'citation'
     when 'Announcement';           return 'announcement'
     when 'Tag';                    return 'tag'
@@ -725,6 +725,7 @@
     title        = parse_element(data, :text,   '/workflow/title')
     description  = parse_element(data, :text,   '/workflow/description')
     license_type = parse_element(data, :text,   '/workflow/license-type')
+    type         = parse_element(data, :text,   '/workflow/type')
     content_type = parse_element(data, :text,   '/workflow/content-type')
     content      = parse_element(data, :binary, '/workflow/content')
     preview      = parse_element(data, :binary, '/workflow/preview')
@@ -734,8 +735,35 @@
     ob.title        = title        if title
     ob.body         = description  if description
     ob.license      = license_type if license_type
-    ob.content_type = content_type if content_type
 
+    # handle workflow type
+
+    if type
+
+      ob.content_type = ContentType.find_by_title(type)
+
+      if ob.content_type.nil?
+        ob.errors.add("Type")
+        return rest_response(400, :object => ob)
+      end
+
+    elsif content_type
+
+      content_types = ContentType.find_all_by_mime_type(content_type)
+  
+      if content_types.length == 1
+        ob.content_type = content_types.first
+      else
+        if content_types.empty?
+          ob.errors.add("Content type")
+        else
+          ob.errors.add("Content type", "matches more than one registered content type")
+        end
+
+        return rest_response(400, :object => ob)
+      end
+    end
+
     ob.content_blob = ContentBlob.new(:data ="" content) if content
 
     # Handle the preview and svg images.  If there's a preview supplied, use

Modified: trunk/lib/sanity_test.rb (2175 => 2176)


--- trunk/lib/sanity_test.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/sanity_test.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -90,7 +90,7 @@
   # workflows
 
   should_be_empty("All workflows must have a content type",
-      workflows.select do |w| w.content_type.length.zero? end)
+      workflows.select do |w| !w.content_type.nil? end)
 
   @results_string += "\nTotal tests:      address@hidden"
   @results_string += "Successful tests: address@hidden do |r| r == true end.length}\n"

Modified: trunk/lib/workflow_processors/interface.rb (2175 => 2176)


--- trunk/lib/workflow_processors/interface.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_processors/interface.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -19,11 +19,6 @@
       ""
     end
     
-    # MUST be unique across all processors
-    def self.content_type
-      ""
-    end
-    
     def self.display_data_format
       ""
     end

Modified: trunk/lib/workflow_processors/taverna2_beta.rb (2175 => 2176)


--- trunk/lib/workflow_processors/taverna2_beta.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_processors/taverna2_beta.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -18,11 +18,6 @@
       "Taverna 2 beta"
     end
     
-    # MUST be unique across all processors
-    def self.content_type
-      "taverna2beta"
-    end
-    
     def self.display_data_format
       "T2FLOW"
     end

Modified: trunk/lib/workflow_processors/taverna_scufl.rb (2175 => 2176)


--- trunk/lib/workflow_processors/taverna_scufl.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_processors/taverna_scufl.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -30,11 +30,6 @@
       "Taverna 1"
     end
     
-    # MUST be unique across all processors
-    def self.content_type
-      "application/vnd.taverna.scufl+xml"
-    end
-    
     def self.display_data_format
       "SCUFL"
     end

Modified: trunk/lib/workflow_processors/trident_opc.rb (2175 => 2176)


--- trunk/lib/workflow_processors/trident_opc.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_processors/trident_opc.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -18,11 +18,6 @@
       "Trident (Package)"
     end
     
-    # MUST be unique across all processors
-    def self.content_type
-      "trident_opc"
-    end
-    
     def self.display_data_format
       "Package"
     end

Modified: trunk/lib/workflow_processors/trident_xoml.rb (2175 => 2176)


--- trunk/lib/workflow_processors/trident_xoml.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_processors/trident_xoml.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -18,11 +18,6 @@
       "Trident (XOML)"
     end
     
-    # MUST be unique across all processors
-    def self.content_type
-      "application/xaml+xml"
-    end
-    
     def self.display_data_format
       "XOML"
     end

Modified: trunk/lib/workflow_types_handler.rb (2175 => 2176)


--- trunk/lib/workflow_types_handler.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/lib/workflow_types_handler.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -14,9 +14,6 @@
       @@processor_classes                       = [ ]
       @@workflow_types_that_can_infer_metadata  = [ ]
       @@processor_display_names                 = { }
-      @@processor_content_types                 = { }
-      @@type_display_name_content_types         = { }
-      @@content_type_type_display_names         = { }
       
       ObjectSpace.each_object(Class) do |c|
         if c < WorkflowProcessors::Interface
@@ -26,9 +23,6 @@
           
           # Also populate the lookup tables for ease of use later.
           @@processor_display_names[c.display_name] = c
-          @@processor_content_types[c.content_type] = c
-          @@type_display_name_content_types[c.display_name] = c.content_type
-          @@content_type_type_display_names[c.content_type] = c.display_name
         end
       end
     end
@@ -49,13 +43,11 @@
     
     # Then get the types stored in the database (removing duplicates)
     
-    proc_c_types = @@processor_content_types.keys
+    types_in_db = ContentType.find_by_sql("SELECT content_types.title FROM content_types, workflows WHERE content_types.id = workflows.content_type_id GROUP BY content_types.id")
     
-    types_in_db = Workflow.find_by_sql("SELECT content_type FROM workflows GROUP BY content_type")
-    
     types_in_db.each do |t|
-      c_type = t[:content_type]
-      @@types[c_type] = nil unless proc_c_types.include?(c_type) or @@types.has_key?(c_type)
+      c_type = t.title
+      @@types[c_type] = nil unless @@types.has_key?(c_type)
     end
   end
   
@@ -87,38 +79,6 @@
     end
   end
   
-  # Gets the processor class for the given workflow content type.
-  # Returns nil if no corresponding processor is found.
-  def self.processor_class_for_content_type(content_type)
-    if @@processor_content_types.has_key?(content_type)
-      return @@processor_content_types[content_type]
-    else
-      return nil
-    end
-  end
-  
-  # Gets the corresponding content type for the workflow type's display name provided.
-  # This tries to find a corresponding processor for the type display name,
-  # or the same type display name provided is returned as the content type.
-  def self.content_type_for_type_display_name(type_display_name)
-    if @@type_display_name_content_types.has_key?(type_display_name)
-      return @@type_display_name_content_types[type_display_name]
-    else
-      return type_display_name
-    end
-  end
-  
-  # Gets the corresponding workflow type display name for the content type provided.
-  # This tries to find a corresponding processor for the content type,
-  # or the same content type is returned as the type display name.
-  def self.type_display_name_for_content_type(content_type)
-    if @@content_type_type_display_names.has_key?(content_type)
-      return @@content_type_type_display_names[content_type]
-    else
-      return content_type
-    end
-  end
-  
   # Gets the list of workflow types (denoted by type display name) that support parsing and inferring metadata.
   def self.ones_that_can_infer_metadata
     @@type_display_names_that_can_infer_metadata
@@ -135,12 +95,7 @@
   # The following should map the unique key values (which are based on what the variable name is) with the corresponding processor class.
   # These act as quick lookup tables.
   @@processor_display_names = { }
-  @@processor_content_types = { }
   
-  # Map processor supported types (denoted by type display name) with corresponding content types, and vice versa.
-  @@type_display_name_content_types = { }
-  @@content_type_type_display_names = { }
-  
   # Maps workflow types (denoted by type display name) with their corresponding processor classes 
   # (or nil if no processor exists for that type).
   # This is a more definitive collection of the types available in the system than the @@processor_display_name collection,
@@ -158,9 +113,9 @@
     ("workflow_processors/" + f.gsub(/.rb/, '')).camelize.constantize
   end
 end
-
+
 # Load up the processor classes at startup
 logger.debug("Workflow type processors found: " + WorkflowTypesHandler.processor_classes.to_sentence)
 
 # Refresh the list of workflow types in the system
-WorkflowTypesHandler.refresh_all_known_types!
+WorkflowTypesHandler.refresh_all_known_types!

Modified: trunk/test/fixtures/blobs.yml (2175 => 2176)


--- trunk/test/fixtures/blobs.yml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/fixtures/blobs.yml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -9,7 +9,7 @@
   body: some text
   created_at: 2008-04-22 15:32:01
   license: by-sa
-  content_type: image/png
+  content_type_id: 1
   content_blob_id: 1
 
 text:
@@ -20,7 +20,7 @@
   title: developers.txt
   body: myExperiment instructions
   created_at: 2007-01-01 00:00:03
-  content_type: text/plain
+  content_type_id: 2
   content_blob_id: 2
 
 for_true_policy:
@@ -32,7 +32,7 @@
   body: some text
   created_at: 2008-04-22 15:32:01
   license: by-sa
-  content_type: image/png
+  content_type_id: 1
   content_blob_id: 1
 
 for_false_policy:
@@ -44,7 +44,7 @@
   body: some text
   created_at: 2008-04-22 15:32:01
   license: by-sa
-  content_type: image/png
+  content_type_id: 1
   content_blob_id: 1
 
 for_protected_policy:
@@ -56,7 +56,7 @@
   body: some text
   created_at: 2008-04-22 15:32:01
   license: by-sa
-  content_type: image/png
+  content_type_id: 1
   content_blob_id: 1
 
 for_public_policy:
@@ -68,6 +68,6 @@
   body: some text
   created_at: 2008-04-22 15:32:01
   license: by-sa
-  content_type: image/png
+  content_type_id: 1
   content_blob_id: 1
 

Added: trunk/test/fixtures/content_types.yml (0 => 2176)


--- trunk/test/fixtures/content_types.yml	                        (rev 0)
+++ trunk/test/fixtures/content_types.yml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -0,0 +1,33 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+png:
+  id: 1
+  user_id: 1
+  title: Portable Network Graphics
+  description: A graphics file format.
+  description_html: "<p>A graphics file format.</p>"
+  mime_type: image/png
+  created_at: 2008-04-22 15:32:01
+  updated_at: 2008-04-22 15:32:01
+
+
+text:
+  id: 2
+  user_id: 1
+  title: Plain text
+  description: This is a file containing plain text.
+  description_html: "<p>This is a file containing plain text.</p>"
+  mime_type: text/plain
+  created_at: 2008-04-22 15:32:01
+  updated_at: 2008-04-22 15:32:01
+
+taverna:
+  id: 3
+  user_id: 1
+  title: Taverna 1
+  description: The Taverna 1 workflow file format.
+  description_html: "<p>The Taverna 1 workflow file format.</p>"
+  mime_type: application/vnd.taverna.scufl+xml
+  created_at: 2008-04-22 15:32:01
+  updated_at: 2008-04-22 15:32:01
+

Modified: trunk/test/fixtures/workflow_versions.yml (2175 => 2176)


--- trunk/test/fixtures/workflow_versions.yml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/fixtures/workflow_versions.yml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -13,7 +13,7 @@
   created_at: 2008-02-14 20:19:18
   updated_at: 2008-02-14 20:19:18
   revision_comments: 
-  content_type: application/vnd.taverna.scufl+xml
+  content_type_id: 3
   content_blob_id: 3
 
 workflow_branch_choice_version1:
@@ -30,5 +30,5 @@
   created_at: 2008-04-11 22:19:33
   updated_at: 2008-05-14 06:45:08
   revision_comments: 
-  content_type: application/vnd.taverna.scufl+xml
+  content_type_id: 3
   content_blob_id: 4

Modified: trunk/test/fixtures/workflows.yml (2175 => 2176)


--- trunk/test/fixtures/workflows.yml	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/fixtures/workflows.yml	2009-04-24 14:32:02 UTC (rev 2176)
@@ -12,7 +12,7 @@
   updated_at: 2008-02-14 20:19:18
   license: by-sa
   current_version: 1
-  content_type: application/vnd.taverna.scufl+xml
+  content_type_id: 3
   content_blob_id: 3
 
 workflow_branch_choice:
@@ -28,5 +28,5 @@
   updated_at: 2008-05-14 06:45:08
   license: by-sa
   current_version: 1
-  content_type: application/vnd.taverna.scufl+xml
+  content_type_id: 3
   content_blob_id: 4

Modified: trunk/test/functional/blobs_controller_test.rb (2175 => 2176)


--- trunk/test/functional/blobs_controller_test.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/functional/blobs_controller_test.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -10,7 +10,7 @@
 class BlobsController; def rescue_action(e) raise e end; end
 
 class BlobsControllerTest < Test::Unit::TestCase
-  fixtures :blobs, :users, :contributions, :content_blobs, :workflows, :packs, :policies, :permissions, :networks
+  fixtures :blobs, :users, :contributions, :content_blobs, :workflows, :packs, :policies, :permissions, :networks, :content_types
 
   def setup
     @controller = BlobsController.new

Modified: trunk/test/functional/networks_controller_test.rb (2175 => 2176)


--- trunk/test/functional/networks_controller_test.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/functional/networks_controller_test.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -10,7 +10,7 @@
 class NetworksController; def rescue_action(e) raise e end; end
 
 class NetworksControllerTest < Test::Unit::TestCase
-  fixtures :networks, :users
+  fixtures :networks, :users, :content_types
 
   def setup
     @controller = NetworksController.new

Modified: trunk/test/functional/reviews_controller_test.rb (2175 => 2176)


--- trunk/test/functional/reviews_controller_test.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/functional/reviews_controller_test.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -5,7 +5,7 @@
 class ReviewsController; def rescue_action(e) raise e end; end
 
 class ReviewsControllerTest < Test::Unit::TestCase
-  fixtures :reviews, :users, :workflows, :workflow_versions, :contributions, :blobs, :packs, :policies, :permissions
+  fixtures :reviews, :users, :workflows, :workflow_versions, :contributions, :blobs, :packs, :policies, :permissions, :content_types
 
   def setup
     @controller = ReviewsController.new

Modified: trunk/test/functional/workflows_controller_test.rb (2175 => 2176)


--- trunk/test/functional/workflows_controller_test.rb	2009-04-22 12:29:31 UTC (rev 2175)
+++ trunk/test/functional/workflows_controller_test.rb	2009-04-24 14:32:02 UTC (rev 2176)
@@ -10,7 +10,7 @@
 class WorkflowsController; def rescue_action(e) raise e end; end
 
 class WorkflowsControllerTest < Test::Unit::TestCase
-  fixtures :workflows, :users, :contributions, :workflow_versions, :content_blobs, :blobs, :packs, :policies, :permissions, :networks
+  fixtures :workflows, :users, :contributions, :workflow_versions, :content_blobs, :blobs, :packs, :policies, :permissions, :networks, :content_types
 
   def setup
     @controller = WorkflowsController.new

reply via email to

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