<commit_before>class UpwizardController < ApplicationController
  include Wicked::Wizard
  steps :publish, :decide, :go_sparql, :go_filestore, :go_transform, :go_back

  def create
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :update, @upwizard
    @upwizard.update_attributes(upwizard_params)
    fill_filedetails_if_empty
    @upwizard.save
    calculate_filetype
    #byebug
  end

  def index
    #byebug
    upwizard = Upwizard.new  # Create new wizard
    upwizard.user = current_user
    authorize! :create, upwizard
    upwizard.update_attributes(params.permit([:task]))
    upwizard.save

    goto_step = steps.first
    options = request.query_parameters

    options = options.respond_to?(:to_h) ? options.to_h : options
    options = { :controller => wicked_controller,
                :action     => 'show',
                :id         => goto_step || params[:id],
                :wiz_id     => upwizard.id,
                :only_path  => true
               }.merge options
    redirect_to url_for(options)
  end

  def destroy
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :destroy, @upwizard
    @upwizard.destroy
  end

  def show
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :read, @upwizard
    calculate_filetype
    #byebug
    case step
    when :go_filestore
      redirect_to_create_filestore
    when :go_sparql
      redirect_to_create_sparql_endpoint
    when :go_transform
      redirect_to_create_transformation
    when :go_back
      redirect_to_homepage
    else
      render_wizard
    end
  end

  def update
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :update, @upwizard

    # Delete the old file object if we get a new file object
    unless upwizard_params[:file] == nil
      unless @upwizard.file == nil
        @upwizard.file.destroy
        @upwizard.file_size = 0
        @upwizard.file_content_type = ""
        @upwizard.original_filename = ""
      end
    end
    @upwizard.update_attributes(upwizard_params)
    fill_filedetails_if_empty
    @upwizard.save
    calculate_filetype
    #byebug
    render_wizard
  end



private<commit_msg>Fixed upwizard to accept new file and delete the old one<commit_after>class UpwizardController < ApplicationController
  include Wicked::Wizard
  steps :publish, :decide, :go_sparql, :go_filestore, :go_transform, :go_back

  def create
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :update, @upwizard
    @upwizard.update_attributes(upwizard_params)
    fill_filedetails_if_empty
    @upwizard.save
    calculate_filetype
    #byebug
  end

  def index
    #byebug
    upwizard = Upwizard.new  # Create new wizard
    upwizard.user = current_user
    authorize! :create, upwizard
    upwizard.update_attributes(params.permit([:task]))
    upwizard.save

    goto_step = steps.first
    options = request.query_parameters

    options = options.respond_to?(:to_h) ? options.to_h : options
    options = { :controller => wicked_controller,
                :action     => 'show',
                :id         => goto_step || params[:id],
                :wiz_id     => upwizard.id,
                :only_path  => true
               }.merge options
    redirect_to url_for(options)
  end

  def destroy
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :destroy, @upwizard
    @upwizard.destroy
  end

  def show
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :read, @upwizard
    calculate_filetype
    #byebug
    case step
    when :go_filestore
      redirect_to_create_filestore
    when :go_sparql
      redirect_to_create_sparql_endpoint
    when :go_transform
      redirect_to_create_transformation
    when :go_back
      redirect_to_homepage
    else
      render_wizard
    end
  end

  def update
    @upwizard = Upwizard.find(params[:wiz_id])
    authorize! :update, @upwizard

    # Delete the old file object if we get a new file object
    unless upwizard_params[:file] == nil
      unless @upwizard.file == nil
        @upwizard.file.delete
        @upwizard.file = nil
        @upwizard.file_size = 0
        @upwizard.file_content_type = ""
        @upwizard.original_filename = ""
      end
    end
    @upwizard.update_attributes(upwizard_params)
    fill_filedetails_if_empty
    @upwizard.save
    calculate_filetype
    #byebug
    render_wizard
  end



private
{'fraction_non_alphanumeric': 0.08148824469299247, 'fraction_numerical': 0.00045651677699155445, 'mean_word_length': 2.748502994011976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1994919', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1454, 'n_words': 293}