<?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=Ggpalank</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=Ggpalank"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ggpalank"/>
	<updated>2026-09-11T17:15:17Z</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_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99062</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99062"/>
		<updated>2015-11-09T06:26:22Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. 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 [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*'''assignment_participant.rb'''&lt;br /&gt;
*'''assignment_team.rb''' and &lt;br /&gt;
*views related to submitted hyperlinks and files ('''submitted_content/_hyperlink.html.erb''', '''submitted_content/_submitted_files.html.erb''')&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column '''hyperlinks''' in '''teams''' table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&amp;lt;br&amp;gt;- hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the '''directory_num''' field (also the content) to '''teams''' table.&amp;lt;br&amp;gt;- Move the '''set_student_directory_num''' from '''participant_controller''' to '''team_controller''', then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have '''directory_num''', instead, it just check the '''directory_num''' from '''teams''' table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to '''team_id''', say, '''23841'''. Since there is no existing correlation between teams and submitted content, we will first need to look up the '''participants''' in the team using the '''teams_users''' table. And then, using those user_id values one at a time, we need to look up the '''participants''' table.&lt;br /&gt;
&lt;br /&gt;
[[File:db.jpg]]&lt;br /&gt;
&lt;br /&gt;
Finally, we need to merge the results before displaying it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hyperlinks&lt;br /&gt;
  links = Array.new&lt;br /&gt;
  self.participants.each { |team_member|&lt;br /&gt;
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}&lt;br /&gt;
  links&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient.&lt;br /&gt;
&lt;br /&gt;
Instead, if the hyperlinks data were available in '''teams''' table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.&lt;br /&gt;
&lt;br /&gt;
As a part of this change, we’ll have to move the following routines in '''assignment_participants.rb''', which deal hyperlink handling to '''assignment_team.rb'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Appends the hyperlink to a list that is stored in YAML format in the DB&lt;br /&gt;
  # @exception  If is hyperlink was already there&lt;br /&gt;
  #             If it is an invalid URL&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Note: This method is not used yet. It is here in the case it will be&lt;br /&gt;
    needed.&lt;br /&gt;
  # @exception  If the index does not exist in the array&lt;br /&gt;
  def remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks.delete(hyperlink_to_delete)&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar refactoring work needs to be done for the '''directory_num''' field as well.&lt;br /&gt;
Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:&lt;br /&gt;
*the submitted hyperlinks and files are correctly displayed on the submitted content page.&lt;br /&gt;
*the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*the instructor can see the submitted content from the reviewees.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
'''Use Case 1:''' Submit hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The submitted hyperlink should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted hyperlink.&lt;br /&gt;
#A reviewer should be able to see the submitted hyperlink.&lt;br /&gt;
#An instructor should be able to see the submitted hyperlink.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Use Case 2:''' Submit file for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the file.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted file is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted file.&lt;br /&gt;
#A reviewer should be able to see the submitted file.&lt;br /&gt;
#An instructor should be able to see the submitted file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Use Case 3:''' Delete hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to delete the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The deleted hyperlink should be removed from the teams table in DB.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.&lt;br /&gt;
#All other team members should not see the deleted hyperlink.&lt;br /&gt;
#A reviewer should not be able to see the deleted hyperlink.&lt;br /&gt;
#An instructor should not be able to see the deleted hyperlink.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Scope for further Improvement =&lt;br /&gt;
A proposal for further improvement would be to possibly create a new '''submitted_content''' table in the database. This table could include attributes like '''user_id''', '''team_id''', '''can_submit''', '''hyperlink''', '''directory_num''', '''uploaded_at''', '''updated_at'''. This approach would resolve the existing hyperlinks issue and more importantly, aid in recording a history of the submitted hyperlinks. There could be a “Show previous submissions” view for a team. So, if ever there’s a scenario where a student or an instructor needs to revert or go back and check a previous submission, he/she can easily access it from this table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99061</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99061"/>
		<updated>2015-11-09T06:25:43Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. 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 [https://en.wikipedia.org/wiki/Open_source open source] application and the code can be cloned from [https://github.com/expertiza/expertiza 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*'''assignment_participant.rb'''&lt;br /&gt;
*'''assignment_team.rb''' and &lt;br /&gt;
*views related to submitted hyperlinks and files ('''submitted_content/_hyperlink.html.erb''', '''submitted_content/_submitted_files.html.erb''')&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column '''hyperlinks''' in '''teams''' table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&amp;lt;br&amp;gt;- hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the '''directory_num''' field (also the content) to '''teams''' table.&amp;lt;br&amp;gt;- Move the '''set_student_directory_num''' from '''participant_controller''' to '''team_controller''', then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have '''directory_num''', instead, it just check the '''directory_num''' from '''teams''' table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to '''team_id''', say, '''23841'''. Since there is no existing correlation between teams and submitted content, we will first need to look up the '''participants''' in the team using the '''teams_users''' table. And then, using those user_id values one at a time, we need to look up the '''participants''' table.&lt;br /&gt;
&lt;br /&gt;
[[File:db.jpg]]&lt;br /&gt;
&lt;br /&gt;
Finally, we need to merge the results before displaying it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hyperlinks&lt;br /&gt;
  links = Array.new&lt;br /&gt;
  self.participants.each { |team_member|&lt;br /&gt;
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}&lt;br /&gt;
  links&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient.&lt;br /&gt;
&lt;br /&gt;
Instead, if the hyperlinks data were available in '''teams''' table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.&lt;br /&gt;
&lt;br /&gt;
As a part of this change, we’ll have to move the following routines in '''assignment_participants.rb''', which deal hyperlink handling to '''assignment_team.rb'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Appends the hyperlink to a list that is stored in YAML format in the DB&lt;br /&gt;
  # @exception  If is hyperlink was already there&lt;br /&gt;
  #             If it is an invalid URL&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Note: This method is not used yet. It is here in the case it will be&lt;br /&gt;
    needed.&lt;br /&gt;
  # @exception  If the index does not exist in the array&lt;br /&gt;
  def remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks.delete(hyperlink_to_delete)&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar refactoring work needs to be done for the '''directory_num''' field as well.&lt;br /&gt;
Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:&lt;br /&gt;
*the submitted hyperlinks and files are correctly displayed on the submitted content page.&lt;br /&gt;
*the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*the instructor can see the submitted content from the reviewees.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
'''Use Case 1:''' Submit hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The submitted hyperlink should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted hyperlink.&lt;br /&gt;
#A reviewer should be able to see the submitted hyperlink.&lt;br /&gt;
#An instructor should be able to see the submitted hyperlink.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Use Case 2:''' Submit file for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the file.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted file is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted file.&lt;br /&gt;
#A reviewer should be able to see the submitted file.&lt;br /&gt;
#An instructor should be able to see the submitted file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Use Case 3:''' Delete hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to delete the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The deleted hyperlink should be removed from the teams table in DB.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.&lt;br /&gt;
#All other team members should not see the deleted hyperlink.&lt;br /&gt;
#A reviewer should not be able to see the deleted hyperlink.&lt;br /&gt;
#An instructor should not be able to see the deleted hyperlink.&lt;br /&gt;
&lt;br /&gt;
= Scope for further Improvement =&lt;br /&gt;
A proposal for further improvement would be to possibly create a new '''submitted_content''' table in the database. This table could include attributes like '''user_id''', '''team_id''', '''can_submit''', '''hyperlink''', '''directory_num''', '''uploaded_at''', '''updated_at'''. This approach would resolve the existing hyperlinks issue and more importantly, aid in recording a history of the submitted hyperlinks. There could be a “Show previous submissions” view for a team. So, if ever there’s a scenario where a student or an instructor needs to revert or go back and check a previous submission, he/she can easily access it from this table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99058</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99058"/>
		<updated>2015-11-09T06:22:50Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/getting_started.html&amp;lt;/ref&amp;gt;. 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 [https://github.com/expertiza/expertiza 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*'''assignment_participant.rb'''&lt;br /&gt;
*'''assignment_team.rb''' and &lt;br /&gt;
*views related to submitted hyperlinks and files ('''submitted_content/_hyperlink.html.erb''', '''submitted_content/_submitted_files.html.erb''')&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column '''hyperlinks''' in '''teams''' table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&amp;lt;br&amp;gt;- hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the '''directory_num''' field (also the content) to '''teams''' table.&amp;lt;br&amp;gt;- Move the '''set_student_directory_num''' from '''participant_controller''' to '''team_controller''', then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have '''directory_num''', instead, it just check the '''directory_num''' from '''teams''' table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to '''team_id''', say, '''23841'''. Since there is no existing correlation between teams and submitted content, we will first need to look up the '''participants''' in the team using the '''teams_users''' table. And then, using those user_id values one at a time, we need to look up the '''participants''' table.&lt;br /&gt;
&lt;br /&gt;
[[File:db.jpg]]&lt;br /&gt;
&lt;br /&gt;
Finally, we need to merge the results before displaying it. So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hyperlinks&lt;br /&gt;
  links = Array.new&lt;br /&gt;
  self.participants.each { |team_member|&lt;br /&gt;
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}&lt;br /&gt;
  links&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, if the hyperlinks data were available in '''teams''' table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.&lt;br /&gt;
&lt;br /&gt;
As a part of this change, we’ll have to move the following routines in '''assignment_participants.rb''', which deal hyperlink handling to '''assignment_team.rb'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Appends the hyperlink to a list that is stored in YAML format in the DB&lt;br /&gt;
  # @exception  If is hyperlink was already there&lt;br /&gt;
  #             If it is an invalid URL&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Note: This method is not used yet. It is here in the case it will be&lt;br /&gt;
    needed.&lt;br /&gt;
  # @exception  If the index does not exist in the array&lt;br /&gt;
  def remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks.delete(hyperlink_to_delete)&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar refactoring work needs to be done for the '''directory_num''' field as well.&lt;br /&gt;
Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:&lt;br /&gt;
*the submitted hyperlinks and files are correctly displayed on the submitted content page.&lt;br /&gt;
*the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*the instructor can see the submitted content from the reviewees.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
'''Use Case 1:''' Submit hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The submitted hyperlink should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted hyperlink.&lt;br /&gt;
#A reviewer should be able to see the submitted hyperlink.&lt;br /&gt;
#An instructor should be able to see the submitted hyperlink.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Use Case 2:''' Submit file for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the file.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted file is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted file.&lt;br /&gt;
#A reviewer should be able to see the submitted file.&lt;br /&gt;
#An instructor should be able to see the submitted file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Use Case 3:''' Delete hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to delete the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The deleted hyperlink should be removed from the teams table in DB.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.&lt;br /&gt;
#All other team members should not see the deleted hyperlink.&lt;br /&gt;
#A reviewer should not be able to see the deleted hyperlink.&lt;br /&gt;
#An instructor should not be able to see the deleted hyperlink.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99057</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99057"/>
		<updated>2015-11-09T06:10:29Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza&amp;lt;ref&amp;gt;https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt; is a project developed using Ruby on Rails platform. 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 [https://github.com/expertiza/expertiza 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*assignment_participant.rb&lt;br /&gt;
*assignment_team.rb and &lt;br /&gt;
*views related to submitted hyperlinks and files (submitted_content/_hyperlink.html.erb, submitted_content/_submitted_files.html.erb)&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column hyperlinks in teams table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from participants table into teams table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the hyperlinks field from participants table.&amp;lt;br&amp;gt;- hyperlink-related methods in both assignment_participant.rb and assignment_team.rb have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the directory_num field (also the content) to teams table.&amp;lt;br&amp;gt;- Move the set_student_directory_num from participant_controller to team_controller, then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have directory_num, instead, it just check the directory_num from teams table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to team_id, say, 23841. Since there is no existing correlation between teams and submitted content, we will first need to look up the participants in the team using the teams_users table. And then, using those user_id values one at a time, we need to look up the participants table.&lt;br /&gt;
&lt;br /&gt;
[[File:db.jpg]]&lt;br /&gt;
&lt;br /&gt;
Finally, we need to merge the results before displaying it. So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hyperlinks&lt;br /&gt;
  links = Array.new&lt;br /&gt;
  self.participants.each { |team_member|&lt;br /&gt;
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}&lt;br /&gt;
  links&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, if the hyperlinks data were available in teams table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.&lt;br /&gt;
&lt;br /&gt;
As a part of this change, we’ll have to move the following routines in '''assignment_participants.rb''', which deal hyperlink handling to '''assignment_team.rb'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Appends the hyperlink to a list that is stored in YAML format in the DB&lt;br /&gt;
  # @exception  If is hyperlink was already there&lt;br /&gt;
  #             If it is an invalid URL&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Note: This method is not used yet. It is here in the case it will be&lt;br /&gt;
    needed.&lt;br /&gt;
  # @exception  If the index does not exist in the array&lt;br /&gt;
  def remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks.delete(hyperlink_to_delete)&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar refactoring work needs to be done for the '''directory_num''' field as well.&lt;br /&gt;
Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:&lt;br /&gt;
*the submitted hyperlinks and files are correctly displayed on the submitted content page.&lt;br /&gt;
*the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*the instructor can see the submitted content from the reviewees.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
'''Use Case 1:''' Submit hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The submitted hyperlink should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted hyperlink.&lt;br /&gt;
#A reviewer should be able to see the submitted hyperlink.&lt;br /&gt;
#An instructor should be able to see the submitted hyperlink.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Use Case 2:''' Submit file for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the file.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted file is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted file.&lt;br /&gt;
#A reviewer should be able to see the submitted file.&lt;br /&gt;
#An instructor should be able to see the submitted file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Use Case 3:''' Delete hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to delete the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The deleted hyperlink should be removed from the teams table in DB.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.&lt;br /&gt;
#All other team members should not see the deleted hyperlink.&lt;br /&gt;
#A reviewer should not be able to see the deleted hyperlink.&lt;br /&gt;
#An instructor should not be able to see the deleted hyperlink.&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99056</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99056"/>
		<updated>2015-11-09T05:46:51Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails platform. 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*assignment_participant.rb&lt;br /&gt;
*assignment_team.rb and &lt;br /&gt;
*views related to submitted hyperlinks and files (submitted_content/_hyperlink.html.erb, submitted_content/_submitted_files.html.erb)&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column hyperlinks in teams table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from participants table into teams table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the hyperlinks field from participants table.&amp;lt;br&amp;gt;- hyperlink-related methods in both assignment_participant.rb and assignment_team.rb have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the directory_num field (also the content) to teams table.&amp;lt;br&amp;gt;- Move the set_student_directory_num from participant_controller to team_controller, then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have directory_num, instead, it just check the directory_num from teams table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to team_id, say, 23841. Since there is no existing correlation between teams and submitted content, we will first need to look up the participants in the team using the teams_users table. And then, using those user_id values one at a time, we need to look up the participants table.&lt;br /&gt;
&lt;br /&gt;
[[File:db.jpg]]&lt;br /&gt;
&lt;br /&gt;
Finally, we need to merge the results before displaying it. So, it becomes a tedious 3-step process. It is evident from this example that the current design is inefficient:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hyperlinks&lt;br /&gt;
  links = Array.new&lt;br /&gt;
  self.participants.each { |team_member|&lt;br /&gt;
    links.concat(team_member.hyperlinks_array) if team_member.hyperlinks_array}&lt;br /&gt;
  links&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead, if the hyperlinks data were available in teams table, we could directly access all the submitted content for a team in one shot, making it much more streamlined.&lt;br /&gt;
&lt;br /&gt;
As a part of this change, we’ll have to move the following routines in '''assignment_participants.rb''', which deal hyperlink handling to '''assignment_team.rb'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Appends the hyperlink to a list that is stored in YAML format in the DB&lt;br /&gt;
  # @exception  If is hyperlink was already there&lt;br /&gt;
  #             If it is an invalid URL&lt;br /&gt;
  def submit_hyperlink(hyperlink)&lt;br /&gt;
    hyperlink.strip!&lt;br /&gt;
    raise &amp;quot;The hyperlink cannot be empty&amp;quot; if hyperlink.empty?&lt;br /&gt;
    url = URI.parse(hyperlink)&lt;br /&gt;
    # If not a valid URL, it will throw an exception&lt;br /&gt;
    Net::HTTP.start(url.host, url.port)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks &amp;lt;&amp;lt; hyperlink&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Note: This method is not used yet. It is here in the case it will be&lt;br /&gt;
    needed.&lt;br /&gt;
  # @exception  If the index does not exist in the array&lt;br /&gt;
  def remove_hyperlink(hyperlink_to_delete)&lt;br /&gt;
    hyperlinks = self.hyperlinks_array&lt;br /&gt;
    hyperlinks.delete(hyperlink_to_delete)&lt;br /&gt;
    self.submitted_hyperlinks = YAML::dump(hyperlinks)&lt;br /&gt;
    self.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def hyperlinks&lt;br /&gt;
    team.try(:hyperlinks) || []&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def hyperlinks_array&lt;br /&gt;
    self.submitted_hyperlinks.blank? ? [] :YAML::load(self.submitted_hyperlinks)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar refactoring work needs to be done for the '''directory_num''' field as well.&lt;br /&gt;
Finally, the refactoring needs to be thoroughly tested by writing test cases for student-submitted hyperlinks and files by making sure that:&lt;br /&gt;
*the submitted hyperlinks and files are correctly displayed on the submitted content page.&lt;br /&gt;
*the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*the instructor can see the submitted content from the reviewees.&lt;br /&gt;
&lt;br /&gt;
== Use Cases ==&lt;br /&gt;
'''Use Case 1:''' Submit hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The submitted hyperlink should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted hyperlink is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted hyperlink.&lt;br /&gt;
#A reviewer should be able to see the submitted hyperlink.&lt;br /&gt;
#An instructor should be able to see the submitted hyperlink.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
'''Use Case 2:''' Submit file for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to submit a file on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to submit the file.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The directory_num field which stores the directory number of the directory storing all the submitted files for a team should be stored in the teams table of the database.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The submitted file is visible every time the student views the “Your work” section for the Assignment.&lt;br /&gt;
#All other team members should be able to view the submitted file.&lt;br /&gt;
#A reviewer should be able to see the submitted file.&lt;br /&gt;
#An instructor should be able to see the submitted file.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Use Case 3:''' Delete hyperlink for an assignment by student.&lt;br /&gt;
 &lt;br /&gt;
'''Description:''' A student who is an assignment participant should be able to delete submitted hyperlink on the “Your work” section of an assignment.&lt;br /&gt;
 &lt;br /&gt;
'''Preconditions:''' Student should be a participant for the assignment he is trying to delete the hyperlink.&lt;br /&gt;
 &lt;br /&gt;
'''Postconditions:''' The deleted hyperlink should be removed from the teams table in DB.&lt;br /&gt;
 &lt;br /&gt;
'''Success Scenario:'''&lt;br /&gt;
#The deleted hyperlink should not be visible the next time the student clicks on “Your work” section.&lt;br /&gt;
#All other team members should not see the deleted hyperlink.&lt;br /&gt;
#A reviewer should not be able to see the deleted hyperlink.&lt;br /&gt;
#An instructor should not be able to see the deleted hyperlink.&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99055</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99055"/>
		<updated>2015-11-09T05:25:02Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: /* Introduction to Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails platform. 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;
= Problem Statement =&lt;br /&gt;
&lt;br /&gt;
== Files involved ==&lt;br /&gt;
*assignment_participant.rb&lt;br /&gt;
*assignment_team.rb and &lt;br /&gt;
*views related to submitted hyperlinks and files (submitted_content/_hyperlink.html.erb, submitted_content/_submitted_files.html.erb)&lt;br /&gt;
&lt;br /&gt;
== What it does ==&lt;br /&gt;
It handles the display, submission, deletion of hyperlinks and files by the teams.&lt;br /&gt;
&lt;br /&gt;
== What is wrong with it ==&lt;br /&gt;
The submitted hyperlinks and files are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments).&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. Similar overhead happens when a team member wants to delete a submitted hyperlink. Also, the '''directory_num''' field needs to be moved from the '''participants''' table to the '''teams''' table. It signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''.&lt;br /&gt;
&lt;br /&gt;
== What needs to be done ==&lt;br /&gt;
*Create a new column '''hyperlinks''' in the '''teams''' table.&lt;br /&gt;
*Write db migration, move all the participants’ submitted hyperlinks from '''participants''' table into '''teams''' table. Duplicate hyperlinks need to be removed.&lt;br /&gt;
*Write db migration, remove the '''hyperlinks''' field from '''participants''' table.&lt;br /&gt;
*Rewrite the hyperlink-related methods in both '''assignment_participant.rb''' and '''assignment_team.rb''' to make sure the new code works with the new db design.&lt;br /&gt;
*Make sure when doing the peer-review, the reviewer can see the submitted content from the reviewees.&lt;br /&gt;
*Make sure when instructor see the peer-review records, they can see the submitted content from the reviewees.&lt;br /&gt;
*Write db migration, move the '''directory_num''' field (also the content, of course) to the '''teams''' table.&lt;br /&gt;
*Move the '''set_student_directory_num''' method from '''participants_controller''' to '''teams_controller''', then refactor this method into smaller methods.&lt;br /&gt;
**This method no longer needs to test all the participants.&lt;br /&gt;
**Check if any of them have '''directory_num'''. If so, instead, it should just check the '''directory_num''' from '''teams''' table.&lt;br /&gt;
*Make change to the submitted-file-related code to make it work with the new design.&lt;br /&gt;
*Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Problem Description =&lt;br /&gt;
The main purpose of this project is to improve how submitted hyperlinks are recorded in Expertiza in the current scheme. As of now, the submitted hyperlinks are stored in '''participants''' table, which means they are associated with individuals instead of team. This is not a good design because in Expertiza, students are always grouped in teams, even when there is only one person in each team (individual assignments). This results in a lot of redundant data.&lt;br /&gt;
Currently, when a team member wants to see all the submitted hyperlinks of his team, Expertiza needs to load all the submitted hyperlinks from each participant in this team and merge them all before display. When a team member wants to remove one hyperlink, Expertiza needs to loop over all the participants, which makes the code complicated and results in unnecessary computations.&lt;br /&gt;
Another aspect of this project requires moving the field '''directory_num''' from the '''participants''' table to the '''teams''' table. The '''directory_num''' field signifies the sub-directory which stores all the files submitted by this team. Intuitively it is clear that each team should ideally have only one common copy of '''directory_num'''. In the current design, since this field is in the '''participants''' table, we are forced to guarantee that all the team members have the same '''directory_num''', which results in redundant code.&lt;br /&gt;
&lt;br /&gt;
= Scope =&lt;br /&gt;
This project can be divided into four major work items:&lt;br /&gt;
#Moving the '''hyperlinks''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''directory_num''' field from the '''participants''' table to the '''teams''' table. After this change, relevant changes are needed in the code to support this database change.&lt;br /&gt;
#Moving the '''set_student_directory_num''' method from the '''participants_controller''' to the '''teams_controller'''. It just needs to check '''directory_num''' from the '''team''' table.&lt;br /&gt;
#Write test cases to verify student-submitted hyperlinks and files.&lt;br /&gt;
&lt;br /&gt;
= Implementation =&lt;br /&gt;
Expertiza files that will be modified for each work item along with the description:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 50px;&amp;quot; | Work Item #&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 225px;&amp;quot; | Files to be modified&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 500px;&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| 1 || assignment_participant.rb&amp;lt;br&amp;gt;assignment_team.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Create a new column hyperlinks in teams table&amp;lt;br&amp;gt;- Write db migration, move all the participants’ submitted hyperlinks from participants table into teams table. All duplicated hyperlinks have to be removed.&amp;lt;br&amp;gt;- Write db migration, remove the hyperlinks field from participants table.&amp;lt;br&amp;gt;- hyperlink-related methods in both assignment_participant.rb and assignment_team.rb have to be rewritten to make sure the new code works with the new db design.&lt;br /&gt;
|-&lt;br /&gt;
| 2 || participants_controller.rb&amp;lt;br&amp;gt;teams_controller.rb&amp;lt;br&amp;gt;db:participants table&amp;lt;br&amp;gt;db:teams table || - Write db migration, move the directory_num field (also the content) to teams table.&amp;lt;br&amp;gt;- Move the set_student_directory_num from participant_controller to team_controller, then refactor this method into smaller methods.&amp;lt;br&amp;gt;- This method no longer needs to test all the participants and see if any of them have directory_num, instead, it just check the directory_num from teams table.&amp;lt;br&amp;gt;- Make change to the submitted-file-related code to make sure it works with the new design.&lt;br /&gt;
|-&lt;br /&gt;
| 3 || New files to be added || - Write test cases to test student-submitted hyperlinks and files.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Design =&lt;br /&gt;
Consider a simple use case where we need to retrieve the submitted hyperlinks and files corresponding to team_id, say, 23841. Since there is no existing correlation between teams and submitted content, we will first need to look up the participants in the team using the teams_users table. And then, using those user_id values one at a time, we need to look up the participants table.&lt;br /&gt;
[[File:db.jpg]]&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Db.jpg&amp;diff=99054</id>
		<title>File:Db.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Db.jpg&amp;diff=99054"/>
		<updated>2015-11-09T05:23:21Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99044</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99044"/>
		<updated>2015-11-09T04:16:16Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction to Expertiza =&lt;br /&gt;
Expertiza is a project developed using Ruby on Rails platform. 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;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99041</id>
		<title>CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015_E1576_Refactoring_submitted_content_(hyperlinks_and_files)&amp;diff=99041"/>
		<updated>2015-11-09T04:13:39Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: Created page with &amp;quot;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1576: Refactoring submitted content (hyperlinks and files)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;font size=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;b&amp;gt;E1576: Refactoring submitted content (hyperlinks and files)&amp;lt;/b&amp;gt;&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98268</id>
		<title>CSC/ECE 517 Fall 2015</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015&amp;diff=98268"/>
		<updated>2015-11-06T05:39:17Z</updated>

		<summary type="html">&lt;p&gt;Ggpalank: /* Final Project Design Document */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Writing Assignment 2==&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1558BGJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1502/AAAASS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss/M1503/IntegrateXMLParser]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1568BZHXJS]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/ossE1572VGA]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2015/oss_E1573_sap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1559 rrz]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1570 avr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1556 CHM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1504 JJD]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1562 APS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1501 GSN]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1550 KMM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1551 RGS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1555 GMR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1552 NFR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1565 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1561 WZL]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1553 AAJ]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1554 AAR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1569 JNR]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1560 PSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss M1505 MSV]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1557 GXM]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1566 ARB]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1567 APT]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/oss E1574 BKS]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015/ossA1550RAN]]&lt;br /&gt;
&lt;br /&gt;
==Final Project Design Document==&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1577 MayYellowRoverJump]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1586 AnonymousChatBetweenAuthorAndReviewer]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1582 Create integration tests for the instructor interface using capybara and rspec]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2015 E1576 Refactoring submitted content (hyperlinks and files)]]&lt;/div&gt;</summary>
		<author><name>Ggpalank</name></author>
	</entry>
</feed>