Modified: trunk/app/models/content_type.rb (2185 => 2186)
--- trunk/app/models/content_type.rb 2009-04-30 13:01:25 UTC (rev 2185)
+++ trunk/app/models/content_type.rb 2009-05-05 12:14:48 UTC (rev 2186)
@@ -6,6 +6,8 @@
class ContentType < ActiveRecord::Base
format_attribute :description
+ belongs_to :user
+
validates_presence_of :title
validates_uniqueness_of :title
end
Modified: trunk/db/migrate/076_create_content_types.rb (2185 => 2186)
--- trunk/db/migrate/076_create_content_types.rb 2009-04-30 13:01:25 UTC (rev 2185)
+++ trunk/db/migrate/076_create_content_types.rb 2009-05-05 12:14:48 UTC (rev 2186)
@@ -19,90 +19,74 @@
add_column :workflow_versions, :content_type_id, :integer
add_column :blobs, :content_type_id, :integer
- # Create ContentType records for myExperiment
+ # Create ContentType records for workflows with processors
u = User.find_by_username(Conf.admins.first)
- if u != nil
+ taverna_1 = ContentType.create(:title => 'Taverna 1', :mime_type => 'application/vnd.taverna.scufl+xml', :user => u)
+ taverna_2 = ContentType.create(:title => 'Taverna 2 beta', :mime_type => 'application/octet-stream', :user => u)
+ trident_x = ContentType.create(:title => 'Trident (XOML)', :mime_type => 'application/xaml+xml', :user => u)
+ trident_p = ContentType.create(:title => 'Trident (Package)', :mime_type => 'application/octet-stream', :user => u)
- # Create ContentType entries for the existing workflows
+ # Create ContentType entries for the existing workflows
- workflow_type_to_content_type_id = {}
+ workflow_type_to_content_type_id = {}
- Workflow.find(:all).map do |w|
- w.attributes["content_type"] end.uniq.each do |entry|
+ Workflow.find(:all).map do |w|
+ w.attributes["content_type"] end.uniq.each do |entry|
- mime_type = 'application/octet-stream'
- title = nil
+ mime_type = 'application/octet-stream'
- if entry == 'application/vnd.taverna.scufl+xml'
+ if entry == 'application/vnd.taverna.scufl+xml'
+ workflow_type_to_content_type_id[entry] = taverna_1.id
+ next
+ end
- mime_type = 'application/vnd.taverna.scufl+xml'
- title = 'Taverna 1'
+ if entry == 'taverna2beta'
+ workflow_type_to_content_type_id[entry] = taverna_2.id
+ next
+ end
- elsif entry == 'taverna2beta'
+ if entry == 'application/xaml+xml'
+ workflow_type_to_content_type_id[entry] = trident_x.id
+ next
+ end
- title = 'Taverna 2 beta'
+ if entry == 'trident_opc'
+ workflow_type_to_content_type_id[entry] = trident_p.id
+ next
+ end
- elsif entry == 'trident_opc'
+ ft = ContentType.create(:user_id => u.id, :title => entry, :mime_type => 'application/octet-stream')
- title = 'Trident (Package)'
+ workflow_type_to_content_type_id[entry] = ft.id
+ end
- elsif entry == 'application/xaml+xml'
+ # Create ContentType entries for the existing blobs
- title = 'Trident (XOML)'
- mime_type = 'application/xaml+xml'
+ blob_type_to_content_type_id = {}
- elsif entry == 'Excel 2007 Macro-Enabled Workbook'
+ 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)
- 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
-
+ blob_type_to_content_type_id[entry] = ft.id
end
+ end
- # Create ContentType entries for the existing blobs
+ # Set the content_type_id for the existing workflows and blobs
- blob_type_to_content_type_id = {}
+ 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}")
- 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
+ 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
- # 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
+ 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
remove_column :workflows, :content_type