<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Abonam</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Abonam"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Abonam"/>
	<updated>2026-08-21T22:16:03Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=100397</id>
		<title>CSC/ECE 517 Fall 2015 E1579 Instructor account creation over the web</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=100397"/>
		<updated>2015-12-07T20:19:01Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  '''Introduction to Expertiza''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Expertiza[https://expertiza.ncsu.edu/wiki/] is a project developed using Ruby on Rails[https://en.wikipedia.org/wiki/Ruby_on_Rails]. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub[https://en.wikipedia.org/wiki/GitHub]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
== '''Purpose''' ==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to allow new users to access the system and experiment with all the features of Expertiza and make a “Demo like” feel for the new user where the user can experiment with it.  This project adds  a new feature of Instructor Creation over the web which is completely different from the previous way the user and instructor accounts were created by existing super administrators. Code will be restructured to convey readability, handle exceptions.&lt;br /&gt;
 &lt;br /&gt;
== '''Scope''' ==&lt;br /&gt;
&lt;br /&gt;
The scope of this project will involve adding a new View/Page that would input all the new user(Instructor) Details which would be a signup page.The signup page will be designed in a way which would have security feature as Captchas embedded into it.  There would be another new View/Page created that would act as the landing page for the newly created Demo_instructor  which would contain specific instructions/ Video on how to add assignments, add students to the assignments. Also an email is sent soon after a successful creation of such user. The project also deals with providing no access to the public features, which could be extended manually by a super admin.The code will also be tested well to ensure the robustness of newly added functionality without compromising the existing working functionalities.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
==== Project outcomes ====&lt;br /&gt;
*Create a new role by SuperAdmin&lt;br /&gt;
**Fixed the drop-down menu for Based on roles option while creating a new.&lt;br /&gt;
**Fixed add new permissions for a role functionality.&lt;br /&gt;
&lt;br /&gt;
*Allow people to request instructor accounts over the web. &lt;br /&gt;
**Added a Link in Main Screen “Demo Instructor signup”.&lt;br /&gt;
**Created a New Page where the User Fills the details wrt to a new Instructor Privileged access.&lt;br /&gt;
**Included Captcha Functionality and other necessary features for a secure Sign Up.&lt;br /&gt;
**Fixed role permission deletion functionality.&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Creation of Instructor Account.&lt;br /&gt;
**Redirect the New Instructor back to the Login Page.&lt;br /&gt;
**Send an email to the super Admin notifying him of a new Instructor that has been created over the web&lt;br /&gt;
**Send an email to new user with username and new password details. &lt;br /&gt;
&lt;br /&gt;
*Upon Successful Login of the New Instructor&lt;br /&gt;
**Redirect the User to a Instruction Page which gives information on how to create an assignments and register students for it and other basic information needed. Basically a instructions page that can be used for providing information.&lt;br /&gt;
**Provided a Button (Proceed) that would redirect him to the main Expertiza page.&lt;br /&gt;
**Made sure that he does not see any Public entities( assignments, Courses) created by any other TA's, Admins or Super Admins.&lt;br /&gt;
**Demo user has a general access to Expertiza and should be able to perform basic actions like adding a course, adding an assignment &amp;amp; assigning students for the created assignments.&lt;br /&gt;
&lt;br /&gt;
==== Files to be changed ====&lt;br /&gt;
*role.rb&lt;br /&gt;
*tree_display_controller.rb&lt;br /&gt;
*auth_controller.rb&lt;br /&gt;
*auth/_login.html.erb&lt;br /&gt;
&lt;br /&gt;
==== Files Added ====&lt;br /&gt;
*demo_controller.rb&lt;br /&gt;
*tree_display_demo.jsx&lt;br /&gt;
*tree_display/list_for_demo.html.erb&lt;br /&gt;
*tree_display_demo.scss&lt;br /&gt;
*demo_controller_spec.rb&lt;br /&gt;
*demo_controller/instructions_page.html.erb&lt;br /&gt;
&lt;br /&gt;
====Future scope for improvements====&lt;br /&gt;
*The save functionality after editing an assignment throws an error which needs to be checked upon. &lt;br /&gt;
&lt;br /&gt;
'''The demo_controller is created to support the main functionalities'''&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
     @demo_role = Role.find_by_name(&amp;quot;demo_instructor&amp;quot;)&lt;br /&gt;
    if @demo_role&lt;br /&gt;
         @user = User.new&lt;br /&gt;
          @demo_role_id = @demo_role.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Demo Instructor Role not yet created&amp;quot;&lt;br /&gt;
      redirect_to '/'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def instruction_page&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def proceed&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    if simple_captcha_valid?&lt;br /&gt;
      check = User.find_by_name(params[:user][:name])&lt;br /&gt;
        if check != nil&lt;br /&gt;
        params[:user][:name] = params[:user][:email]&lt;br /&gt;
        end&lt;br /&gt;
      @user = User.new(user_params)&lt;br /&gt;
        if @user.save&lt;br /&gt;
        password = @user.reset_password         # the password is reset&lt;br /&gt;
        MailerHelper::send_mail_to_user(@user, &amp;quot;Your Expertiza account and password have been created&amp;quot;, &amp;quot;user_welcome&amp;quot;, password).deliver&lt;br /&gt;
        flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
        redirect_to '/'&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = &amp;quot;Please check on the credentials again and re enter.&amp;quot;&lt;br /&gt;
        render :action =&amp;gt; 'new'&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please ENTER the correct CAPTCHA code&amp;quot;&lt;br /&gt;
      render :action =&amp;gt; 'new'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def show&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_params&lt;br /&gt;
    params.require(:user).permit(:name, :crypted_password, :role_id, :password_salt, :fullname, :email, :parent_id, :private_by_default,&lt;br /&gt;
 :mru_directory_path, :email_on_review, :email_on_submission, :email_on_review_of_review, :is_new_user, :master_permission_granted, :handle, :leaderboard_privacy, :digital_certificate, :persistence_token, :timezonepref, :public_key, :copy_of_emails,:institutions_id)&lt;br /&gt;
  end&lt;br /&gt;
'''Refactored code in tree_display_controller'''&lt;br /&gt;
     &lt;br /&gt;
  if ['Super-Administrator', 'Administrator','Instructor','Teaching Assistant'].include? current_role_name&lt;br /&gt;
       res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
     elsif node.get_instructor_id===session[:user].id&lt;br /&gt;
       res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''For the creation of Demo Instructor experimenting with the features of expertiza&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the controller admin_controller.rb, the new actions to be added and their purpose is explained below.&lt;br /&gt;
&lt;br /&gt;
Action added: create_demo_instructor role&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: create role for the demo_instructor by super administrator&lt;br /&gt;
&lt;br /&gt;
Action added: new_demo_instructor signup &amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Linked to the Signup form for creating an instructor to allow the experimenting with expertiza features&lt;br /&gt;
&lt;br /&gt;
Action added: Display instructions page for demo user&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Show case all the instructions for a new instructor. &lt;br /&gt;
&lt;br /&gt;
Action added : remove_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: For the super administrator to remove the instructor&lt;br /&gt;
&lt;br /&gt;
The corresponding views for the new_demo_instructor, list_demo_instructors, remove_demo_instructor are added manually.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Upon Demo Instructor Login into the account created&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the tree_display_controller.rb, goto_instructions action is added and instructions.html.erb view is created for this action. instructions.html.erb contains the instructions required for the creation of courses, assignments, adding participants to assignments, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Requirements''' ==&lt;br /&gt;
 &lt;br /&gt;
The main objective for the project is to add the new signup functionality for the new User and also to clarify and improve code quality.  Although specific implementation details will change through this process, the functionality of the system will remain intact.  The overall requirements to the system will therefore not change. We need to make sure that the new demo instructor will not be able to see all the public entities of other instructors, TA's. need to implement and change all the necessary files to make sure unnecessary items are not showcased to the demo instructor.&lt;br /&gt;
&lt;br /&gt;
== ''' Flow ''' ==&lt;br /&gt;
The following diagram represents the high level flow of control in the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Capture.PNG]]&lt;br /&gt;
 &lt;br /&gt;
== '''Mock Ups ''' ==&lt;br /&gt;
&lt;br /&gt;
The role creation page by super administrator.&lt;br /&gt;
&lt;br /&gt;
[[File: Course.png‎]]&lt;br /&gt;
&lt;br /&gt;
The instructions page will have few instructions and a Simple Video Tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File: Instructions page.png]]&lt;br /&gt;
&lt;br /&gt;
The Expertiza Home page with the Demo_Instructor.&lt;br /&gt;
&lt;br /&gt;
[[File: Role creation.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Use Cases''' ==&lt;br /&gt;
&lt;br /&gt;
'''1.Sign-up as new Instructor''': New users can signup to view all features(except the public entities).&lt;br /&gt;
&lt;br /&gt;
'''2.View instructions page''': New instructor can view an instructions page for a walk through of the features.&lt;br /&gt;
&lt;br /&gt;
'''3.Super-admin gives access:''' Super-admin gives access to all public entities for the newly created instructor.&lt;br /&gt;
&lt;br /&gt;
'''4.New instructor-private items''' The demo instructor can access all the private items.&lt;br /&gt;
&lt;br /&gt;
== '''Use case Diagram'''==&lt;br /&gt;
&lt;br /&gt;
[[File:Uml_oodd.png‎ ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We would be writing the below test cases so as to make sure all the necessary functionalities are properly implemented and tested.&lt;br /&gt;
&lt;br /&gt;
== '''Test Cases'''==&lt;br /&gt;
'''1.Sign-up Test Case''': We will be checking if the demo user provides all the inputs needed for proper signup along with passing the Captcha .&lt;br /&gt;
&lt;br /&gt;
'''2.Landing Page Test Case''': Will be checking on if all the demo users land on the same Instruction page and if other Users like TA/SuperUser/Instructors do not land on the Instruction page.&lt;br /&gt;
&lt;br /&gt;
'''3. Accessibility Test''': The Demo User should be only be able to access his only entities and not the Public entities of other users(TA/SuperUser/Instructors).&lt;br /&gt;
&lt;br /&gt;
'''4. Adding Entities Test Case''': Will check if the Demo user is able to 1) create Assignments, 2) Add students to Assignments, 3)  Make Questionnaires and have access to these entities.&lt;br /&gt;
&lt;br /&gt;
== ''' References ''' ==&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza home page] &amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/GitHub Github Wikipedia Page]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails Wikipedia Page]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://research.csc.ncsu.edu/efg/expertiza/papers Papers on Expertiza]&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=100367</id>
		<title>CSC/ECE 517 Fall 2015 E1579 Instructor account creation over the web</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=100367"/>
		<updated>2015-12-05T05:07:26Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  '''Introduction to Expertiza''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Expertiza[https://expertiza.ncsu.edu/wiki/] is a project developed using Ruby on Rails[https://en.wikipedia.org/wiki/Ruby_on_Rails]. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub[https://en.wikipedia.org/wiki/GitHub]. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
== '''Purpose''' ==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to allow new users to access the system and experiment with all the features of Expertiza and make a “Demo like” feel for the new user where the user can experiment with it.  This project adds  a new feature of Instructor Creation over the web which is completely different from the previous way the user and instructor accounts were created by existing super administrators. Code will be restructured to convey readability, handle exceptions.&lt;br /&gt;
 &lt;br /&gt;
== '''Scope''' ==&lt;br /&gt;
&lt;br /&gt;
The scope of this project will involve adding a new View/Page that would input all the new user(Instructor) Details which would be a signup page.The signup page will be designed in a way which would have security feature as Captchas embedded into it.  There would be another new View/Page created that would act as the landing page for the newly created Demo_instructor  which would contain specific instructions/ Video on how to add assignments, add students to the assignments. Also an email is sent soon after a successful creation of such user. The project also deals with providing no access to the public features, which could be extended manually by a super admin.The code will also be tested well to ensure the robustness of newly added functionality without compromising the existing working functionalities.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
==== Project outcomes ====&lt;br /&gt;
*Create a new role by SuperAdmin&lt;br /&gt;
**Fixed the drop-down menu for Based on roles option while creating a new.&lt;br /&gt;
**Fixed add new permissions for a role functionality.&lt;br /&gt;
&lt;br /&gt;
*Allow people to request instructor accounts over the web. &lt;br /&gt;
**Added a Link in Main Screen “Demo Instructor signup”.&lt;br /&gt;
**Created a New Page where the User Fills the details wrt to a new Instructor Privileged access.&lt;br /&gt;
**Included Captcha Functionality and other necessary features for a secure Sign Up.&lt;br /&gt;
**Fixed role permission deletion functionality.&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Creation of Instructor Account.&lt;br /&gt;
**Redirect the New Instructor back to the Login Page.&lt;br /&gt;
**Send an email to the super Admin notifying him of a new Instructor that has been created over the web&lt;br /&gt;
**Send an email to new user with username and new password details. &lt;br /&gt;
&lt;br /&gt;
*Upon Successful Login of the New Instructor&lt;br /&gt;
**Redirect the User to a Instruction Page which gives information on how to create an assignments and register students for it and other basic information needed. Basically a instructions page that can be used for providing information.&lt;br /&gt;
**Provided a Button (Proceed) that would redirect him to the main Expertiza page.&lt;br /&gt;
**Made sure that he does not see any Public entities( assignments, Courses) created by any other TA's, Admins or Super Admins.&lt;br /&gt;
**Demo user has a general access to Expertiza and should be able to perform basic actions like adding a course, adding an assignment &amp;amp; assigning students for the created assignments.&lt;br /&gt;
&lt;br /&gt;
==== Files to be changed ====&lt;br /&gt;
*role.rb&lt;br /&gt;
*tree_display_controller.rb&lt;br /&gt;
*auth_controller.rb&lt;br /&gt;
*auth/_login.html.erb&lt;br /&gt;
&lt;br /&gt;
==== Files Added ====&lt;br /&gt;
*demo_controller.rb&lt;br /&gt;
*tree_display_demo.jsx&lt;br /&gt;
*tree_display/list_for_demo.html.erb&lt;br /&gt;
*tree_display_demo.scss&lt;br /&gt;
*demo_controller_spec.rb&lt;br /&gt;
*demo_controller/instructions_page.html.erb&lt;br /&gt;
&lt;br /&gt;
'''The demo_controller is created to support the main functionalities'''&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    true&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def new&lt;br /&gt;
     @demo_role = Role.find_by_name(&amp;quot;demo_instructor&amp;quot;)&lt;br /&gt;
    if @demo_role&lt;br /&gt;
         @user = User.new&lt;br /&gt;
          @demo_role_id = @demo_role.id&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Demo Instructor Role not yet created&amp;quot;&lt;br /&gt;
      redirect_to '/'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def instruction_page&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def proceed&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def create&lt;br /&gt;
    if simple_captcha_valid?&lt;br /&gt;
      check = User.find_by_name(params[:user][:name])&lt;br /&gt;
        if check != nil&lt;br /&gt;
        params[:user][:name] = params[:user][:email]&lt;br /&gt;
        end&lt;br /&gt;
      @user = User.new(user_params)&lt;br /&gt;
        if @user.save&lt;br /&gt;
        password = @user.reset_password         # the password is reset&lt;br /&gt;
        MailerHelper::send_mail_to_user(@user, &amp;quot;Your Expertiza account and password have been created&amp;quot;, &amp;quot;user_welcome&amp;quot;, password).deliver&lt;br /&gt;
        flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
        redirect_to '/'&lt;br /&gt;
      else&lt;br /&gt;
        flash[:error] = &amp;quot;Please check on the credentials again and re enter.&amp;quot;&lt;br /&gt;
        render :action =&amp;gt; 'new'&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = &amp;quot;Please ENTER the correct CAPTCHA code&amp;quot;&lt;br /&gt;
      render :action =&amp;gt; 'new'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def show&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_params&lt;br /&gt;
    params.require(:user).permit(:name, :crypted_password, :role_id, :password_salt, :fullname, :email, :parent_id, :private_by_default,&lt;br /&gt;
 :mru_directory_path, :email_on_review, :email_on_submission, :email_on_review_of_review, :is_new_user, :master_permission_granted, :handle, :leaderboard_privacy, :digital_certificate, :persistence_token, :timezonepref, :public_key, :copy_of_emails,:institutions_id)&lt;br /&gt;
  end&lt;br /&gt;
'''Refactored code in tree_display_controller'''&lt;br /&gt;
     &lt;br /&gt;
  if ['Super-Administrator', 'Administrator','Instructor','Teaching Assistant'].include? current_role_name&lt;br /&gt;
       res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
     elsif node.get_instructor_id===session[:user].id&lt;br /&gt;
       res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''For the creation of Demo Instructor experimenting with the features of expertiza&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the controller admin_controller.rb, the new actions to be added and their purpose is explained below.&lt;br /&gt;
&lt;br /&gt;
Action added: create_demo_instructor role&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: create role for the demo_instructor by super administrator&lt;br /&gt;
&lt;br /&gt;
Action added: new_demo_instructor signup &amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Linked to the Signup form for creating an instructor to allow the experimenting with expertiza features&lt;br /&gt;
&lt;br /&gt;
Action added: Display instructions page for demo user&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Show case all the instructions for a new instructor. &lt;br /&gt;
&lt;br /&gt;
Action added : remove_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: For the super administrator to remove the instructor&lt;br /&gt;
&lt;br /&gt;
The corresponding views for the new_demo_instructor, list_demo_instructors, remove_demo_instructor are added manually.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Upon Demo Instructor Login into the account created&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the tree_display_controller.rb, goto_instructions action is added and instructions.html.erb view is created for this action. instructions.html.erb contains the instructions required for the creation of courses, assignments, adding participants to assignments, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Requirements''' ==&lt;br /&gt;
 &lt;br /&gt;
The main objective for the project is to add the new signup functionality for the new User and also to clarify and improve code quality.  Although specific implementation details will change through this process, the functionality of the system will remain intact.  The overall requirements to the system will therefore not change. We need to make sure that the new demo instructor will not be able to see all the public entities of other instructors, TA's. need to implement and change all the necessary files to make sure unnecessary items are not showcased to the demo instructor.&lt;br /&gt;
&lt;br /&gt;
== ''' Flow ''' ==&lt;br /&gt;
The following diagram represents the high level flow of control in the project.&lt;br /&gt;
&lt;br /&gt;
[[File:Capture.PNG]]&lt;br /&gt;
 &lt;br /&gt;
== '''Mock Ups ''' ==&lt;br /&gt;
&lt;br /&gt;
The role creation page by super administrator.&lt;br /&gt;
&lt;br /&gt;
[[File: Course.png‎]]&lt;br /&gt;
&lt;br /&gt;
The instructions page will have few instructions and a Simple Video Tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File: Instructions page.png]]&lt;br /&gt;
&lt;br /&gt;
The Expertiza Home page with the Demo_Instructor.&lt;br /&gt;
&lt;br /&gt;
[[File: Role creation.png]]&lt;br /&gt;
&lt;br /&gt;
== '''Use Cases''' ==&lt;br /&gt;
&lt;br /&gt;
'''1.Sign-up as new Instructor''': New users can signup to view all features(except the public entities).&lt;br /&gt;
&lt;br /&gt;
'''2.View instructions page''': New instructor can view an instructions page for a walk through of the features.&lt;br /&gt;
&lt;br /&gt;
'''3.Super-admin gives access:''' Super-admin gives access to all public entities for the newly created instructor.&lt;br /&gt;
&lt;br /&gt;
'''4.New instructor-private items''' The demo instructor can access all the private items.&lt;br /&gt;
&lt;br /&gt;
== '''Use case Diagram'''==&lt;br /&gt;
&lt;br /&gt;
[[File:Uml_oodd.png‎ ]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We would be writing the below test cases so as to make sure all the necessary functionalities are properly implemented and tested.&lt;br /&gt;
&lt;br /&gt;
== '''Test Cases'''==&lt;br /&gt;
'''1.Sign-up Test Case''': We will be checking if the demo user provides all the inputs needed for proper signup along with passing the Captcha .&lt;br /&gt;
&lt;br /&gt;
'''2.Landing Page Test Case''': Will be checking on if all the demo users land on the same Instruction page and if other Users like TA/SuperUser/Instructors do not land on the Instruction page.&lt;br /&gt;
&lt;br /&gt;
'''3. Accessibility Test''': The Demo User should be only be able to access his only entities and not the Public entities of other users(TA/SuperUser/Instructors).&lt;br /&gt;
&lt;br /&gt;
'''4. Adding Entities Test Case''': Will check if the Demo user is able to 1) create Assignments, 2) Add students to Assignments, 3)  Make Questionnaires and have access to these entities.&lt;br /&gt;
&lt;br /&gt;
== ''' References ''' ==&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza home page] &amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/GitHub Github Wikipedia Page]&amp;lt;br&amp;gt;&lt;br /&gt;
[https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails Wikipedia Page]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://research.csc.ncsu.edu/efg/expertiza/papers Papers on Expertiza]&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99948</id>
		<title>CSC/ECE 517 Fall 2015 E1579 Instructor account creation over the web</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99948"/>
		<updated>2015-11-14T05:31:49Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* UML Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  '''Introduction to Expertiza''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
== '''Purpose''' ==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to allow new users to access the system and experiment with all the features of Expertiza and make a “Demo like” feel for the new user where the user can experiment with it.  This project adds  a new feature of Instructor Creation over the web which is completely different from the previous way  the user and instructor accounts were created by existing super administrators, instructors or TAs. Code will be restructured to convey readability, handle exceptions.&lt;br /&gt;
 &lt;br /&gt;
== '''Scope''' ==&lt;br /&gt;
&lt;br /&gt;
The scope of this project will involve adding a new View/Page that would input all the new user(Instructor) Details which would be a signup page.The signup page will be designed in a way which would have security feature as Captchas embedded into it.  There would be another new View/Page created that would act as the landing page for the newly created Demo_instructor  which would contain specific instructions/ Video on how to add assignments, add students to the assignments. Also an email is sent soon after a successful creation of such user. The project also deals with providing limited access to all the features, which could be extended manually by a super admin.The code will also be tested well to ensure the robustness of newly added functionality without compromising the existing working functionalities.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
==== What needs to be done ====&lt;br /&gt;
&lt;br /&gt;
*Allow people to request instructor accounts over the web. &lt;br /&gt;
**Add a Link in Main Screen “Instructor Account request”.&lt;br /&gt;
**Create a New Page where the User Fills the details wrt to a new Instructor Privileged access.&lt;br /&gt;
**Include Captcha Functionality and other necessary features for a secure Sign Up.&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Creation of Instructor Account.&lt;br /&gt;
**Redirect the New Instructor back to the Login Page.&lt;br /&gt;
**Send an email to the super Admin notifying him of a new Instructor that has been created over the web&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Login of the New Instructor&lt;br /&gt;
**Redirect the User to a  New Landing Page/Instruction Page which gives information on how to create an assignments and register students for it and other  basic information needed. Basically a Placeholder page that can be used for providing information.&lt;br /&gt;
**Provide a Button that would redirect him to the main Expertiza page.&lt;br /&gt;
**Make sure that he does not see any Public entities( assignments, Courses) created by any other TA's, Admins or Super Admins.&lt;br /&gt;
**Should have a general access to Expertiza and should be able to perform basic actions like adding a course, adding an assignment and assigning students for the created assignments.&lt;br /&gt;
&lt;br /&gt;
==== Files to be changed ====&lt;br /&gt;
*role.rb&lt;br /&gt;
*instructor.rb&lt;br /&gt;
*roles_permission.rb&lt;br /&gt;
*roles_permission_controller.rb&lt;br /&gt;
*sign_up_sheet_controller.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A role named Demo-Instructor is added to the added to the role.rb model with the following code:'''&lt;br /&gt;
&lt;br /&gt;
  def self.demo_instructor&lt;br /&gt;
    @@instructor_role ||= find_by_name 'Demo-Instructor'&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def demo_instructor?&lt;br /&gt;
    name['Demo-Instructor']&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
Various controller and model files containing action_allowed? should be updated as &lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', 'Student', 'Demo-Instructor'].include? current_role_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
roles table will be updated will be updated by the super-administrator from the new.html.erb form associated with the new action of roles_controller&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''For the creation of Demo Instructor experimenting with the features of expertiza&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the controller admin_controller.rb, the new actions to be added and their purpose is explained below.&lt;br /&gt;
&lt;br /&gt;
Action added: new_demo_instructor &amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Linked to the Signup form for creating an instructor to allow the experimenting with expertiza features&lt;br /&gt;
&lt;br /&gt;
Action added: create_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: the save operation for the instructor created into the database&lt;br /&gt;
&lt;br /&gt;
Action added: list_demo_instructors&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: To list them &lt;br /&gt;
&lt;br /&gt;
Action added : remove_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: For the super administrator to remove the instructor&lt;br /&gt;
&lt;br /&gt;
The corresponding views for the new_demo_instructor, list_demo_instructors, remove_demo_instructor are added manually.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Upon Demo Instructor Login into the account created&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the tree_display_controller.rb, goto_instructions action is added and instructions.html.erb view is created for this action. instructions.html.erb contains the instructions required for the creation of courses, assignments, adding participants to assignments, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Requirements''' ==&lt;br /&gt;
 &lt;br /&gt;
The main objective for the project is to add the new signup functionality for the new User and also to clarify and improve code quality.  Although specific implementation details will change through this process, the functionality of the system will remain intact.  The overall requirements to the system will therefore not change. We need to make sure that the new demo instructor will not be able to see all the public entities of other instructors, TA's. need to implement and change all the necessary files to make sure unnecessary items are not showcased to the demo instructor.&lt;br /&gt;
&lt;br /&gt;
== '''Mock Ups ''' ==&lt;br /&gt;
&lt;br /&gt;
The Expertiza Login page with the Instructor Account Request Link.&lt;br /&gt;
&lt;br /&gt;
[[File: Homepage.PNG]]&lt;br /&gt;
&lt;br /&gt;
The PlaceHolder page will have few instructions and a Simple Video Tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File: Placehlder.PNG]]&lt;br /&gt;
&lt;br /&gt;
The home page for demo instructor excluding public entities.&lt;br /&gt;
&lt;br /&gt;
[[File: Instructor_default_page_(1).PNG]]&lt;br /&gt;
&lt;br /&gt;
== '''Use Cases''' ==&lt;br /&gt;
&lt;br /&gt;
'''1.Sign-up as new Instructor''': New users can signup to view all features(except the public entities).&lt;br /&gt;
&lt;br /&gt;
'''2.View instructions page''': New instructor can view an instructions page for a walk through of the features.&lt;br /&gt;
&lt;br /&gt;
'''3.Super-admin gives access:''' Super-admin gives access to all public entities for the newly created instructor.&lt;br /&gt;
&lt;br /&gt;
'''4.New instructor-private items''' The demo instructor can access all the private items.&lt;br /&gt;
&lt;br /&gt;
== '''Use case Diagram'''==&lt;br /&gt;
&lt;br /&gt;
[[File:Uml_oodd.png‎ ]]&lt;br /&gt;
&lt;br /&gt;
== ''' References ''' ==&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza home page] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://research.csc.ncsu.edu/efg/expertiza/papers Papers on Expertiza]&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99946</id>
		<title>CSC/ECE 517 Fall 2015 E1579 Instructor account creation over the web</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99946"/>
		<updated>2015-11-14T05:29:31Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Use Cases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  '''Introduction to Expertiza''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
== '''Purpose''' ==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to allow new users to access the system and experiment with all the features of Expertiza and make a “Demo like” feel for the new user where the user can experiment with it.  This project adds  a new feature of Instructor Creation over the web which is completely different from the previous way  the user and instructor accounts were created by existing super administrators, instructors or TAs. Code will be restructured to convey readability, handle exceptions.&lt;br /&gt;
 &lt;br /&gt;
== '''Scope''' ==&lt;br /&gt;
&lt;br /&gt;
The scope of this project will involve adding a new View/Page that would input all the new user(Instructor) Details which would be a signup page.The signup page will be designed in a way which would have security feature as Captchas embedded into it.  There would be another new View/Page created that would act as the landing page for the newly created Demo_instructor  which would contain specific instructions/ Video on how to add assignments, add students to the assignments. Also an email is sent soon after a successful creation of such user. The project also deals with providing limited access to all the features, which could be extended manually by a super admin.The code will also be tested well to ensure the robustness of newly added functionality without compromising the existing working functionalities.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
==== What needs to be done ====&lt;br /&gt;
&lt;br /&gt;
*Allow people to request instructor accounts over the web. &lt;br /&gt;
**Add a Link in Main Screen “Instructor Account request”.&lt;br /&gt;
**Create a New Page where the User Fills the details wrt to a new Instructor Privileged access.&lt;br /&gt;
**Include Captcha Functionality and other necessary features for a secure Sign Up.&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Creation of Instructor Account.&lt;br /&gt;
**Redirect the New Instructor back to the Login Page.&lt;br /&gt;
**Send an email to the super Admin notifying him of a new Instructor that has been created over the web&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Login of the New Instructor&lt;br /&gt;
**Redirect the User to a  New Landing Page/Instruction Page which gives information on how to create an assignments and register students for it and other  basic information needed. Basically a Placeholder page that can be used for providing information.&lt;br /&gt;
**Provide a Button that would redirect him to the main Expertiza page.&lt;br /&gt;
**Make sure that he does not see any Public entities( assignments, Courses) created by any other TA's, Admins or Super Admins.&lt;br /&gt;
**Should have a general access to Expertiza and should be able to perform basic actions like adding a course, adding an assignment and assigning students for the created assignments.&lt;br /&gt;
&lt;br /&gt;
==== Files to be changed ====&lt;br /&gt;
*role.rb&lt;br /&gt;
*instructor.rb&lt;br /&gt;
*roles_permission.rb&lt;br /&gt;
*roles_permission_controller.rb&lt;br /&gt;
*sign_up_sheet_controller.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A role named Demo-Instructor is added to the added to the role.rb model with the following code:'''&lt;br /&gt;
&lt;br /&gt;
  def self.demo_instructor&lt;br /&gt;
    @@instructor_role ||= find_by_name 'Demo-Instructor'&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def demo_instructor?&lt;br /&gt;
    name['Demo-Instructor']&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
Various controller and model files containing action_allowed? should be updated as &lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', 'Student', 'Demo-Instructor'].include? current_role_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
roles table will be updated will be updated by the super-administrator from the new.html.erb form associated with the new action of roles_controller&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''For the creation of Demo Instructor experimenting with the features of expertiza&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the controller admin_controller.rb, the new actions to be added and their purpose is explained below.&lt;br /&gt;
&lt;br /&gt;
Action added: new_demo_instructor &amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Linked to the Signup form for creating an instructor to allow the experimenting with expertiza features&lt;br /&gt;
&lt;br /&gt;
Action added: create_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: the save operation for the instructor created into the database&lt;br /&gt;
&lt;br /&gt;
Action added: list_demo_instructors&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: To list them &lt;br /&gt;
&lt;br /&gt;
Action added : remove_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: For the super administrator to remove the instructor&lt;br /&gt;
&lt;br /&gt;
The corresponding views for the new_demo_instructor, list_demo_instructors, remove_demo_instructor are added manually.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Upon Demo Instructor Login into the account created&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the tree_display_controller.rb, goto_instructions action is added and instructions.html.erb view is created for this action. instructions.html.erb contains the instructions required for the creation of courses, assignments, adding participants to assignments, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Requirements''' ==&lt;br /&gt;
 &lt;br /&gt;
The main objective for the project is to add the new signup functionality for the new User and also to clarify and improve code quality.  Although specific implementation details will change through this process, the functionality of the system will remain intact.  The overall requirements to the system will therefore not change. We need to make sure that the new demo instructor will not be able to see all the public entities of other instructors, TA's. need to implement and change all the necessary files to make sure unnecessary items are not showcased to the demo instructor.&lt;br /&gt;
&lt;br /&gt;
== '''Mock Ups ''' ==&lt;br /&gt;
&lt;br /&gt;
The Expertiza Login page with the Instructor Account Request Link.&lt;br /&gt;
&lt;br /&gt;
[[File: Homepage.PNG]]&lt;br /&gt;
&lt;br /&gt;
The PlaceHolder page will have few instructions and a Simple Video Tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File: Placehlder.PNG]]&lt;br /&gt;
&lt;br /&gt;
The home page for demo instructor excluding public entities.&lt;br /&gt;
&lt;br /&gt;
[[File: Instructor_default_page_(1).PNG]]&lt;br /&gt;
&lt;br /&gt;
== '''Use Cases''' ==&lt;br /&gt;
&lt;br /&gt;
'''1.Sign-up as new Instructor''': New users can signup to view all features(except the public entities).&lt;br /&gt;
&lt;br /&gt;
'''2.View instructions page''': New instructor can view an instructions page for a walk through of the features.&lt;br /&gt;
&lt;br /&gt;
'''3.Super-admin gives access:''' Super-admin gives access to all public entities for the newly created instructor.&lt;br /&gt;
&lt;br /&gt;
'''4.New instructor-private items''' The demo instructor can access all the private items.&lt;br /&gt;
&lt;br /&gt;
== '''UML Diagram'''==&lt;br /&gt;
&lt;br /&gt;
''UML diagram for use cases''&lt;br /&gt;
[[File:Uml_oodd.png‎ ]]&lt;br /&gt;
&lt;br /&gt;
== ''' References ''' ==&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza home page] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://research.csc.ncsu.edu/efg/expertiza/papers Papers on Expertiza]&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml_oodd.png&amp;diff=99945</id>
		<title>File:Uml oodd.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Uml_oodd.png&amp;diff=99945"/>
		<updated>2015-11-14T05:27:05Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99933</id>
		<title>CSC/ECE 517 Fall 2015 E1579 Instructor account creation over the web</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1579_Instructor_account_creation_over_the_web&amp;diff=99933"/>
		<updated>2015-11-14T04:50:52Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Files to be changed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==  '''Introduction to Expertiza''' ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails. It provides features like peer review, team assignments and submission of projects. This can be achieved by submitting code base, URL of hosted code on remote server and Wiki submissions. It is an open source application and the code can be cloned from GitHub. This application provides an efficient way to manage assignments, grades and reviews. This makes the process easier and faster when the class strength is large.&lt;br /&gt;
&lt;br /&gt;
== '''Purpose''' ==&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to allow new users to access the system and experiment with all the features of Expertiza and make a “Demo like” feel for the new user where the user can experiment with it.  This project adds  a new feature of Instructor Creation over the web which is completely different from the previous way  the user and instructor accounts were created by existing super administrators, instructors or TAs. Code will be restructured to convey readability, handle exceptions.&lt;br /&gt;
 &lt;br /&gt;
== '''Scope''' ==&lt;br /&gt;
&lt;br /&gt;
The scope of this project will involve adding a new View/Page that would input all the new user(Instructor) Details which would be a signup page.The signup page will be designed in a way which would have security feature as Captchas embedded into it.  There would be another new View/Page created that would act as the landing page for the newly created Demo_instructor  which would contain specific instructions/ Video on how to add assignments, add students to the assignments. Also an email is sent soon after a successful creation of such user. The project also deals with providing limited access to all the features, which could be extended manually by a super admin.The code will also be tested well to ensure the robustness of newly added functionality without compromising the existing working functionalities.&lt;br /&gt;
&lt;br /&gt;
=='''Implementation'''==&lt;br /&gt;
&lt;br /&gt;
==== What needs to be done ====&lt;br /&gt;
&lt;br /&gt;
*Allow people to request instructor accounts over the web. &lt;br /&gt;
**Add a Link in Main Screen “Instructor Account request”.&lt;br /&gt;
**Create a New Page where the User Fills the details wrt to a new Instructor Privileged access.&lt;br /&gt;
**Include Captcha Functionality and other necessary features for a secure Sign Up.&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Creation of Instructor Account.&lt;br /&gt;
**Redirect the New Instructor back to the Login Page.&lt;br /&gt;
**Send an email to the super Admin notifying him of a new Instructor that has been created over the web&lt;br /&gt;
&lt;br /&gt;
*Upon Successful Login of the New Instructor&lt;br /&gt;
**Redirect the User to a  New Landing Page/Instruction Page which gives information on how to create an assignments and register students for it and other  basic information needed. Basically a Placeholder page that can be used for providing information.&lt;br /&gt;
**Provide a Button that would redirect him to the main Expertiza page.&lt;br /&gt;
**Make sure that he does not see any Public entities( assignments, Courses) created by any other TA's, Admins or Super Admins.&lt;br /&gt;
**Should have a general access to Expertiza and should be able to perform basic actions like adding a course, adding an assignment and assigning students for the created assignments.&lt;br /&gt;
&lt;br /&gt;
==== Files to be changed ====&lt;br /&gt;
*role.rb&lt;br /&gt;
*instructor.rb&lt;br /&gt;
*roles_permission.rb&lt;br /&gt;
*roles_permission_controller.rb&lt;br /&gt;
*sign_up_sheet_controller.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''A role named Demo-Instructor is added to the added to the role.rb model with the following code:'''&lt;br /&gt;
&lt;br /&gt;
  def self.demo_instructor&lt;br /&gt;
    @@instructor_role ||= find_by_name 'Demo-Instructor'&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def demo_instructor?&lt;br /&gt;
    name['Demo-Instructor']&lt;br /&gt;
  end &lt;br /&gt;
&lt;br /&gt;
Various controller and model files containing action_allowed? should be updated as &lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    ['Instructor', 'Teaching Assistant', 'Administrator', 'Super-Administrator', 'Student', 'Demo-Instructor'].include? current_role_name&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
roles table will be updated will be updated by the super-administrator from the new.html.erb form associated with the new action of roles_controller&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''For the creation of Demo Instructor experimenting with the features of expertiza&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the controller admin_controller.rb, the new actions to be added and their purpose is explained below.&lt;br /&gt;
&lt;br /&gt;
Action added: new_demo_instructor &amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: Linked to the Signup form for creating an instructor to allow the experimenting with expertiza features&lt;br /&gt;
&lt;br /&gt;
Action added: create_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: the save operation for the instructor created into the database&lt;br /&gt;
&lt;br /&gt;
Action added: list_demo_instructors&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: To list them &lt;br /&gt;
&lt;br /&gt;
Action added : remove_demo_instructor&amp;lt;br&amp;gt;&lt;br /&gt;
Purpose: For the super administrator to remove the instructor&lt;br /&gt;
&lt;br /&gt;
The corresponding views for the new_demo_instructor, list_demo_instructors, remove_demo_instructor are added manually.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Upon Demo Instructor Login into the account created&lt;br /&gt;
'''&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the tree_display_controller.rb, goto_instructions action is added and instructions.html.erb view is created for this action. instructions.html.erb contains the instructions required for the creation of courses, assignments, adding participants to assignments, etc.&lt;br /&gt;
&lt;br /&gt;
== '''Requirements''' ==&lt;br /&gt;
 &lt;br /&gt;
The main objective for the project is to add the new signup functionality for the new User and also to clarify and improve code quality.  Although specific implementation details will change through this process, the functionality of the system will remain intact.  The overall requirements to the system will therefore not change. We need to make sure that the new demo instructor will not be able to see all the public entities of other instructors, TA's. need to implement and change all the necessary files to make sure unnecessary items are not showcased to the demo instructor.&lt;br /&gt;
&lt;br /&gt;
== '''Mock Ups ''' ==&lt;br /&gt;
&lt;br /&gt;
The Expertiza Login page with the Instructor Account Request Link.&lt;br /&gt;
&lt;br /&gt;
[[File: Homepage.PNG]]&lt;br /&gt;
&lt;br /&gt;
The PlaceHolder page will have few instructions and a Simple Video Tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File: Placehlder.PNG]]&lt;br /&gt;
&lt;br /&gt;
The home page for demo instructor excluding public entities.&lt;br /&gt;
&lt;br /&gt;
[[File: Instructor_default_page_(1).PNG]]&lt;br /&gt;
&lt;br /&gt;
== '''Use Cases''' ==&lt;br /&gt;
&lt;br /&gt;
'''1.Sign-up as new Instructor''': New users can signup to view all features(except the public entities).&lt;br /&gt;
&lt;br /&gt;
'''2.View instructions page''': New instructor can view an instructions page for a walk through of the features.&lt;br /&gt;
&lt;br /&gt;
'''3.Super-admin gives access:''' Super-admin gives access to all public entities for the newly created instructor.&lt;br /&gt;
&lt;br /&gt;
'''4.New instructor-private items''' The demo instructor can access all the private items.&lt;br /&gt;
&lt;br /&gt;
== ''' References ''' ==&lt;br /&gt;
[https://expertiza.ncsu.edu/ Expertiza home page] &amp;lt;br&amp;gt;&lt;br /&gt;
[http://research.csc.ncsu.edu/efg/expertiza/papers Papers on Expertiza]&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98511</id>
		<title>File:Review rubrics screenshot.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98511"/>
		<updated>2015-11-06T22:57:10Z</updated>

		<summary type="html">&lt;p&gt;Abonam: uploaded a new version of &amp;amp;quot;File:Review rubrics screenshot.png&amp;amp;quot;: Reverted to version as of 22:32, 6 November 2015&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98509</id>
		<title>File:Review rubrics screenshot.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98509"/>
		<updated>2015-11-06T22:56:45Z</updated>

		<summary type="html">&lt;p&gt;Abonam: uploaded a new version of &amp;amp;quot;File:Review rubrics screenshot.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98507</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98507"/>
		<updated>2015-11-06T22:54:44Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Direct access to sub categories in tree display */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Direct access to sub categories in tree display=&lt;br /&gt;
[[File:Review rubrics screenshot.png |center]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Sub-tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98506</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98506"/>
		<updated>2015-11-06T22:39:32Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Login using Instructor Credentials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Direct access to sub categories in tree display=&lt;br /&gt;
[[File:Review rubrics screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Sub-tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98504</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98504"/>
		<updated>2015-11-06T22:38:37Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Checking the sub categories in each parent Tree */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Login using Instructor Credentials=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Sub-tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98503</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98503"/>
		<updated>2015-11-06T22:38:10Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Checking the direct access tabs from navigation bar */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Login using Instructor Credentials=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Tree screenshot.png]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98497</id>
		<title>File:Review rubrics screenshot.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Review_rubrics_screenshot.png&amp;diff=98497"/>
		<updated>2015-11-06T22:32:29Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Sub-tree_screenshot.png&amp;diff=98496</id>
		<title>File:Sub-tree screenshot.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Sub-tree_screenshot.png&amp;diff=98496"/>
		<updated>2015-11-06T22:27:57Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98368</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98368"/>
		<updated>2015-11-06T16:57:57Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* TreeDisplayController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Login using Instructor Credentials=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98366</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98366"/>
		<updated>2015-11-06T16:54:27Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* How to test the changes from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==='''How to test the changes from UI'''===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=Login using Instructor Credentials=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the direct access tabs from navigation bar=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
=Checking the sub categories in each parent Tree=&lt;br /&gt;
[[File:Example.jpg]]&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98365</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98365"/>
		<updated>2015-11-06T16:25:30Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* How to test the changes from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to test the changes from UI==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* To check the changes made in go_to_menu_items method, hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
* To test the changes made in get_children_node_ng and get_children_node_2_ng methods, click on the sub categories under each of the parent tree displays (Courses, Assignments and Questionnaires) and all of them will further expand to show the details. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98297</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98297"/>
		<updated>2015-11-06T14:49:58Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* How to test the changes from UI */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to test the changes from UI==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
* Hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98293</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=98293"/>
		<updated>2015-11-06T14:49:07Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* MenuItemsController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to test the changes from UI==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|* Login in as an instructor or admin using credentials (admin with password: admin or instructor6 with password: password)&lt;br /&gt;
|* Hover over the Manage tab in the navigation bar on the top  and click all the links and check whether they are being redirected to correct pages. For example, if Questionnaires is clicked, you should be | redirected directly to the page displaying all the questionnaires with its sub-categories like Reviews, Surveys etc.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97508</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97508"/>
		<updated>2015-10-31T15:08:08Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
       allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
     end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
  before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
     it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
        dbl.populate_1_row(Node.new)&lt;br /&gt;
     end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#go_to_menu_items&amp;quot; do&lt;br /&gt;
    before do&lt;br /&gt;
          allow(nil).to receive(:find_by_node_object_id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:id).and_return(nil)&lt;br /&gt;
          allow(nil).to receive(:name).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
      it &amp;quot;should receive Review Rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Review Rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Teammate review rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Teammate review&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Metareview rubrics and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Metareview&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Author feedbacks and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Author Feedback&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Global surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Global Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Course evaluations and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Course Evaluation&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should receive Surveys and redirect to list&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(&amp;quot;Survey&amp;quot;).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;, params1: &amp;quot;Surveys&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
      it &amp;quot;should redirect to root_url if request parameter is invalid&amp;quot; do&lt;br /&gt;
          allow(nil).to receive(:find_by_name).with(nil).and_return(nil)&lt;br /&gt;
          get &amp;quot;go_to_menu_items&amp;quot;&lt;br /&gt;
          expect(response).to redirect_to(root_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    describe &amp;quot;#drill&amp;quot; do&lt;br /&gt;
      it &amp;quot;redirect to list action&amp;quot; do&lt;br /&gt;
           get &amp;quot;drill&amp;quot; , root: 1&lt;br /&gt;
           session[:root].should == &amp;quot;1&amp;quot;&lt;br /&gt;
           expect(response).to redirect_to(list_tree_display_index_path)&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97338</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97338"/>
		<updated>2015-10-30T15:52:39Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Removing duplicate methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97337</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97337"/>
		<updated>2015-10-30T15:52:12Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Removing duplicate methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
              session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
              session[:last_open_tab] = 2&lt;br /&gt;
      elsif (node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||&lt;br /&gt;
              node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9||&lt;br /&gt;
              node_object.id ==10) # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
           session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
           redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
           redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97336</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97336"/>
		<updated>2015-10-30T15:48:33Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Removing duplicate methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
# direct access to questionnaires&lt;br /&gt;
  def goto_questionnaires&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Questionnaires')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to review rubrics&lt;br /&gt;
  def goto_review_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to metareview rubrics&lt;br /&gt;
  def goto_metareview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Metareview')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to teammate review rubrics&lt;br /&gt;
  def goto_teammatereview_rubrics&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Teammate Review')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to author feedbacks&lt;br /&gt;
  def goto_author_feedbacks&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Author Feedback')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to global survey&lt;br /&gt;
  def goto_global_survey&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Global Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to surveys&lt;br /&gt;
  def goto_surveys&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Survey')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to course evaluations&lt;br /&gt;
  def goto_course_evaluations&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Course Evaluation')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to courses&lt;br /&gt;
  def goto_courses&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Courses')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # direct access to assignments&lt;br /&gt;
  def goto_assignments&lt;br /&gt;
    node_object = TreeFolder.find_by_name('Assignments')&lt;br /&gt;
    session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
    redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 # direct access&lt;br /&gt;
 def go_to_menu_items&lt;br /&gt;
    name = params[:params1]&lt;br /&gt;
    if name&lt;br /&gt;
      if name == &amp;quot;Review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Teammate review rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Metareview rubrics&amp;quot;&lt;br /&gt;
          name = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Author feedbacks&amp;quot;&lt;br /&gt;
          name = &amp;quot;Author Feedback&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Global surveys&amp;quot;&lt;br /&gt;
          name = &amp;quot;Global Survey&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Course evaluations&amp;quot;&lt;br /&gt;
          name = &amp;quot;Course Evaluation&amp;quot;&lt;br /&gt;
        elsif name == &amp;quot;Surveys&amp;quot;&lt;br /&gt;
            name = &amp;quot;Survey&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      node_object = TreeFolder.find_by_name(name)&lt;br /&gt;
      puts node_object.inspect&lt;br /&gt;
      session[:root] = FolderNode.find_by_node_object_id(node_object.id).id&lt;br /&gt;
      if node_object.name == &amp;quot;Courses&amp;quot;&lt;br /&gt;
        session[:last_open_tab] = 1&lt;br /&gt;
      elsif node_object.name == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
        session[:last_open_tab] = 2&lt;br /&gt;
      elsif node_object.id ==1 ||node_object.id ==4 ||node_object.id ==5 ||node_object.id ==6 ||node_object.id ==7 ||node_object.id ==8 ||node_object.id ==9 ||node_object.id ==10 # if node_object_name is Questionnaires or its child_nodes&lt;br /&gt;
        session[:last_open_tab] = 3   # for Questionnaires and all its childnodes&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :controller =&amp;gt; 'tree_display', :action =&amp;gt; 'list'&lt;br /&gt;
&lt;br /&gt;
    else        # if the passed params is null, redirect to root&lt;br /&gt;
      redirect_to &amp;quot;/&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97334</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97334"/>
		<updated>2015-10-30T15:40:52Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Problem Statement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Controller Responsibilities:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''Bad practices followed:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''Refactoring to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
#   Merge  all the repeating methods into a single method.&lt;br /&gt;
#   Write functional tests for the TreeDispayController.&lt;br /&gt;
#   Remove commented code in list method.&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.map_id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if redirect_when_disallowed(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    @review_scores = Array.new&lt;br /&gt;
    @question_type = Array.new&lt;br /&gt;
    @questions.each do |question|&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; Score.where(response_id: @map.response_id, question_id:  question.id).first&lt;br /&gt;
      @question_type &amp;lt;&amp;lt; QuestionType.find_by_question_id(question.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97332</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97332"/>
		<updated>2015-10-30T15:29:01Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* Rspec Test */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''What's wrong with it:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.map_id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if redirect_when_disallowed(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    @review_scores = Array.new&lt;br /&gt;
    @question_type = Array.new&lt;br /&gt;
    @questions.each do |question|&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; Score.where(response_id: @map.response_id, question_id:  question.id).first&lt;br /&gt;
      @question_type &amp;lt;&amp;lt; QuestionType.find_by_question_id(question.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
        allow(session[:user]).to receive(&amp;quot;ta?&amp;quot;).and_return(true)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97328</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97328"/>
		<updated>2015-10-30T15:14:01Z</updated>

		<summary type="html">&lt;p&gt;Abonam: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''What's wrong with it:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.map_id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if redirect_when_disallowed(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    @review_scores = Array.new&lt;br /&gt;
    @question_type = Array.new&lt;br /&gt;
    @questions.each do |question|&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; Score.where(response_id: @map.response_id, question_id:  question.id).first&lt;br /&gt;
      @question_type &amp;lt;&amp;lt; QuestionType.find_by_question_id(question.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
  describe &amp;quot;#get_children_node_ng&amp;quot; do&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97326</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97326"/>
		<updated>2015-10-30T15:13:11Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* MenuItemsController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''What's wrong with it:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|------&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.map_id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if redirect_when_disallowed(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    @review_scores = Array.new&lt;br /&gt;
    @question_type = Array.new&lt;br /&gt;
    @questions.each do |question|&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; Score.where(response_id: @map.response_id, question_id:  question.id).first&lt;br /&gt;
      @question_type &amp;lt;&amp;lt; QuestionType.find_by_question_id(question.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
  describe &amp;quot;#get_children_node_ng&amp;quot; do&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97325</id>
		<title>CSC/ECE 517 Fall 2015/oss E1570 avr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1570_avr&amp;diff=97325"/>
		<updated>2015-10-30T15:12:29Z</updated>

		<summary type="html">&lt;p&gt;Abonam: /* TreeDisplayController */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''E1570. Refactoring TreeDisplayController'''&lt;br /&gt;
&lt;br /&gt;
This page provides a description of the Expertiza based OSS project. This project aimed at refactoring the TreeDisplayController.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Expertiza=&lt;br /&gt;
Expertiza is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). The Expertiza project is supported by the National Science Foundation.&amp;lt;ref&amp;gt;[http://expertiza.ncsu.edu/ Expertiza]&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[http://wikis.lib.ncsu.edu/index.php/Expertiza Wiki]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Problem Statement =&lt;br /&gt;
'''Classes involved:'''&lt;br /&gt;
 tree_display_controller.rb&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''What they do:'''&lt;br /&gt;
This controller deals with displaying “trees” of objects to the instructor.  When an instructor logs in, (s)he is greeted with a homepage that lists questionnaires (rubrics, quizzes, surveys), courses, and assignments.  These objects are displayed in a “tree,” allowing the user to click on the top-level object and see the objects beneath it.&lt;br /&gt;
&lt;br /&gt;
'''What's wrong with it:'''&lt;br /&gt;
* Many Duplicate Methods.&lt;br /&gt;
* Very Long Methods combining many Functionalities.&lt;br /&gt;
* Redundant methods not being used anywhere.&lt;br /&gt;
&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
#   Split  &amp;lt;font face=Courier New&amp;gt;get_children_node_ng &amp;lt;/font&amp;gt; and &amp;lt;font face=Courier New&amp;gt;get_children_node_2_ng &amp;lt;/font&amp;gt; into smaller methods and give reasonable names to them and make sure implement common code in a single method.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Changes Made=&lt;br /&gt;
&lt;br /&gt;
==TreeDisplayController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| goto_questionnaires, goto_review_rubrics, goto_metareview_rubrics, goto_teammatereview_rubrics, goto_author_feedbacks, goto_global_survey, goto_surveys, goto_course_evaluations, goto_courses, goto_assignments&lt;br /&gt;
| All these methods were merged into a single method with name go_to_menu_items which receives a parameter of the name of tree_folder object, such as &amp;quot;Questionnaires&amp;quot;.&lt;br /&gt;
|Since all the methods were performing the same action, i.e passing the node object id to list method in TreeDisplayController, the name is passed a parameter to the go_to_menu_items method from &amp;quot;link&amp;quot; method in MenuItemsController. Using this parameter the respective object and its ID are found and is redirected to &amp;quot;list&amp;quot; method.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_ng&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | Moved part of the code from these methods to newly created methods populate_rows,display_row,page_render methods.&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot; | These Methods had many functionalities being implemented which made the method look lengthy and moreover these methods were performing almost similar functions which could be grouped together and reduce the overall code length.&lt;br /&gt;
|-&lt;br /&gt;
| get_children_node_2_ng&lt;br /&gt;
|-&lt;br /&gt;
| Put ur method here&lt;br /&gt;
| Put ur txt here&lt;br /&gt;
| put ur text here&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==MenuItemsController==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:13%;&amp;quot;|Method Name&lt;br /&gt;
! style=&amp;quot;width:33%;&amp;quot;|Changes Made &lt;br /&gt;
! style=&amp;quot;width:43%;&amp;quot;|Reason For Change&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|-------&lt;br /&gt;
| link&lt;br /&gt;
| Redirect url only for the menu_items altered in TreeDisplayController is changed to go_to_menu_items_url.&lt;br /&gt;
| Since the 10 methods had been merged into one method in TreeDisplayController, the redirect url is set to go_to_menu_items url. &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
= Re-factored Code =&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      tmpRes[fnode.get_name] = ch_nodes&lt;br /&gt;
&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    for nodeType in tmpRes.keys&lt;br /&gt;
      res[nodeType] =  Array.new&lt;br /&gt;
&lt;br /&gt;
      for node in tmpRes[nodeType]&lt;br /&gt;
        tmpObject = {}&lt;br /&gt;
        tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
        tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
        tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
&lt;br /&gt;
        if nodeType == 'Courses' || nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
          tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
          tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
          tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
          tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
          instructor_id = node.get_instructor_id&lt;br /&gt;
          tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
&lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
          if nodeType == &amp;quot;Assignments&amp;quot;&lt;br /&gt;
            tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
            tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
            tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
            tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
            tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
            tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res[nodeType] &amp;lt;&amp;lt; tmpObject&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
   def get_children_node_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    ch_nodes = {}&lt;br /&gt;
    for node in childNodes&lt;br /&gt;
      # Declaring Foldernode Object as New&lt;br /&gt;
      fnode = eval(params[:reactParams][:nodeType]).new&lt;br /&gt;
      for a in node&lt;br /&gt;
        fnode[a[0]] = a[1]&lt;br /&gt;
      end&lt;br /&gt;
      # fnode is the parent node&lt;br /&gt;
      # ch_nodes are childrens&lt;br /&gt;
      ch_nodes[fnode.get_name] = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
      # cnode = fnode.get_children(&amp;quot;created_at&amp;quot;, &amp;quot;desc&amp;quot;, 2, nil, nil)&lt;br /&gt;
    end&lt;br /&gt;
      call_function =&amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      #Render JSON of the child nodes&lt;br /&gt;
      populate_rows(ch_nodes,call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Refactoring get_children_node_2_ng method==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_children_node_2_ng&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
    tmpRes = {}&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
    tmpRes = ch_nodes&lt;br /&gt;
    if tmpRes&lt;br /&gt;
      for child in tmpRes&lt;br /&gt;
        nodeType = child.type&lt;br /&gt;
        res2 = {}&lt;br /&gt;
        res2[&amp;quot;nodeinfo&amp;quot;] = child&lt;br /&gt;
        res2[&amp;quot;name&amp;quot;] = child.get_name&lt;br /&gt;
        res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
        res2[&amp;quot;type&amp;quot;] = nodeType&lt;br /&gt;
&lt;br /&gt;
        res2[&amp;quot;private&amp;quot;] = child.get_private&lt;br /&gt;
        res2[&amp;quot;creation_date&amp;quot;] = child.get_creation_date&lt;br /&gt;
        res2[&amp;quot;updated_date&amp;quot;] = child.get_modified_date&lt;br /&gt;
        if nodeType == 'CourseNode' || nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
          res2[&amp;quot;directory&amp;quot;] = child.get_directory&lt;br /&gt;
          instructor_id = child.get_instructor_id&lt;br /&gt;
          res2[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
          unless (instructor_id.nil?)&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
          else&lt;br /&gt;
            res2[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
          end&lt;br /&gt;
&lt;br /&gt;
          res2[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; &lt;br /&gt;
Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(child))&lt;br /&gt;
          if nodeType == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
            res2[&amp;quot;course_id&amp;quot;] = child.get_course_id&lt;br /&gt;
            res2[&amp;quot;max_team_size&amp;quot;] = child.get_max_team_size&lt;br /&gt;
            res2[&amp;quot;is_intelligent&amp;quot;] = child.get_is_intelligent&lt;br /&gt;
            res2[&amp;quot;require_quiz&amp;quot;] = child.get_require_quiz&lt;br /&gt;
            res2[&amp;quot;allow_suggestions&amp;quot;] = child.get_allow_suggestions&lt;br /&gt;
            res2[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', child.node_object_id]).first ? true : false&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
        res &amp;lt;&amp;lt; res2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: res}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
 def get_children_node_2_ng&lt;br /&gt;
    # Second Level of Tree Display with Children Nodes&lt;br /&gt;
    childNodes = {}&lt;br /&gt;
    if params[:reactParams2][:child_nodes].is_a? String&lt;br /&gt;
      childNodes = JSON.parse(params[:reactParams2][:child_nodes])&lt;br /&gt;
    else&lt;br /&gt;
      childNodes = params[:reactParams2][:child_nodes]&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    res = []&lt;br /&gt;
    fnode = eval(params[:reactParams2][:nodeType]).new&lt;br /&gt;
    childNodes.each do |key, value|&lt;br /&gt;
      fnode[key] = value&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    ch_nodes = fnode.get_children(nil, nil, session[:user].id, nil, nil)&lt;br /&gt;
&lt;br /&gt;
    call_function = &amp;quot;get_children_node_2_ng&amp;quot;&lt;br /&gt;
    populate_rows(ch_nodes, call_function)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Common Methods Added to get_children_node_ng and get_children_node_2_ng controllers ==&lt;br /&gt;
&lt;br /&gt;
===populate_rows ===&lt;br /&gt;
  &lt;br /&gt;
This is a new Common Method for both get_children_node_ng and get_children_node_2_ng  that does the functionality of rendering a page with data from all nodes by calling another method populate_1_row(). There is another Method call that happens in this method which as a whole renders the List View.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
! |populate_rows()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_rows(list,call_function) #render page with data for all nodes in list&lt;br /&gt;
    if call_function == &amp;quot;get_children_node_ng&amp;quot;&lt;br /&gt;
      tmpRes ={}&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = {}&lt;br /&gt;
       for nodeType in tmpRes.keys&lt;br /&gt;
        # declaring a new array&lt;br /&gt;
        res[nodeType] =  Array.new&lt;br /&gt;
        for node in tmpRes[nodeType]&lt;br /&gt;
          res[nodeType] &amp;lt;&amp;lt; populate_1_row(node)&lt;br /&gt;
        end&lt;br /&gt;
       end&lt;br /&gt;
&lt;br /&gt;
    else&lt;br /&gt;
      tmpRes = list&lt;br /&gt;
      res = []&lt;br /&gt;
      if tmpRes&lt;br /&gt;
        for child in tmpRes&lt;br /&gt;
          res2 = {}&lt;br /&gt;
          res2 = populate_1_row(child)&lt;br /&gt;
          res2[&amp;quot;key&amp;quot;] = params[:reactParams2][:key]&lt;br /&gt;
          res &amp;lt;&amp;lt; res2&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    page_render(res)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===populate_1_row ===&lt;br /&gt;
&lt;br /&gt;
  This is a new Method that is called from Method populate_row() and fetches all the child node names from respective Controller actions and then populates the tmpObject.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |populate_1_row()&lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def populate_1_row(node) #return JSON for 1 Node&lt;br /&gt;
    tmpObject = {}&lt;br /&gt;
    tmpObject[&amp;quot;nodeinfo&amp;quot;] = node&lt;br /&gt;
    # all the child nodes names got and put in tmpObject from respective controller actions&lt;br /&gt;
    tmpObject[&amp;quot;name&amp;quot;] = node.get_name&lt;br /&gt;
    tmpObject[&amp;quot;type&amp;quot;] = node.type&lt;br /&gt;
    if node.type == 'CourseNode' || node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
      tmpObject[&amp;quot;directory&amp;quot;] = node.get_directory&lt;br /&gt;
      tmpObject[&amp;quot;creation_date&amp;quot;] = node.get_creation_date&lt;br /&gt;
      tmpObject[&amp;quot;updated_date&amp;quot;] = node.get_modified_date&lt;br /&gt;
      tmpObject[&amp;quot;private&amp;quot;] = node.get_private&lt;br /&gt;
      instructor_id = node.get_instructor_id&lt;br /&gt;
      tmpObject[&amp;quot;instructor_id&amp;quot;] = instructor_id&lt;br /&gt;
      unless (instructor_id.nil?)&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = User.find(instructor_id).name&lt;br /&gt;
      else&lt;br /&gt;
        tmpObject[&amp;quot;instructor&amp;quot;] = nil&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
      tmpObject[&amp;quot;is_available&amp;quot;] = is_available(session[:user], instructor_id) || (session[:user].role_id == 6 &amp;amp;&amp;amp; Ta.get_my_instructors(session[:user].id).include?(instructor_id) &amp;amp;&amp;amp; ta_for_current_course?(node))&lt;br /&gt;
      if node.type == &amp;quot;AssignmentNode&amp;quot;&lt;br /&gt;
        tmpObject[&amp;quot;course_id&amp;quot;] = node.get_course_id&lt;br /&gt;
        tmpObject[&amp;quot;max_team_size&amp;quot;] = node.get_max_team_size&lt;br /&gt;
        tmpObject[&amp;quot;is_intelligent&amp;quot;] = node.get_is_intelligent&lt;br /&gt;
        tmpObject[&amp;quot;require_quiz&amp;quot;] = node.get_require_quiz&lt;br /&gt;
        tmpObject[&amp;quot;allow_suggestions&amp;quot;] = node.get_allow_suggestions&lt;br /&gt;
        tmpObject[&amp;quot;has_topic&amp;quot;] = SignUpTopic.where(['assignment_id = ?', node.node_object_id]).first ? true : false&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    tmpObject&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
===page_render ===&lt;br /&gt;
&lt;br /&gt;
  This is also a common Method which integrates the rendering functionality of get_children_node_ng and get_children_node_2_ng making sure both levels are properly populated in the view.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def page_render(list) # Common Render Functionality for get_children_node_ng and get_children_node_2_ng methods&lt;br /&gt;
    respond_to do |format|&lt;br /&gt;
      format.html {render json: list}&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
== Method Removal==&lt;br /&gt;
 There was a Method which dint have any Routes defined in the Routes.rb file and was not called in any of the Controller . After Careful analysis we descided to remove the method from the tree Display Controller.&lt;br /&gt;
&lt;br /&gt;
=== filter ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |filter &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  def filter&lt;br /&gt;
    search = params[:filter_string]&lt;br /&gt;
    filter_node = params[:filternode]&lt;br /&gt;
    qid = 'filter+'&lt;br /&gt;
&lt;br /&gt;
    if filter_node == 'QAN'&lt;br /&gt;
      assignment = Assignment.find_by_name(search)&lt;br /&gt;
      if assignment&lt;br /&gt;
        assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: assignment.id)&lt;br /&gt;
        if assignment_questionnaires&lt;br /&gt;
          assignment_questionnaires.each { |q|  qid &amp;lt;&amp;lt; &amp;quot;#{q.questionnaire_id.to_s}+&amp;quot; }&lt;br /&gt;
          session[:root] = 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    elsif filter_node == 'ACN'&lt;br /&gt;
      session[:root] = 2&lt;br /&gt;
      qid &amp;lt;&amp;lt;  search&lt;br /&gt;
    end&lt;br /&gt;
    return qid&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
==Removing duplicate methods==&lt;br /&gt;
Anush For u to write here...&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |Before Changes&lt;br /&gt;
! |After Changes &lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.map_id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def new_feedback&lt;br /&gt;
    review = Response.find(params[:id])&lt;br /&gt;
    if review&lt;br /&gt;
      reviewer = AssignmentParticipant.where(user_id: session[:user].id, parent_id:  review.map.assignment.id).first&lt;br /&gt;
      map = FeedbackResponseMap.where(reviewed_object_id: review.id, reviewer_id:  reviewer.id).first&lt;br /&gt;
      if map.nil?&lt;br /&gt;
        #if no feedback exists by dat user den only create for dat particular response/review&lt;br /&gt;
        map = FeedbackResponseMap.create(:reviewed_object_id =&amp;gt; review.id, :reviewer_id =&amp;gt; reviewer.id, &lt;br /&gt;
                                         :reviewee_id =&amp;gt; review.map.reviewer.id)&lt;br /&gt;
      end&lt;br /&gt;
      redirect_to :action =&amp;gt; 'new', :id =&amp;gt; map.id, :return =&amp;gt; &amp;quot;feedback&amp;quot;&lt;br /&gt;
    else&lt;br /&gt;
      redirect_to :back&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|- style=&amp;quot;vertical-align:bottom;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if redirect_when_disallowed(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    @review_scores = Array.new&lt;br /&gt;
    @question_type = Array.new&lt;br /&gt;
    @questions.each do |question|&lt;br /&gt;
      @review_scores &amp;lt;&amp;lt; Score.where(response_id: @map.response_id, question_id:  question.id).first&lt;br /&gt;
      @question_type &amp;lt;&amp;lt; QuestionType.find_by_question_id(question.id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
def view&lt;br /&gt;
    @response = Response.find(params[:id])&lt;br /&gt;
    return if action_allowed?(@response)&lt;br /&gt;
    @map = @response.map&lt;br /&gt;
    get_content&lt;br /&gt;
    get_scores(@response, @questions)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
==Rspec Test==&lt;br /&gt;
&lt;br /&gt;
  We have written Rspec tests for the tree_display_controller and have run the same with success.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! |page_render() &lt;br /&gt;
|- style=&amp;quot;vertical-align:top;&amp;quot;&lt;br /&gt;
|&amp;lt;pre&amp;gt;&lt;br /&gt;
  require 'rails_helper'&lt;br /&gt;
&lt;br /&gt;
describe TreeDisplayController do&lt;br /&gt;
  describe &amp;quot;#get_children_node_ng&amp;quot; do&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#list&amp;quot; do&lt;br /&gt;
    it &amp;quot;should not redirect to student_task controller if current user is an instructor&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(false)&lt;br /&gt;
      post &amp;quot;list&amp;quot;&lt;br /&gt;
      response.should_not redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
    it &amp;quot;should redirect to student_task controller if current user is a student&amp;quot; do&lt;br /&gt;
      allow(session[:user]).to receive(&amp;quot;student?&amp;quot;).and_return(true)&lt;br /&gt;
       post &amp;quot;list&amp;quot;&lt;br /&gt;
       response.should redirect_to(list_student_task_index_path)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#ta_for_current_mappings?&amp;quot; do&lt;br /&gt;
    it &amp;quot;should return true if current user is a TA for current course&amp;quot; do&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_rows&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_rows).with(Hash, String)}&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_rows({},&amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
  describe &amp;quot;#populate_1_row&amp;quot; do&lt;br /&gt;
    let(:dbl) { double }&lt;br /&gt;
    before { expect(dbl).to receive(:populate_1_row).with(Node) }&lt;br /&gt;
    it &amp;quot;passes when the arguments match&amp;quot; do&lt;br /&gt;
      dbl.populate_1_row(Node.new)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&amp;lt;references&amp;gt;&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abonam</name></author>
	</entry>
</feed>