Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions BrainPortal/app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def create #:nodoc:
@task.errors.add(:tool_config_id, 'is on an Execution Server that is currently offline')
end

unless @task.errors.empty? && @task.valid?
if @task.errors.any? || ! @task.valid?
flash.now[:error] += messages
initialize_common_form_values
respond_to do |format|
Expand All @@ -405,16 +405,47 @@ def create #:nodoc:
return
end

# Prepare final list of tasks; from the one maintask object we have,
# we get a full array of clones of that task in tasklist
tasklist,ftl_message = @task.wrapper_final_task_list

# Revalidate everything for all the tasks in the new tasklist
# This is kind of costly, but we have no choices if special validation
# modules have been loaded for after_form().
# As soon as any task in the task list is not valid, we stop checking and
# return to the form.
af_messages = "" # 'after_form' messages
tasklist.each_with_index do |task,idx|
af_messages += task.wrapper_after_form
af_messages = af_messages.split("\n").uniq.join("\n") # remove duplicate messages, if any
next if task.errors.empty? && task.valid? # move on to next task if everything ok

# Found at least one faulty task, so inform user
task.errors.each { |key,message| @task.errors.add(key,message) } # copy error messages, if any
@task.errors.add(:base, "While creating a set of tasks, at least one of them was found to be invalid, probably because a file selected as input was not appropriate.")
flash.now[:error] += af_messages

# Re-render the form
initialize_common_form_values
respond_to do |format|
format.html { render :action => 'new' }
format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
format.json { render :json => @task.errors, :status => :unprocessable_entity }
end
return
end

# Create a bunch of tasks and launch them, either in background or in foreground
tasklist,messages = create_tasklist_from_initial_task(@task)
tl_messages = create_tasklist_from_initial_task(@task,tasklist)

if tasklist.size == 1
flash[:notice] += "Launching a #{@task.pretty_name} task in background."
else
flash[:notice] += "Launching #{tasklist.size} #{@task.pretty_name} tasks in background."
end
flash[:notice] += "\n" unless messages.blank? || messages =~ /\n$/
flash[:notice] += messages + "\n" unless messages.blank?
flash[:notice] += "\n#{af_messages.strip}" if af_messages.present?
flash[:notice] += "\n#{ftl_message.strip}" if ftl_message.present?
flash[:notice] += "\n#{tl_messages.strip}" if tl_messages.present?

# Increment the number of times the user has launched this particular tool
tool_id = @task.tool.id
Expand Down Expand Up @@ -1395,7 +1426,7 @@ def create_initial_task_from_form(new_task_info, tool_id = nil) #:nodoc:
# Part of the create() process for a task
#
# Code extracted from the old monolithic 'create'
def create_tasklist_from_initial_task(maintask) #:nodoc:
def create_tasklist_from_initial_task(maintask,tasklist) #:nodoc:

messages = ""

Expand All @@ -1421,14 +1452,6 @@ def create_tasklist_from_initial_task(maintask) #:nodoc:
messages += "Warning: parallelization cannot be performed until the admin configures a Tool for it.\n"
end

# Prepare final list of tasks; from the one maintask object we have,
# we get a full array of clones of that task in tasklist
tasklist,task_list_message = maintask.wrapper_final_task_list
if task_list_message.present?
messages += "\n" if messages.present?
messages += task_list_message
end

# Spawn a background process to launch the tasks.
# In case of API requests, we don't spawn.
CBRAIN.spawn_with_active_records_if(! api_request?, :admin, "Spawn Tasks") do
Expand Down Expand Up @@ -1502,7 +1525,7 @@ def create_tasklist_from_initial_task(maintask) #:nodoc:

end # CBRAIN spawn_if block

return tasklist,messages
return messages
end

# Some useful variables for the views for 'new' and 'edit'
Expand Down
14 changes: 9 additions & 5 deletions BrainPortal/app/models/boutiques_portal_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ def final_task_list #:nodoc:
end
end

# Re-introduce the file IDs of the task list, in case the main form
# needs to be re-rendered.
self.params[:interface_userfile_ids] |= task_array_userfiles_ids

return tasklist.flatten
end # When only one file input

Expand Down Expand Up @@ -505,8 +509,8 @@ def validateCols(cbcsv,id)
# Ensure that the +input+ parameter is not null and matches a generic tool
# parameter type (:file, :numeric, :string or :flag) before converting the
# parameter's value to the corresponding Ruby type (if appropriate).
# For example, sanitize_param(someinput) where someinput's name is 'deviation'
# and someinput's type is 'numeric' would validate that
# For example, sanitize_param(someinput) where someinput's name is 'deviation'
# and someinput's type is 'numeric' would validate that
# self.params['invoke']['deviation'] is a number and then convert it to a Ruby Float or
# Integer.
#
Expand Down Expand Up @@ -548,7 +552,7 @@ def sanitize_param(input)

# Taken userfile names. An error will be raised if two input files have the
# same name.
@taken_files ||= Set.new
@taken_files ||= {}

# Fetch the parameter and convert to an Enumerable if required
values = invoke_params[name]
Expand Down Expand Up @@ -608,10 +612,10 @@ def sanitize_param(input)
next nil # remove bad value
end

if @taken_files.include?(file.id)
if @taken_files[file.id].present? && @taken_files[file.id] != input.id
params_errors.add(invokename, ": file name already in use (#{file.name})")
else
@taken_files.add(file.id)
@taken_files[file.id] = input.id
end

end
Expand Down
11 changes: 11 additions & 0 deletions BrainPortal/app/models/portal_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,17 @@ def params_errors
@params_errors_cache
end

# Needed in case of a dup()
def params_errors_clear #:nodoc:
@params_errors_cache = nil
end

def dup #:nodoc:
obj = super
obj.params_errors_clear
obj
end

# This method returns a 'pretty' name for a params attributes.
# This implementation will try to look up a hash table returned
# by the class method pretty_params_names() first, so an
Expand Down
Loading