Instantly share code, notes, and snippets.

Embed
What would you like to do?
Old create method
# POST /issues
# POST /issues.xml
def create
@issue = Issue.new(params[:issue])
# A D D N E W C A U S E / E F F E C T
if params[:action_carrier]
# Read in the :type passed with form to recognize whether this is a Cause or Effect
@causality = params[:action_carrier].to_s
@causality_id = params[:id_carrier]
# * * * * Check whether the Cause/effect already exists as an issue * * * *
if Issue.exists?(:wiki_url => [@issue.wiki_url])
# Retrieve the ID of existing issue
@wikiurl = @issue.wiki_url
@issueid = Issue.where(:wiki_url => @wikiurl).select('id').first.id
# Define a new Relationship
@relationship = Relationship.new
# Populate User_Id if relationship was created by a logged in User
if @issue.user_id.to_s != ""
@relationship.user_id = @issue.user_id
end
# It is a Cause
if @causality == "C"
@relationship.cause_id = @issueid
@relationship.issue_id = @causality_id
@notice = 'New cause linked Successfully'
end
# It is an Inhibitor
if @causality == "I"
@relationship.cause_id = @issueid
@relationship.issue_id = @causality_id
@relationship.relationship_type = 'I'
@notice = 'New reducing issue linked Successfully'
end
# It is a Superset
if @causality == "P"
@relationship.cause_id = @issueid
@relationship.issue_id = @causality_id
@relationship.relationship_type = 'H'
@notice = 'New superset linked Successfully'
end
# It is an Effect
if @causality == "E"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issueid
@notice = 'New effect linked Successfully'
end
# It is an Inhibited
if @causality == "R"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issueid
@relationship.relationship_type = 'I'
@notice = 'New reduced issue linked Successfully'
end
# It is a Subset
if @causality == "S"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issueid
@relationship.relationship_type = 'H'
@notice = 'New subset linked Successfully'
end
# Save the Relationship
if @relationship.save
# remove duplicate suggestions if any
if Suggestion.exists?(:causality => @causality, :wiki_url => [@issue.wiki_url], :issue_id=>@causality_id)
@suggestion_id = Suggestion.where(:causality => @causality, :wiki_url => [@issue.wiki_url], :issue_id=>@causality_id).select('id').first.id
@suggestion = Suggestion.find(@suggestion_id)
@suggestion.update_attributes('status' => 'A')
@suggestion.save
end
Reputation::Utils.reputation(:action=>:create, \
:type=>:relationship, \
:id=>@relationship.id, \
:me=>@relationship.user_id, \
:undo=>false, \
:calculate=>true)
redirect_to(:back, :notice => @notice)
else
@notice = @relationship.errors.full_messages
redirect_to(:back, :notice => @notice.to_s + ' Causal link was not created')
end
# * * * * The issue pointing to this wiki_url does not exist so create new issue before relation * * * *
else
if @issue.save
suggested_causes, suggested_effects, suggested_inhibitors, suggested_reduced, suggested_parents, suggested_subsets = Suggestion.new.get_suggestions(@issue.wiki_url, @issue.id)
Suggestion.create(suggested_causes)
Suggestion.create(suggested_effects)
Suggestion.create(suggested_inhibitors)
Suggestion.create(suggested_reduced)
Suggestion.create(suggested_parents)
Suggestion.create(suggested_subsets)
Reputation::Utils.reputation(:action=>:create, \
:type=>:issue, \
:me=>@issue.user_id, \
:undo=>false, \
:calculate=>true)
# Define a new Relationship
@relationship = Relationship.new
# Populate User_Id if relationship was created by a logged in User
if @issue.user_id.to_s != ""
@relationship.user_id = @issue.user_id
end
# It is a Cause
if @causality == "C"
@relationship.cause_id = @issue.id
@relationship.issue_id = @causality_id
@notice = 'New Issue was created and linked as a cause'
end
# It is an Inhibitor
if @causality == "I"
@relationship.cause_id = @issue.id
@relationship.issue_id = @causality_id
@relationship.relationship_type = 'I'
@notice = 'New Issue was created and linked as reducer'
end
# It is a Superset
if @causality == "P"
@relationship.cause_id = @issue.id
@relationship.issue_id = @causality_id
@relationship.relationship_type = 'H'
@notice = 'New Issue was created and linked as a superset'
end
# It is an Effect
if @causality == "E"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issue.id
@notice = 'New Issue was created and linked as an effect'
end
# It is an Inhibited
if @causality == "R"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issue.id
@relationship.relationship_type = 'I'
@notice = 'New Issue was created and linked as reduced'
end
# It is a Subset
if @causality == "S"
@relationship.cause_id = @causality_id
@relationship.issue_id = @issue.id
@relationship.relationship_type = 'H'
@notice = 'New Issue was created and linked as a subset'
end
# Save the Relationship
if @relationship.save
# remove duplicate suggestions if any
if Suggestion.exists?(:causality => @causality, :wiki_url => [@issue.wiki_url], :issue_id=>@causality_id)
@suggestion_id = Suggestion.where(:causality => @causality, :wiki_url => [@issue.wiki_url], :issue_id=>@causality_id).select('id').first.id
@suggestion = Suggestion.find(@suggestion_id)
@suggestion.update_attributes('status' => 'A')
@suggestion.save
end
Reputation::Utils.reputation(:action=>:create, \
:type=>:relationship, \
:id=>@relationship.id, \
:me=>@relationship.user_id, \
:undo=>false, \
:calculate=>true)
redirect_to(:back, :notice => @notice)
else
@notice = @relationship.errors.full_messages
redirect_to(:back, :notice => @notice.to_s + ' Causal link was not created')
end
# some problem occurred and the Issue could not be saved
else
@notice = @issue.errors.full_messages
redirect_to(:back, :notice => @notice.to_s + ' Causal link was not created')
end
#code to generate suggestions for the Newly created Issue
# Define new Suggestions
Suggestion.new(params[:issue_id=>@issue.id, :wiki_url=>@issue.wiki_url])
end
else
respond_to do |format|
if @issue.save
# Define new Suggestions
#@suggestion = Suggestion.new(params[:issue_id=>@issue.id, :wiki_url=>@issue.wiki_url])
#@suggestion.create
suggested_causes, suggested_effects, suggested_inhibitors, suggested_reduced, suggested_parents, suggested_subsets = Suggestion.new.get_suggestions(@issue.wiki_url, @issue.id)
Suggestion.create(suggested_causes)
Suggestion.create(suggested_effects)
Suggestion.create(suggested_inhibitors)
Suggestion.create(suggested_reduced)
Suggestion.create(suggested_parents)
Suggestion.create(suggested_subsets)
format.html { redirect_to(@issue, :notice => 'Issue was successfully created.') }
format.xml { render :xml => @issue, :status => :created, :location => @issue }
else
format.html { render :action => "new" }
format.xml { render :xml => @issue.errors, :status => :unprocessable_entity }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment