myexperiment-hackers
[Top][All Lists]
Advanced

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

[myexperiment-hackers] [2837] branches/datasets: Fixed issue where dupli


From: noreply
Subject: [myexperiment-hackers] [2837] branches/datasets: Fixed issue where duplicate ports were created.
Date: Wed, 23 Nov 2011 06:28:54 -0500 (EST)

Revision
2837
Author
fbacall
Date
2011-11-23 06:28:53 -0500 (Wed, 23 Nov 2011)

Log Message

Fixed issue where duplicate ports were created. Added destroy callbacks to avoid orphaned records

Modified Paths

Added Paths

Diff

Modified: branches/datasets/app/controllers/data_items_controller.rb (2836 => 2837)


--- branches/datasets/app/controllers/data_items_controller.rb	2011-11-22 16:07:16 UTC (rev 2836)
+++ branches/datasets/app/controllers/data_items_controller.rb	2011-11-23 11:28:53 UTC (rev 2837)
@@ -137,19 +137,26 @@
     port_type = params[:workflow_port_type]
     version = @data_set.workflow_version
 
+    #Try and get existing port from relationship
     if @relationship.objekt
-      #If port has changed...
+      #But only if port wasn't changed in the form
       if (params[:workflow_port] == @relationship.objekt.name) &&
-          (port_type == @relationship.objekt.port_type.to_s) &&
-          (version == @relationship.objekt.workflow_version)
-        #Try and find one that already exists with given params
-        port = WorkflowPort.find(:first, :conditions => ["name = ? AND port_type = ? AND workflow_id = ? AND workflow_version = ?",
-                                                         params[:workflow_port], port_type, @workflow.id, version])
+         (port_type == @relationship.objekt.port_type.to_s) &&
+         (version == @relationship.objekt.workflow_version)
+
+        port = @relationship.objekt
       end
     end
 
-    #If still no port, make one
+    #Try finding a port with identical attributes
     unless port
+      port = WorkflowPort.find(:first,
+                               :conditions => ["name = ? AND port_type = ? AND workflow_id = ? AND workflow_version = ?",
+                                                             params[:workflow_port], port_type, @workflow.id, version])
+    end
+
+    #If we still don't have a port, make one
+    unless port
       #Check if port name from form is a valid port name
       workflow_model = @data_set.workflow.get_workflow_model_object(version)
       collection = ((port_type == "input") ? workflow_model.sources : workflow_model.sinks)
@@ -193,7 +200,6 @@
   end
 
   def auth
-    puts action_name
     unless Authorization.is_authorized?(action_name, nil, @workflow, current_user)
       respond_to do |format|
         format.html { render :nothing => true, :status => 403 }

Modified: branches/datasets/app/models/relationship.rb (2836 => 2837)


--- branches/datasets/app/models/relationship.rb	2011-11-22 16:07:16 UTC (rev 2836)
+++ branches/datasets/app/models/relationship.rb	2011-11-23 11:28:53 UTC (rev 2837)
@@ -18,7 +18,7 @@
   after_destroy :touch_context
 
   #To avoid leaving orphaned text data
-  before_destroy :destroy_text_data
+  after_destroy :destroy_text_data
 
   def touch_context
     # Rails 2 - use context.destroyed? instead of context.contribution.nil?

Modified: branches/datasets/app/models/workflow.rb (2836 => 2837)


--- branches/datasets/app/models/workflow.rb	2011-11-22 16:07:16 UTC (rev 2836)
+++ branches/datasets/app/models/workflow.rb	2011-11-23 11:28:53 UTC (rev 2837)
@@ -72,6 +72,9 @@
     
     # :dependent => :destroy is not supported in belongs_to in rails 1.2.6
     after_destroy { |wv| wv.content_blob.destroy if wv.content_blob }
+
+    # Destroy data sets + ports linked to this version after destroy
+    after_destroy :clean_up_data_sets_and_ports
     
     # Update the parent contribution model buy only if this isn't the current version (because the workflow model will take care of that).
     # This is required to keep the contribution's updated_at field accurate.
@@ -98,6 +101,12 @@
       @display_data_format = (klass.nil? ? self.file_ext : klass.display_data_format)
     end
 
+    def clean_up_data_sets_and_ports
+      (workflow.data_sets + workflow.workflow_ports).select { |d| d.workflow_version == version }.each do |d|
+        d.destroy
+      end
+    end
+
   end
   
   non_versioned_columns.push("license_id", "tag_list", "preview_id")

Modified: branches/datasets/app/models/workflow_port.rb (2836 => 2837)


--- branches/datasets/app/models/workflow_port.rb	2011-11-22 16:07:16 UTC (rev 2836)
+++ branches/datasets/app/models/workflow_port.rb	2011-11-23 11:28:53 UTC (rev 2837)
@@ -3,32 +3,27 @@
 # Copyright (c) 2011 University of Manchester and the University of Southampton.
 # See license.txt for details.
 
+
+#WorkflowPort - a model of an input or output port on a workflow. Its primary use is to allow relationships to be stated
+# between things and workflows on a more fine-grained level. WorkflowPorts are created "lazily" as needed, as opposed to
+# being created when the workflow is uploaded. They are only removed when the workflow is destroyed.
+
 class WorkflowPort < ActiveRecord::Base
 
   belongs_to :workflow
 
   validates_presence_of :name, :port_type, :workflow_id, :workflow_version
 
-  #This doesn't work, messes up because port_type is a symbol?
-  #validates_uniqueness_of :name, :scope => [:port_type, :workflow_id, :workflow_version]
+  validates_uniqueness_of :name, :scope => [:port_type, :workflow_id, :workflow_version]
 
-  # Adapted from #3 of: http://zargony.com/2008/04/28/five-tips-for-developing-rails-applications
-  validates_inclusion_of :port_type, :in => [:input, :output]
+  validates_inclusion_of :port_type, :in => ["input", "output"]
 
-  def port_type
-    read_attribute(:port_type).to_sym
-  end
-
-  def port_type=(value)
-    write_attribute(:port_type, value.to_s)
-  end
-
   def input?
-    port_type == :input
+    port_type == "input"
   end
 
   def output?
-    port_type == :output
+    port_type == "output"
   end
 
 end
\ No newline at end of file

Modified: branches/datasets/app/views/data_sets/show.rhtml (2836 => 2837)


--- branches/datasets/app/views/data_sets/show.rhtml	2011-11-22 16:07:16 UTC (rev 2836)
+++ branches/datasets/app/views/data_sets/show.rhtml	2011-11-23 11:28:53 UTC (rev 2837)
@@ -7,9 +7,6 @@
   </div>
   <div style="float: right; margin: 0.5em">
     <ul class="sectionIcons">
-      <li>
-        <%= icon('download', "#", nil, nil, 'Download this data set') %>
-      </li>
       <% if mine?(@workflow) %>
         <li>
           <%= icon('edit', edit_workflow_data_set_path(@workflow, @data_set), nil, nil, 'Edit data set') %>

Added: branches/datasets/test/fixtures/data_sets.yml ( => )


Added: branches/datasets/test/fixtures/workflow_ports.yml
===================================================================

Added: branches/datasets/test/functional/data_sets_controller_test.rb ( => )


Added: branches/datasets/test/unit/data_set_test.rb
===================================================================
--- branches/datasets/test/unit/data_set_test.rb	                        (rev 0)
+++ branches/datasets/test/unit/data_set_test.rb	2011-11-23 11:28:53 UTC (rev 2837)
@@ -0,0 +1,14 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class DataSetTest < Test::Unit::TestCase
+  fixtures :workflows
+  fixtures :blobs
+  fixtures :workflow_ports
+  fixtures :data_sets
+  fixtures :text_data
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end

reply via email to

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