<?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=Nmaruva</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=Nmaruva"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Nmaruva"/>
	<updated>2026-06-30T19:09:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165264</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165264"/>
		<updated>2025-04-27T01:38:45Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|-&lt;br /&gt;
| select_metareviewer || POST || /review_mappings/:id/select_metareviewer || Assigns a specific metareviewer to a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
| add_metareviewer || POST || /review_mappings/:id/add_metareviewer || Randomly assigns a metareviewer using helper logic&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || Assigns a metareviewer dynamically from eligible participants.&lt;br /&gt;
|-&lt;br /&gt;
| delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id || Removes all metareview mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||Deletes all unsubmitted review mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||  Deletes a specific reviewer mapping by ID.&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareviewer || DELETE || /review_mappings/delete_metareviewer/:id || Deletes a metareviewer assignment from a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareview || DELETE || /review_mappings/:id/delete_metareview || Removes a specific metareview associated with a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
|unsubmit_review || DELETE || /review_mappings/:id/unsubmit_review || Marks a submitted review as unsubmitted or retracts the review submission.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
====1. list_mappings====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
====2. automatic_review_mapping====&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
====3. automatic_review_mapping_strategy====&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
====4. automatic_review_mapping_staggered====&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
====5. assign_reviewers_for_team====&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
====6. peer_review_strategy====&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
====7. save_grade_and_comment_for_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
====8. add_calibration====&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
====9. select_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
====10. add_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
====11. assign_reviewer_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
====12. review_allowed====&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
====13. check_outstanding_reviews====&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
====14. start_self_review====&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
====15. assign_quiz_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
====16. select_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches review mapping and metareviewer using provided IDs.&lt;br /&gt;
&lt;br /&gt;
*Checks if the metareviewer is already assigned to the mapping.&lt;br /&gt;
&lt;br /&gt;
*If not assigned, creates a MetareviewResponseMap linking the metareviewer to the reviewer.&lt;br /&gt;
&lt;br /&gt;
*Returns appropriate JSON messages for success or error conditions.&lt;br /&gt;
&lt;br /&gt;
====17.add_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates the review mapping by ID.&lt;br /&gt;
&lt;br /&gt;
*Delegates the assignment logic to add_metareviewer helper method.&lt;br /&gt;
&lt;br /&gt;
*Helper selects a random eligible metareviewer from the assignment's participants.&lt;br /&gt;
&lt;br /&gt;
*Creates a MetareviewResponseMap entry.&lt;br /&gt;
&lt;br /&gt;
*Returns a success or failure message based on assignment feasibility.&lt;br /&gt;
&lt;br /&gt;
====18. assign_metareviewer_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the ResponseMap and corresponding Assignment.&lt;br /&gt;
&lt;br /&gt;
*Delegates participant selection logic to helper: find_available_metareviewer.&lt;br /&gt;
&lt;br /&gt;
*Creates a new MetareviewResponseMap entry linking selected participant.&lt;br /&gt;
&lt;br /&gt;
*Returns a JSON object indicating the outcome and assigned metareviewer ID.&lt;br /&gt;
&lt;br /&gt;
====19. delete_outstanding_reviewers====&lt;br /&gt;
&lt;br /&gt;
*Controller receives an assignment_id.&lt;br /&gt;
&lt;br /&gt;
*Queries all ReviewResponseMap entries with no associated Response (i.e., pending reviews).&lt;br /&gt;
&lt;br /&gt;
*Deletes all such mappings using delete_all.&lt;br /&gt;
&lt;br /&gt;
*Returns a message indicating how many records were removed.&lt;br /&gt;
&lt;br /&gt;
====20. delete_all_metareviewers====&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the assignment and retrieves all related participant IDs.&lt;br /&gt;
&lt;br /&gt;
*Deletes all MetareviewResponseMap entries whose reviewee_id matches any participant in the assignment.&lt;br /&gt;
&lt;br /&gt;
*Responds with a JSON count of the deleted metareviewer mappings.&lt;br /&gt;
&lt;br /&gt;
====21. delete_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates a ResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the record.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
====22.delete_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates a MetareviewResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the metareviewer mapping.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
====23.delete_metareview====&lt;br /&gt;
&lt;br /&gt;
*Controller finds a MetareviewResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Deletes the record if it exists.&lt;br /&gt;
&lt;br /&gt;
====24.unsubmit_review====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches the ResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Checks for an associated Response object.&lt;br /&gt;
&lt;br /&gt;
*Sets submitted_at to nil if present to unsubmit.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Examples ===&lt;br /&gt;
Here are a few representative code snippets of POST,GET,DELETE function types implemented:&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
This function dynamically assigns an available metareviewer to a given review mapping. It finds the appropriate assignment and review mapping, selects an eligible metareviewer, and creates a new metareview mapping, returning an error if any step fails.&lt;br /&gt;
&lt;br /&gt;
  # POST /api/v1/review_mappings/:id/assign_metareviewer_dynamically&lt;br /&gt;
  def assign_metareviewer_dynamically&lt;br /&gt;
    review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
    return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
    assignment = Assignment.find_by(id: review_mapping.reviewed_object_id)&lt;br /&gt;
    return render json: { error: 'Assignment not found' }, status: :not_found unless assignment&lt;br /&gt;
    metareviewer = ReviewMappingsHelper.find_available_metareviewer(assignment, review_mapping)&lt;br /&gt;
    return render json: { error: 'No available metareviewer found' }, status: :unprocessable_entity unless metareviewer&lt;br /&gt;
    MetareviewResponseMap.create!(&lt;br /&gt;
     reviewed_object_id: review_mapping.id,&lt;br /&gt;
     reviewer_id: metareviewer.id,&lt;br /&gt;
     reviewee_id: review_mapping.reviewer_id&lt;br /&gt;
    )&lt;br /&gt;
    render json: {&lt;br /&gt;
      message: 'Metareviewer dynamically assigned successfully',&lt;br /&gt;
      metareviewer_id: metareviewer.id&lt;br /&gt;
    }, status: :ok&lt;br /&gt;
    rescue ActiveRecord::RecordInvalid =&amp;gt; e&lt;br /&gt;
    render json: { error: e.message }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
This function deletes a specific review mapping (reviewer assignment) based on the provided ID, removing the reviewer from the review process and returning a success or error message.&lt;br /&gt;
&lt;br /&gt;
    # DELETE /api/v1/review_mappings/:id/delete_reviewer&lt;br /&gt;
    def delete_reviewer&lt;br /&gt;
      review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
      return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
      review_mapping.destroy&lt;br /&gt;
      render json: { message: 'Reviewer mapping deleted successfully' }, status: :ok&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
====select_reviewer====&lt;br /&gt;
This function selects a contributor (team) for review mapping, stores the selected contributor in the session for tracking during the review assignment process, and returns the contributor's information or an error if not found.&lt;br /&gt;
&lt;br /&gt;
    # GET /api/v1/review_mappings/select_reviewer&lt;br /&gt;
    # Selects a contributor for review mapping and stores it in the session&lt;br /&gt;
    # This is used in the review assignment process to track the selected contributor&lt;br /&gt;
   def select_reviewer&lt;br /&gt;
     @contributor = Team.find(params[:contributor_id])&lt;br /&gt;
     session[:contributor] = @contributor&lt;br /&gt;
     render json: @contributor, status: :ok&lt;br /&gt;
     rescue ActiveRecord::RecordNotFound&lt;br /&gt;
       render json: { error: &amp;quot;Contributor not found&amp;quot; }, status: :not_found&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer already assigned&lt;br /&gt;
&lt;br /&gt;
*201 Created: Metareviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or metareviewer not found&lt;br /&gt;
&lt;br /&gt;
17. add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Random eligible metareviewer assigned&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No available metareviewers found&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, metareviewer assigned successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or assignment not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No valid metareviewers available&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: Pending reviewer mappings deleted&lt;br /&gt;
&lt;br /&gt;
*200 OK: No outstanding mappings to delete (0 removed)&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: All metareviewer mappings deleted successfully&lt;br /&gt;
&lt;br /&gt;
*200 OK: No metareviewer mappings to delete&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping does not exist&lt;br /&gt;
&lt;br /&gt;
22. delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
23. delete_metareview&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareview mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
24. unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*200 OK: Review unsubmitted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or response not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: Failed to update the response&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [https://youtu.be/uAQBWx0Mjyg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165263</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165263"/>
		<updated>2025-04-27T01:35:00Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|-&lt;br /&gt;
| select_metareviewer || POST || /review_mappings/:id/select_metareviewer || Assigns a specific metareviewer to a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
| add_metareviewer || POST || /review_mappings/:id/add_metareviewer || Randomly assigns a metareviewer using helper logic&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || Assigns a metareviewer dynamically from eligible participants.&lt;br /&gt;
|-&lt;br /&gt;
| delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id || Removes all metareview mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||Deletes all unsubmitted review mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||  Deletes a specific reviewer mapping by ID.&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareviewer || DELETE || /review_mappings/delete_metareviewer/:id ||&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareview || DELETE || /review_mappings/:id/delete_metareview ||&lt;br /&gt;
|-&lt;br /&gt;
|unsubmit_review || DELETE || /review_mappings/:id/unsubmit_review || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
====1. list_mappings====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
====2. automatic_review_mapping====&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
====3. automatic_review_mapping_strategy====&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
====4. automatic_review_mapping_staggered====&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
====5. assign_reviewers_for_team====&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
====6. peer_review_strategy====&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
====7. save_grade_and_comment_for_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
====8. add_calibration====&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
====9. select_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
====10. add_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
====11. assign_reviewer_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
====12. review_allowed====&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
====13. check_outstanding_reviews====&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
====14. start_self_review====&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
====15. assign_quiz_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
====16. select_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches review mapping and metareviewer using provided IDs.&lt;br /&gt;
&lt;br /&gt;
*Checks if the metareviewer is already assigned to the mapping.&lt;br /&gt;
&lt;br /&gt;
*If not assigned, creates a MetareviewResponseMap linking the metareviewer to the reviewer.&lt;br /&gt;
&lt;br /&gt;
*Returns appropriate JSON messages for success or error conditions.&lt;br /&gt;
&lt;br /&gt;
====17.add_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates the review mapping by ID.&lt;br /&gt;
&lt;br /&gt;
*Delegates the assignment logic to add_metareviewer helper method.&lt;br /&gt;
&lt;br /&gt;
*Helper selects a random eligible metareviewer from the assignment's participants.&lt;br /&gt;
&lt;br /&gt;
*Creates a MetareviewResponseMap entry.&lt;br /&gt;
&lt;br /&gt;
*Returns a success or failure message based on assignment feasibility.&lt;br /&gt;
&lt;br /&gt;
====18. assign_metareviewer_dynamically====&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the ResponseMap and corresponding Assignment.&lt;br /&gt;
&lt;br /&gt;
*Delegates participant selection logic to helper: find_available_metareviewer.&lt;br /&gt;
&lt;br /&gt;
*Creates a new MetareviewResponseMap entry linking selected participant.&lt;br /&gt;
&lt;br /&gt;
*Returns a JSON object indicating the outcome and assigned metareviewer ID.&lt;br /&gt;
&lt;br /&gt;
====19. delete_outstanding_reviewers====&lt;br /&gt;
&lt;br /&gt;
*Controller receives an assignment_id.&lt;br /&gt;
&lt;br /&gt;
*Queries all ReviewResponseMap entries with no associated Response (i.e., pending reviews).&lt;br /&gt;
&lt;br /&gt;
*Deletes all such mappings using delete_all.&lt;br /&gt;
&lt;br /&gt;
*Returns a message indicating how many records were removed.&lt;br /&gt;
&lt;br /&gt;
====20. delete_all_metareviewers====&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the assignment and retrieves all related participant IDs.&lt;br /&gt;
&lt;br /&gt;
*Deletes all MetareviewResponseMap entries whose reviewee_id matches any participant in the assignment.&lt;br /&gt;
&lt;br /&gt;
*Responds with a JSON count of the deleted metareviewer mappings.&lt;br /&gt;
&lt;br /&gt;
====21. delete_reviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates a ResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the record.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
====22.delete_metareviewer====&lt;br /&gt;
&lt;br /&gt;
*Controller locates a MetareviewResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the metareviewer mapping.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
====23.delete_metareview====&lt;br /&gt;
&lt;br /&gt;
*Controller finds a MetareviewResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Deletes the record if it exists.&lt;br /&gt;
&lt;br /&gt;
====24.unsubmit_review====&lt;br /&gt;
&lt;br /&gt;
*Controller fetches the ResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Checks for an associated Response object.&lt;br /&gt;
&lt;br /&gt;
*Sets submitted_at to nil if present to unsubmit.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Examples ===&lt;br /&gt;
Here are a few representative code snippets of POST,GET,DELETE function types implemented:&lt;br /&gt;
&lt;br /&gt;
  # POST /api/v1/review_mappings/:id/assign_metareviewer_dynamically&lt;br /&gt;
  def assign_metareviewer_dynamically&lt;br /&gt;
    review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
    return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
    assignment = Assignment.find_by(id: review_mapping.reviewed_object_id)&lt;br /&gt;
    return render json: { error: 'Assignment not found' }, status: :not_found unless assignment&lt;br /&gt;
    metareviewer = ReviewMappingsHelper.find_available_metareviewer(assignment, review_mapping)&lt;br /&gt;
    return render json: { error: 'No available metareviewer found' }, status: :unprocessable_entity unless metareviewer&lt;br /&gt;
    MetareviewResponseMap.create!(&lt;br /&gt;
     reviewed_object_id: review_mapping.id,&lt;br /&gt;
     reviewer_id: metareviewer.id,&lt;br /&gt;
     reviewee_id: review_mapping.reviewer_id&lt;br /&gt;
    )&lt;br /&gt;
    render json: {&lt;br /&gt;
      message: 'Metareviewer dynamically assigned successfully',&lt;br /&gt;
      metareviewer_id: metareviewer.id&lt;br /&gt;
    }, status: :ok&lt;br /&gt;
    rescue ActiveRecord::RecordInvalid =&amp;gt; e&lt;br /&gt;
    render json: { error: e.message }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
    # DELETE /api/v1/review_mappings/:id/delete_reviewer&lt;br /&gt;
    def delete_reviewer&lt;br /&gt;
      review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
      return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
      review_mapping.destroy&lt;br /&gt;
      render json: { message: 'Reviewer mapping deleted successfully' }, status: :ok&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # GET /api/v1/review_mappings/select_reviewer&lt;br /&gt;
    # Selects a contributor for review mapping and stores it in the session&lt;br /&gt;
    # This is used in the review assignment process to track the selected contributor&lt;br /&gt;
   def select_reviewer&lt;br /&gt;
     @contributor = Team.find(params[:contributor_id])&lt;br /&gt;
     session[:contributor] = @contributor&lt;br /&gt;
     render json: @contributor, status: :ok&lt;br /&gt;
     rescue ActiveRecord::RecordNotFound&lt;br /&gt;
       render json: { error: &amp;quot;Contributor not found&amp;quot; }, status: :not_found&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer already assigned&lt;br /&gt;
&lt;br /&gt;
*201 Created: Metareviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or metareviewer not found&lt;br /&gt;
&lt;br /&gt;
17. add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Random eligible metareviewer assigned&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No available metareviewers found&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, metareviewer assigned successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or assignment not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No valid metareviewers available&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: Pending reviewer mappings deleted&lt;br /&gt;
&lt;br /&gt;
*200 OK: No outstanding mappings to delete (0 removed)&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: All metareviewer mappings deleted successfully&lt;br /&gt;
&lt;br /&gt;
*200 OK: No metareviewer mappings to delete&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping does not exist&lt;br /&gt;
&lt;br /&gt;
22. delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
23. delete_metareview&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareview mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
24. unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*200 OK: Review unsubmitted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or response not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: Failed to update the response&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [https://youtu.be/uAQBWx0Mjyg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165157</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=165157"/>
		<updated>2025-04-23T03:50:58Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|-&lt;br /&gt;
| select_metareviewer || POST || /review_mappings/:id/select_metareviewer || Assigns a specific metareviewer to a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
| add_metareviewer || POST || /review_mappings/:id/add_metareviewer || Randomly assigns a metareviewer using helper logic&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || Assigns a metareviewer dynamically from eligible participants.&lt;br /&gt;
|-&lt;br /&gt;
| delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id || Removes all metareview mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||Deletes all unsubmitted review mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||  Deletes a specific reviewer mapping by ID.&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareviewer || DELETE || /review_mappings/delete_metareviewer/:id ||&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareview || DELETE || /review_mappings/:id/delete_metareview ||&lt;br /&gt;
|-&lt;br /&gt;
|unsubmit_review || DELETE || /review_mappings/:id/unsubmit_review || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller fetches review mapping and metareviewer using provided IDs.&lt;br /&gt;
&lt;br /&gt;
*Checks if the metareviewer is already assigned to the mapping.&lt;br /&gt;
&lt;br /&gt;
*If not assigned, creates a MetareviewResponseMap linking the metareviewer to the reviewer.&lt;br /&gt;
&lt;br /&gt;
*Returns appropriate JSON messages for success or error conditions.&lt;br /&gt;
&lt;br /&gt;
17.add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates the review mapping by ID.&lt;br /&gt;
&lt;br /&gt;
*Delegates the assignment logic to add_metareviewer helper method.&lt;br /&gt;
&lt;br /&gt;
*Helper selects a random eligible metareviewer from the assignment's participants.&lt;br /&gt;
&lt;br /&gt;
*Creates a MetareviewResponseMap entry.&lt;br /&gt;
&lt;br /&gt;
*Returns a success or failure message based on assignment feasibility.&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the ResponseMap and corresponding Assignment.&lt;br /&gt;
&lt;br /&gt;
*Delegates participant selection logic to helper: find_available_metareviewer.&lt;br /&gt;
&lt;br /&gt;
*Creates a new MetareviewResponseMap entry linking selected participant.&lt;br /&gt;
&lt;br /&gt;
*Returns a JSON object indicating the outcome and assigned metareviewer ID.&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*Controller receives an assignment_id.&lt;br /&gt;
&lt;br /&gt;
*Queries all ReviewResponseMap entries with no associated Response (i.e., pending reviews).&lt;br /&gt;
&lt;br /&gt;
*Deletes all such mappings using delete_all.&lt;br /&gt;
&lt;br /&gt;
*Returns a message indicating how many records were removed.&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the assignment and retrieves all related participant IDs.&lt;br /&gt;
&lt;br /&gt;
*Deletes all MetareviewResponseMap entries whose reviewee_id matches any participant in the assignment.&lt;br /&gt;
&lt;br /&gt;
*Responds with a JSON count of the deleted metareviewer mappings.&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates a ResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the record.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
22.delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates a MetareviewResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the metareviewer mapping.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
23.delete_metareview&lt;br /&gt;
&lt;br /&gt;
*Controller finds a MetareviewResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Deletes the record if it exists.&lt;br /&gt;
&lt;br /&gt;
24.unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*Controller fetches the ResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Checks for an associated Response object.&lt;br /&gt;
&lt;br /&gt;
*Sets submitted_at to nil if present to unsubmit.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Examples ===&lt;br /&gt;
Here are a few representative code snippets of POST,GET,DELETE function types implemented:&lt;br /&gt;
&lt;br /&gt;
  # POST /api/v1/review_mappings/:id/assign_metareviewer_dynamically&lt;br /&gt;
  def assign_metareviewer_dynamically&lt;br /&gt;
    review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
    return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
    assignment = Assignment.find_by(id: review_mapping.reviewed_object_id)&lt;br /&gt;
    return render json: { error: 'Assignment not found' }, status: :not_found unless assignment&lt;br /&gt;
    metareviewer = ReviewMappingsHelper.find_available_metareviewer(assignment, review_mapping)&lt;br /&gt;
    return render json: { error: 'No available metareviewer found' }, status: :unprocessable_entity unless metareviewer&lt;br /&gt;
    MetareviewResponseMap.create!(&lt;br /&gt;
     reviewed_object_id: review_mapping.id,&lt;br /&gt;
     reviewer_id: metareviewer.id,&lt;br /&gt;
     reviewee_id: review_mapping.reviewer_id&lt;br /&gt;
    )&lt;br /&gt;
    render json: {&lt;br /&gt;
      message: 'Metareviewer dynamically assigned successfully',&lt;br /&gt;
      metareviewer_id: metareviewer.id&lt;br /&gt;
    }, status: :ok&lt;br /&gt;
    rescue ActiveRecord::RecordInvalid =&amp;gt; e&lt;br /&gt;
    render json: { error: e.message }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
    # DELETE /api/v1/review_mappings/:id/delete_reviewer&lt;br /&gt;
    def delete_reviewer&lt;br /&gt;
      review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
      return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
      review_mapping.destroy&lt;br /&gt;
      render json: { message: 'Reviewer mapping deleted successfully' }, status: :ok&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # GET /api/v1/review_mappings/select_reviewer&lt;br /&gt;
    # Selects a contributor for review mapping and stores it in the session&lt;br /&gt;
    # This is used in the review assignment process to track the selected contributor&lt;br /&gt;
   def select_reviewer&lt;br /&gt;
     @contributor = Team.find(params[:contributor_id])&lt;br /&gt;
     session[:contributor] = @contributor&lt;br /&gt;
     render json: @contributor, status: :ok&lt;br /&gt;
     rescue ActiveRecord::RecordNotFound&lt;br /&gt;
       render json: { error: &amp;quot;Contributor not found&amp;quot; }, status: :not_found&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer already assigned&lt;br /&gt;
&lt;br /&gt;
*201 Created: Metareviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or metareviewer not found&lt;br /&gt;
&lt;br /&gt;
17. add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Random eligible metareviewer assigned&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No available metareviewers found&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, metareviewer assigned successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or assignment not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No valid metareviewers available&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: Pending reviewer mappings deleted&lt;br /&gt;
&lt;br /&gt;
*200 OK: No outstanding mappings to delete (0 removed)&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: All metareviewer mappings deleted successfully&lt;br /&gt;
&lt;br /&gt;
*200 OK: No metareviewer mappings to delete&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping does not exist&lt;br /&gt;
&lt;br /&gt;
22. delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
23. delete_metareview&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareview mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
24. unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*200 OK: Review unsubmitted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or response not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: Failed to update the response&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [https://youtu.be/uAQBWx0Mjyg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164774</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164774"/>
		<updated>2025-04-22T22:26:05Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|-&lt;br /&gt;
| select_metareviewer || POST || /review_mappings/:id/select_metareviewer || Assigns a specific metareviewer to a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
| add_metareviewer || POST || /review_mappings/:id/add_metareviewer || Randomly assigns a metareviewer using helper logic&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || Assigns a metareviewer dynamically from eligible participants.&lt;br /&gt;
|-&lt;br /&gt;
| delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id || Removes all metareview mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||Deletes all unsubmitted review mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||  Deletes a specific reviewer mapping by ID.&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareviewer || DELETE || /review_mappings/delete_metareviewer/:id ||&lt;br /&gt;
|-&lt;br /&gt;
|delete_metareview || DELETE || /review_mappings/:id/delete_metareview ||&lt;br /&gt;
|-&lt;br /&gt;
|unsubmit_review || DELETE || /review_mappings/:id/unsubmit_review || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller fetches review mapping and metareviewer using provided IDs.&lt;br /&gt;
&lt;br /&gt;
*Checks if the metareviewer is already assigned to the mapping.&lt;br /&gt;
&lt;br /&gt;
*If not assigned, creates a MetareviewResponseMap linking the metareviewer to the reviewer.&lt;br /&gt;
&lt;br /&gt;
*Returns appropriate JSON messages for success or error conditions.&lt;br /&gt;
&lt;br /&gt;
17.add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates the review mapping by ID.&lt;br /&gt;
&lt;br /&gt;
*Delegates the assignment logic to add_metareviewer helper method.&lt;br /&gt;
&lt;br /&gt;
*Helper selects a random eligible metareviewer from the assignment's participants.&lt;br /&gt;
&lt;br /&gt;
*Creates a MetareviewResponseMap entry.&lt;br /&gt;
&lt;br /&gt;
*Returns a success or failure message based on assignment feasibility.&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the ResponseMap and corresponding Assignment.&lt;br /&gt;
&lt;br /&gt;
*Delegates participant selection logic to helper: find_available_metareviewer.&lt;br /&gt;
&lt;br /&gt;
*Creates a new MetareviewResponseMap entry linking selected participant.&lt;br /&gt;
&lt;br /&gt;
*Returns a JSON object indicating the outcome and assigned metareviewer ID.&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*Controller receives an assignment_id.&lt;br /&gt;
&lt;br /&gt;
*Queries all ReviewResponseMap entries with no associated Response (i.e., pending reviews).&lt;br /&gt;
&lt;br /&gt;
*Deletes all such mappings using delete_all.&lt;br /&gt;
&lt;br /&gt;
*Returns a message indicating how many records were removed.&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the assignment and retrieves all related participant IDs.&lt;br /&gt;
&lt;br /&gt;
*Deletes all MetareviewResponseMap entries whose reviewee_id matches any participant in the assignment.&lt;br /&gt;
&lt;br /&gt;
*Responds with a JSON count of the deleted metareviewer mappings.&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates a ResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the record.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
22.delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates a MetareviewResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the metareviewer mapping.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
23.delete_metareview&lt;br /&gt;
&lt;br /&gt;
*Controller finds a MetareviewResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Deletes the record if it exists.&lt;br /&gt;
&lt;br /&gt;
24.unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*Controller fetches the ResponseMap by ID.&lt;br /&gt;
&lt;br /&gt;
*Checks for an associated Response object.&lt;br /&gt;
&lt;br /&gt;
*Sets submitted_at to nil if present to unsubmit.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Examples ===&lt;br /&gt;
Here are a few representative code snippets of POST,GET,DELETE function types implemented:&lt;br /&gt;
&lt;br /&gt;
  # POST /api/v1/review_mappings/:id/assign_metareviewer_dynamically&lt;br /&gt;
  def assign_metareviewer_dynamically&lt;br /&gt;
    review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
    return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
    assignment = Assignment.find_by(id: review_mapping.reviewed_object_id)&lt;br /&gt;
    return render json: { error: 'Assignment not found' }, status: :not_found unless assignment&lt;br /&gt;
    metareviewer = ReviewMappingsHelper.find_available_metareviewer(assignment, review_mapping)&lt;br /&gt;
    return render json: { error: 'No available metareviewer found' }, status: :unprocessable_entity unless metareviewer&lt;br /&gt;
    MetareviewResponseMap.create!(&lt;br /&gt;
     reviewed_object_id: review_mapping.id,&lt;br /&gt;
     reviewer_id: metareviewer.id,&lt;br /&gt;
     reviewee_id: review_mapping.reviewer_id&lt;br /&gt;
    )&lt;br /&gt;
    render json: {&lt;br /&gt;
      message: 'Metareviewer dynamically assigned successfully',&lt;br /&gt;
      metareviewer_id: metareviewer.id&lt;br /&gt;
    }, status: :ok&lt;br /&gt;
    rescue ActiveRecord::RecordInvalid =&amp;gt; e&lt;br /&gt;
    render json: { error: e.message }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
    # DELETE /api/v1/review_mappings/:id/delete_reviewer&lt;br /&gt;
    def delete_reviewer&lt;br /&gt;
      review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
      return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
      review_mapping.destroy&lt;br /&gt;
      render json: { message: 'Reviewer mapping deleted successfully' }, status: :ok&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # GET /api/v1/review_mappings/select_reviewer&lt;br /&gt;
    # Selects a contributor for review mapping and stores it in the session&lt;br /&gt;
    # This is used in the review assignment process to track the selected contributor&lt;br /&gt;
   def select_reviewer&lt;br /&gt;
     @contributor = Team.find(params[:contributor_id])&lt;br /&gt;
     session[:contributor] = @contributor&lt;br /&gt;
     render json: @contributor, status: :ok&lt;br /&gt;
     rescue ActiveRecord::RecordNotFound&lt;br /&gt;
       render json: { error: &amp;quot;Contributor not found&amp;quot; }, status: :not_found&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer already assigned&lt;br /&gt;
&lt;br /&gt;
*201 Created: Metareviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or metareviewer not found&lt;br /&gt;
&lt;br /&gt;
17. add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Random eligible metareviewer assigned&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No available metareviewers found&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, metareviewer assigned successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or assignment not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No valid metareviewers available&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: Pending reviewer mappings deleted&lt;br /&gt;
&lt;br /&gt;
*200 OK: No outstanding mappings to delete (0 removed)&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: All metareviewer mappings deleted successfully&lt;br /&gt;
&lt;br /&gt;
*200 OK: No metareviewer mappings to delete&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping does not exist&lt;br /&gt;
&lt;br /&gt;
22. delete_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
23. delete_metareview&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareview mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Metareview mapping not found&lt;br /&gt;
&lt;br /&gt;
24. unsubmit_review&lt;br /&gt;
&lt;br /&gt;
*200 OK: Review unsubmitted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or response not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: Failed to update the response&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164744</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164744"/>
		<updated>2025-04-22T21:38:14Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|-&lt;br /&gt;
| select_metareviewer || POST || /review_mappings/:id/select_metareviewer || Assigns a specific metareviewer to a review mapping.&lt;br /&gt;
|-&lt;br /&gt;
| add_metareviewer || POST || /review_mappings/:id/add_metareviewer || Randomly assigns a metareviewer using helper logic&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || Assigns a metareviewer dynamically from eligible participants.&lt;br /&gt;
|-&lt;br /&gt;
| delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id || Removes all metareview mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||Deletes all unsubmitted review mappings for a given assignment.&lt;br /&gt;
|-&lt;br /&gt;
| delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||  Deletes a specific reviewer mapping by ID.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller fetches review mapping and metareviewer using provided IDs.&lt;br /&gt;
&lt;br /&gt;
*Checks if the metareviewer is already assigned to the mapping.&lt;br /&gt;
&lt;br /&gt;
*If not assigned, creates a MetareviewResponseMap linking the metareviewer to the reviewer.&lt;br /&gt;
&lt;br /&gt;
*Returns appropriate JSON messages for success or error conditions.&lt;br /&gt;
&lt;br /&gt;
17.add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates the review mapping by ID.&lt;br /&gt;
&lt;br /&gt;
*Delegates the assignment logic to add_metareviewer helper method.&lt;br /&gt;
&lt;br /&gt;
*Helper selects a random eligible metareviewer from the assignment's participants.&lt;br /&gt;
&lt;br /&gt;
*Creates a MetareviewResponseMap entry.&lt;br /&gt;
&lt;br /&gt;
*Returns a success or failure message based on assignment feasibility.&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the ResponseMap and corresponding Assignment.&lt;br /&gt;
&lt;br /&gt;
*Delegates participant selection logic to helper: find_available_metareviewer.&lt;br /&gt;
&lt;br /&gt;
*Creates a new MetareviewResponseMap entry linking selected participant.&lt;br /&gt;
&lt;br /&gt;
*Returns a JSON object indicating the outcome and assigned metareviewer ID.&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*Controller receives an assignment_id.&lt;br /&gt;
&lt;br /&gt;
*Queries all ReviewResponseMap entries with no associated Response (i.e., pending reviews).&lt;br /&gt;
&lt;br /&gt;
*Deletes all such mappings using delete_all.&lt;br /&gt;
&lt;br /&gt;
*Returns a message indicating how many records were removed.&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*Controller identifies the assignment and retrieves all related participant IDs.&lt;br /&gt;
&lt;br /&gt;
*Deletes all MetareviewResponseMap entries whose reviewee_id matches any participant in the assignment.&lt;br /&gt;
&lt;br /&gt;
*Responds with a JSON count of the deleted metareviewer mappings.&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*Controller locates a ResponseMap by its ID.&lt;br /&gt;
&lt;br /&gt;
*If found, deletes the record.&lt;br /&gt;
&lt;br /&gt;
*Returns a success message or a 404 if the mapping is not found.&lt;br /&gt;
&lt;br /&gt;
=== Implementation Examples ===&lt;br /&gt;
Here are a few representative code snippets of POST,GET,DELETE function types implemented:&lt;br /&gt;
&lt;br /&gt;
  # POST /api/v1/review_mappings/:id/assign_metareviewer_dynamically&lt;br /&gt;
  def assign_metareviewer_dynamically&lt;br /&gt;
    review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
    return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
    assignment = Assignment.find_by(id: review_mapping.reviewed_object_id)&lt;br /&gt;
    return render json: { error: 'Assignment not found' }, status: :not_found unless assignment&lt;br /&gt;
    metareviewer = ReviewMappingsHelper.find_available_metareviewer(assignment, review_mapping)&lt;br /&gt;
    return render json: { error: 'No available metareviewer found' }, status: :unprocessable_entity unless metareviewer&lt;br /&gt;
    MetareviewResponseMap.create!(&lt;br /&gt;
     reviewed_object_id: review_mapping.id,&lt;br /&gt;
     reviewer_id: metareviewer.id,&lt;br /&gt;
     reviewee_id: review_mapping.reviewer_id&lt;br /&gt;
    )&lt;br /&gt;
    render json: {&lt;br /&gt;
      message: 'Metareviewer dynamically assigned successfully',&lt;br /&gt;
      metareviewer_id: metareviewer.id&lt;br /&gt;
    }, status: :ok&lt;br /&gt;
    rescue ActiveRecord::RecordInvalid =&amp;gt; e&lt;br /&gt;
    render json: { error: e.message }, status: :unprocessable_entity&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
    # DELETE /api/v1/review_mappings/:id/delete_reviewer&lt;br /&gt;
    def delete_reviewer&lt;br /&gt;
      review_mapping = ResponseMap.find_by(id: params[:id])&lt;br /&gt;
      return render json: { error: 'Review mapping not found' }, status: :not_found unless review_mapping&lt;br /&gt;
      review_mapping.destroy&lt;br /&gt;
      render json: { message: 'Reviewer mapping deleted successfully' }, status: :ok&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # GET /api/v1/review_mappings/select_reviewer&lt;br /&gt;
    # Selects a contributor for review mapping and stores it in the session&lt;br /&gt;
    # This is used in the review assignment process to track the selected contributor&lt;br /&gt;
   def select_reviewer&lt;br /&gt;
     @contributor = Team.find(params[:contributor_id])&lt;br /&gt;
     session[:contributor] = @contributor&lt;br /&gt;
     render json: @contributor, status: :ok&lt;br /&gt;
     rescue ActiveRecord::RecordNotFound&lt;br /&gt;
       render json: { error: &amp;quot;Contributor not found&amp;quot; }, status: :not_found&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
16. select_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Metareviewer already assigned&lt;br /&gt;
&lt;br /&gt;
*201 Created: Metareviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or metareviewer not found&lt;br /&gt;
&lt;br /&gt;
17. add_metareviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Random eligible metareviewer assigned&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No available metareviewers found&lt;br /&gt;
&lt;br /&gt;
18. assign_metareviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, metareviewer assigned successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping or assignment not found&lt;br /&gt;
&lt;br /&gt;
*422 Unprocessable Entity: No valid metareviewers available&lt;br /&gt;
&lt;br /&gt;
19. delete_outstanding_reviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: Pending reviewer mappings deleted&lt;br /&gt;
&lt;br /&gt;
*200 OK: No outstanding mappings to delete (0 removed)&lt;br /&gt;
&lt;br /&gt;
20. delete_all_metareviewers&lt;br /&gt;
&lt;br /&gt;
*200 OK: All metareviewer mappings deleted successfully&lt;br /&gt;
&lt;br /&gt;
*200 OK: No metareviewer mappings to delete&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
21. delete_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer mapping deleted successfully&lt;br /&gt;
&lt;br /&gt;
*404 Not Found: Review mapping does not exist&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164740</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164740"/>
		<updated>2025-04-22T21:10:44Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|&lt;br /&gt;
|-select_metareviewer || POST || /review_mappings/:id/select_metareviewer ||&lt;br /&gt;
|&lt;br /&gt;
|-add_metareviewer || POST || /review_mappings/:id/add_metareviewer || &lt;br /&gt;
|&lt;br /&gt;
|-assign_metareviewer_dynamically || POST || /review_mappings/:id/assign_metareviewer_dynamically || &lt;br /&gt;
|&lt;br /&gt;
|-delete_all_metareviewers || DELETE  || /review_mappings/delete_all_metareviewers/:assignment_id ||&lt;br /&gt;
|&lt;br /&gt;
|-delete_outstanding_reviewers || DELETE || /review_mappings/delete_outstanding_reviewers/{assignment_id} ||&lt;br /&gt;
|&lt;br /&gt;
|-delete_reviewer || DELETE || /review_mappings/:id/delete_reviewer ||&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164612</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164612"/>
		<updated>2025-04-22T15:43:14Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
=== Sample Testing Block (Swagger UI) ===&lt;br /&gt;
&lt;br /&gt;
All endpoints were tested using Swagger UI to ensure correctness. Below is an example test for the save_grade_and_comment endpoint: &lt;br /&gt;
&lt;br /&gt;
Test Case: Save Grade and Comment&lt;br /&gt;
&lt;br /&gt;
Request URL: &lt;br /&gt;
   POST /api/v1/review_mappings/save_grade_and_comment&lt;br /&gt;
Request Headers:&lt;br /&gt;
   Authorization: Bearer &amp;lt;your_token_here&amp;gt;&lt;br /&gt;
   Content-Type: application/json&lt;br /&gt;
Request Body:&lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;participant_id&amp;quot;: 3,&lt;br /&gt;
  &amp;quot;assignment_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;reviewee_id&amp;quot;: 1,&lt;br /&gt;
  &amp;quot;grade&amp;quot;: 9.5,&lt;br /&gt;
  &amp;quot;comment&amp;quot;: &amp;quot;Very thoughtful and constructive feedback!&amp;quot;,&lt;br /&gt;
  &amp;quot;answers&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 1,&lt;br /&gt;
      &amp;quot;score&amp;quot;: 9,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Strong analysis and good structure.&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;item_id&amp;quot;: 2,&lt;br /&gt;
      &amp;quot;comment&amp;quot;: &amp;quot;Keep up the good work!&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ],&lt;br /&gt;
  &amp;quot;is_submitted&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
Response:&lt;br /&gt;
You should get a 200 OK with:&lt;br /&gt;
  &lt;br /&gt;
  {&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Grade and comment saved successfully.&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
If anything goes wrong, you'll get a helpful 422 error like:&lt;br /&gt;
&lt;br /&gt;
  &amp;quot;Reviewee not part of assignment&amp;quot;&lt;br /&gt;
  &amp;quot;Invalid item ID&amp;quot;&lt;br /&gt;
  &amp;quot;Score must be between X and Y&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164445</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164445"/>
		<updated>2025-04-22T01:11:47Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The review mapping-related endpoints were implemented using a consistent architectural approach that embraces Rails best practices. Each feature follows a thin-controller, rich-helper paradigm to ensure separation of concerns, where controller actions handle routing and validation while helper methods encapsulate the business logic. All endpoints are protected by JWT-based authentication, and routes are designed to be RESTful and easy to integrate. The implementation includes careful handling of STI (Single Table Inheritance) for models like ResponseMap and its subclasses such as TeamReviewResponseMap. All input parameters are validated to return appropriate error messages with standardized status codes like 404 for not found, 400/422 for invalid inputs, and 200 for success. In parallel, full Swagger documentation has been maintained to support testability and discoverability. The seed file was also enhanced to ensure that all entities like assignments, teams, participants, and questionnaire items are in place for robust testing of each endpoint.&lt;br /&gt;
===Function-wise Implementation Details===&lt;br /&gt;
&lt;br /&gt;
1. list_mappings&lt;br /&gt;
&lt;br /&gt;
*Controller fetches assignment and extracts query filters.&lt;br /&gt;
&lt;br /&gt;
*Delegates filter logic to fetch_review_mappings helper.&lt;br /&gt;
&lt;br /&gt;
*Uses ActiveRecord queries and includes associations.&lt;br /&gt;
&lt;br /&gt;
*Returns reviewer/reviewee names and mapping types.&lt;br /&gt;
&lt;br /&gt;
2. automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*Validates assignment presence and input parameters.&lt;br /&gt;
&lt;br /&gt;
*Helper automatic_review_mapping_logic assigns reviewers randomly.&lt;br /&gt;
&lt;br /&gt;
*Ensures no self-reviews and saves mappings.&lt;br /&gt;
&lt;br /&gt;
3. automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*Extends automatic_review_mapping with strategy support.&lt;br /&gt;
&lt;br /&gt;
*Supports default and round_robin strategies.&lt;br /&gt;
&lt;br /&gt;
*Delegates logic to generate_review_mappings_with_strategy.&lt;br /&gt;
&lt;br /&gt;
*Strategy logic selects reviewees based on pattern.&lt;br /&gt;
&lt;br /&gt;
4. automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*Supports staggered circular mappings.&lt;br /&gt;
&lt;br /&gt;
*Helper generate_staggered_review_mappings auto-detects assignment type.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-reviews and duplicates.&lt;br /&gt;
&lt;br /&gt;
*Supports team and individual assignments.&lt;br /&gt;
&lt;br /&gt;
5. assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*Assigns a specific number of reviewers to a given team.&lt;br /&gt;
&lt;br /&gt;
*Avoids self-review by excluding team members.&lt;br /&gt;
&lt;br /&gt;
*Uses helper assign_reviewers_to_team.&lt;br /&gt;
&lt;br /&gt;
*Checks for duplicate mappings before insertion.&lt;br /&gt;
&lt;br /&gt;
6. peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*Assigns reviewers in a staggered fashion using round-robin.&lt;br /&gt;
&lt;br /&gt;
*Supports both team and individual reviewers.&lt;br /&gt;
&lt;br /&gt;
*Uses generate_peer_review_strategy to handle mapping logic.&lt;br /&gt;
&lt;br /&gt;
7. save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*Accepts reviewer input: grades, comments, rubric answers.&lt;br /&gt;
&lt;br /&gt;
*Helper save_review_data validates participants and questionnaire items.&lt;br /&gt;
&lt;br /&gt;
*Saves records to Response, Answer, and links to ResponseMap.&lt;br /&gt;
&lt;br /&gt;
8. add_calibration&lt;br /&gt;
&lt;br /&gt;
*Creates calibration review mappings between instructors and teams.&lt;br /&gt;
&lt;br /&gt;
*Validates permissions and prevents duplicate calibrations.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewMapping.create_calibration_review in the model layer.&lt;br /&gt;
&lt;br /&gt;
9. select_reviewer&lt;br /&gt;
&lt;br /&gt;
*Selects a contributor/team for review.&lt;br /&gt;
&lt;br /&gt;
*Validates input using a helper method and stores selection in session.&lt;br /&gt;
&lt;br /&gt;
10. add_reviewer&lt;br /&gt;
&lt;br /&gt;
*Adds a reviewer to a team for a specific assignment.&lt;br /&gt;
&lt;br /&gt;
*Validates user identity, participant existence, and prevents duplicates.&lt;br /&gt;
&lt;br /&gt;
*Creates ReviewMapping entries on success.&lt;br /&gt;
&lt;br /&gt;
11. assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns reviewers to teams based on topic or preference.&lt;br /&gt;
&lt;br /&gt;
*Validates review limits and outstanding reviews.&lt;br /&gt;
&lt;br /&gt;
*Supports both topic-based and open assignments.&lt;br /&gt;
&lt;br /&gt;
12. review_allowed&lt;br /&gt;
&lt;br /&gt;
*Checks if a reviewer is allowed to perform more reviews based on current limits.&lt;br /&gt;
&lt;br /&gt;
*Uses ReviewResponseMap.review_allowed? logic for validations.&lt;br /&gt;
&lt;br /&gt;
13. check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*Verifies if a reviewer has pending or uncompleted reviews.&lt;br /&gt;
&lt;br /&gt;
*Implements review counting logic with error handling.&lt;br /&gt;
&lt;br /&gt;
14. start_self_review&lt;br /&gt;
&lt;br /&gt;
*Creates a self-review mapping for the participant.&lt;br /&gt;
&lt;br /&gt;
*Validates assignment, prevents duplicates, and uses team information.&lt;br /&gt;
&lt;br /&gt;
15. assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*Dynamically assigns a quiz to a reviewer.&lt;br /&gt;
&lt;br /&gt;
*Validates reviewer, assignment, and questionnaire IDs.&lt;br /&gt;
&lt;br /&gt;
*Creates QuizResponseMap entries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
===Initial Setup===&lt;br /&gt;
&lt;br /&gt;
1. Seed the database  &lt;br /&gt;
   Run `rails db:seed` to populate realistic test data.&lt;br /&gt;
&lt;br /&gt;
2. Start the server - Launch the app with `rails server`.&lt;br /&gt;
&lt;br /&gt;
3. JWT Authentication - Use `/api/v1/login` to get a JWT token and authorize Swagger (`Bearer &amp;lt;token&amp;gt;`).&lt;br /&gt;
&lt;br /&gt;
===Test Execution Workflow===&lt;br /&gt;
&lt;br /&gt;
*Navigate to the Swagger UI (/api-docs) and authorize via JWT.&lt;br /&gt;
&lt;br /&gt;
*For each endpoint, supply valid and edge-case parameters drawn from seed data.&lt;br /&gt;
&lt;br /&gt;
*Execute the request and examine the HTTP response code and payload.&lt;br /&gt;
&lt;br /&gt;
===Endpoint-specific Test Coverage===&lt;br /&gt;
&lt;br /&gt;
1.list_mappings&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid assignment ID, filtered mappings returned&lt;br /&gt;
&lt;br /&gt;
*404: Assignment does not exist&lt;br /&gt;
&lt;br /&gt;
2.automatic_review_mapping&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid input, randomized mappings generated&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing assignment or malformed payload&lt;br /&gt;
&lt;br /&gt;
3.automatic_review_mapping_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid strategies (default, round_robin)&lt;br /&gt;
&lt;br /&gt;
*422: Unsupported strategy&lt;br /&gt;
&lt;br /&gt;
4.automatic_review_mapping_staggered&lt;br /&gt;
&lt;br /&gt;
*200 OK: Correct staggered mapping for individuals/teams&lt;br /&gt;
&lt;br /&gt;
*404: Invalid assignment&lt;br /&gt;
&lt;br /&gt;
5.assign_reviewers_for_team&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewers correctly mapped to all team members&lt;br /&gt;
&lt;br /&gt;
*404/422: Team not found or reviewer pool insufficient&lt;br /&gt;
&lt;br /&gt;
6.peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
*200 OK: Valid round-robin distribution&lt;br /&gt;
&lt;br /&gt;
*400/404: Missing data or invalid assignment ID&lt;br /&gt;
&lt;br /&gt;
7.save_grade_and_comment_for_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Response and answers created&lt;br /&gt;
&lt;br /&gt;
*422: Invalid rubric input or participant mismatch&lt;br /&gt;
&lt;br /&gt;
8.add_calibration&lt;br /&gt;
&lt;br /&gt;
*200 OK: Calibration mapping established&lt;br /&gt;
&lt;br /&gt;
*403/422: Unauthorized or duplicate entry&lt;br /&gt;
&lt;br /&gt;
9.select_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer session updated&lt;br /&gt;
&lt;br /&gt;
*400/404: Invalid contributor ID&lt;br /&gt;
&lt;br /&gt;
10.add_reviewer&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer successfully assigned&lt;br /&gt;
&lt;br /&gt;
*422/404: Participant mismatch or user not found&lt;br /&gt;
&lt;br /&gt;
11.assign_reviewer_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Reviewer assigned via topic selection&lt;br /&gt;
&lt;br /&gt;
*422: Over-assignment detected&lt;br /&gt;
&lt;br /&gt;
12.review_allowed&lt;br /&gt;
&lt;br /&gt;
*200 OK: Returns true/false based on review count&lt;br /&gt;
&lt;br /&gt;
*422/404: Incomplete parameters or non-existent reviewer&lt;br /&gt;
&lt;br /&gt;
13.check_outstanding_reviews&lt;br /&gt;
&lt;br /&gt;
*200 OK : Boolean response indicating pending reviews&lt;br /&gt;
&lt;br /&gt;
14.start_self_review&lt;br /&gt;
&lt;br /&gt;
*200 OK : Self-review mapping saved&lt;br /&gt;
&lt;br /&gt;
*422/404: Review already exists or assignment invalid&lt;br /&gt;
&lt;br /&gt;
15.assign_quiz_dynamically&lt;br /&gt;
&lt;br /&gt;
*200 OK: Quiz mapped to participant&lt;br /&gt;
&lt;br /&gt;
*422/404: Invalid input or questionnaire ID&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164347</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=164347"/>
		<updated>2025-04-21T04:07:44Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|-&lt;br /&gt;
| add_calibration || POST || /review_mappings/add_calibration || Creates calibration review mapping between team and assignment&lt;br /&gt;
|-&lt;br /&gt;
| add_reviewer || POST || /review_mappings/add_reviewer || Assigns reviewers to teams&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mappings/assign_reviewer_dynamically || Dynamically assigns reviewer to team/topic&lt;br /&gt;
|-&lt;br /&gt;
| review_allowed || GET || /review_mappings/review_allowed || Checks if reviewer can perform more reviews&lt;br /&gt;
|-&lt;br /&gt;
| check_outstanding_reviews || GET || /review_mappings/check_outstanding_reviews || Checks for exceeded maximum outstanding reviews&lt;br /&gt;
|-&lt;br /&gt;
| assign_quiz_dynamically || POST || /review_mappings/assign_quiz_dynamically ||  Assigns quiz to participant&lt;br /&gt;
|-&lt;br /&gt;
| select_reviewer || GET || /review_mappings/select_reviewer || Selects and stores a contributor for review mapping&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163991</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163991"/>
		<updated>2025-04-16T22:50:47Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [https://github.com/expertiza/reimplementation-back-end/pull/187 Pull Request]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163750</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163750"/>
		<updated>2025-04-08T02:35:25Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
It ensures that each layer of the application handles a specific task: the controller manages request handling, the models encapsulate data-related logic, and service objects take care of complex workflows or operations. Overall, this reimplementation aims to establish a solid foundation for the controller that aligns with modern Rails development standards and supports the long-term sustainability of the Expertiza platform.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163618</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163618"/>
		<updated>2025-04-08T01:36:00Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. The new controller will be responsible only for handling HTTP requests such as creating, assigning, and deleting review mappings, while delegating all business logic to models, or helper modules. This approach will ensure better code organization, improved testability, and easier long-term maintenance. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163399</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163399"/>
		<updated>2025-04-07T15:05:17Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
Expertiza is an open-source project built on Ruby on Rails that supports peer review and team collaboration in academic settings. It allows students to submit assignments, review each other’s work, and receive feedback. It allows instructors to design and customize assignments, creating a pool of project topics for students to choose from. Students can submit their work in various formats,  and engage in peer review to provide and receive constructive feedback.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This project aims to re-implement the ReviewMappingController as part of a backend modernization effort. The goal is to build a clean, efficient, and maintainable version of the controller from scratch in the reimplementation-back-end repository, following Rails best practices and RESTful design principles. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
*Reimplement the ReviewMappingController in the reimplementation-back-end repository without reusing legacy code.&lt;br /&gt;
*Ensure the controller only handles routing, parameter validation, and delegation of actions.&lt;br /&gt;
*Migrate business logic to models, service objects, or helper modules.&lt;br /&gt;
*Use polymorphic or strategy design patterns to manage different review mapping types.&lt;br /&gt;
*Provide thorough unit and integration tests along with inline documentation. &lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
*ReviewMappingController contains highly coupled and outdated code that mixes business logic with request handling.&lt;br /&gt;
*Hardcoded parameters reduce flexibility and adaptability across different environments. &lt;br /&gt;
*Inconsistent validation and minimal error handling lead to unclear user feedback.&lt;br /&gt;
*Several methods are overly long and difficult to maintain.&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163398</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163398"/>
		<updated>2025-04-07T14:57:11Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation.Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163388</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163388"/>
		<updated>2025-04-07T03:37:51Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The ReviewMappingController is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as ReviewResponseMap, MetareviewResponseMap, and SelfReviewResponseMap, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like ReviewMappingHelper provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingControlle, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163387</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163387"/>
		<updated>2025-04-07T03:35:58Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
The `ReviewMappingController` is responsible for managing the creation, assignment, and deletion of review mappings among participants in an assignment. Following reimplementation-back-end best practices, the controller strictly handles HTTP request routing, parameter validation, and delegates business logic to model methods. It interacts with models such as `ReviewResponseMap`, `MetareviewResponseMap`, and `SelfReviewResponseMap`, which maintain reviewer-reviewee relationships. Operations like dynamic reviewer assignment, metareviewer assignment, and self-review initiation are implemented as model methods to ensure a thin controller and a fat model design. Helper modules like `ReviewMappingHelper` provide small reusable utility methods, promoting modularity, extensibility, and maintainability while adhering to Rails conventions and RESTful principles.&lt;br /&gt;
&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of `ReviewMappingController`, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of `ReviewMappingController`, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the `ReviewMappingController`, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163386</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163386"/>
		<updated>2025-04-07T03:33:54Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;plantuml&amp;quot;&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingController, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163385</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163385"/>
		<updated>2025-04-07T03:30:02Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png|800px|]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingController, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_diagram.png&amp;diff=163384</id>
		<title>File:Controller diagram.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Controller_diagram.png&amp;diff=163384"/>
		<updated>2025-04-07T03:28:02Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163383</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163383"/>
		<updated>2025-04-07T03:24:59Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
[[File:controller_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
@startuml&lt;br /&gt;
object ApplicationController&lt;br /&gt;
object ReviewMappingController {&lt;br /&gt;
  +list_mappings()&lt;br /&gt;
  +create_mapping()&lt;br /&gt;
  +assign_reviewer_dynamically()&lt;br /&gt;
  +assign_metareviewer_dynamically()&lt;br /&gt;
  +start_self_review()&lt;br /&gt;
  +automatic_review_mapping()&lt;br /&gt;
  +delete_mapping()&lt;br /&gt;
  +unsubmit_review()&lt;br /&gt;
}&lt;br /&gt;
object ReviewMappingHelper&lt;br /&gt;
object SubmittedContentHelper&lt;br /&gt;
object ReviewResponseMap {&lt;br /&gt;
  +assign_reviewer()&lt;br /&gt;
  +assign_metareviewer()&lt;br /&gt;
  +assign_self_reviewer()&lt;br /&gt;
  +automatic_mapping()&lt;br /&gt;
}&lt;br /&gt;
object MetareviewResponseMap&lt;br /&gt;
object SelfReviewResponseMap&lt;br /&gt;
object Assignment&lt;br /&gt;
object Participant&lt;br /&gt;
object Team&lt;br /&gt;
object User&lt;br /&gt;
ApplicationController &amp;lt;|-- ReviewMappingController&lt;br /&gt;
ReviewMappingController ..&amp;gt; ReviewMappingHelper&lt;br /&gt;
ReviewMappingController ..&amp;gt; SubmittedContentHelper&lt;br /&gt;
ReviewMappingController --&amp;gt; ReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; MetareviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; SelfReviewResponseMap : delegates&lt;br /&gt;
ReviewMappingController --&amp;gt; Assignment&lt;br /&gt;
ReviewMappingController --&amp;gt; Participant&lt;br /&gt;
ReviewMappingController --&amp;gt; Team&lt;br /&gt;
ReviewMappingController --&amp;gt; User&lt;br /&gt;
ReviewResponseMap --&amp;gt; Participant : reviewer&lt;br /&gt;
ReviewResponseMap --&amp;gt; Team : reviewee&lt;br /&gt;
ReviewResponseMap --&amp;gt; Assignment&lt;br /&gt;
@enduml&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Methods / API Calls ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Method !! HTTP Verb !! Route !! Purpose&lt;br /&gt;
|-&lt;br /&gt;
| list_mappings || GET || /review_mapping || List all mappings for an assignment&lt;br /&gt;
|-&lt;br /&gt;
| create_mapping || POST || /review_mapping || Create a new reviewer → reviewee mapping&lt;br /&gt;
|-&lt;br /&gt;
| assign_reviewer_dynamically || POST || /review_mapping/assign_reviewer_dynamically || Dynamically assign a reviewer to a team&lt;br /&gt;
|-&lt;br /&gt;
| assign_metareviewer_dynamically || POST || /review_mapping/assign_metareviewer_dynamically || Dynamically assign a metareviewer to a review&lt;br /&gt;
|-&lt;br /&gt;
| start_self_review || POST || /review_mapping/start_self_review || Initiate a self-review for a participant&lt;br /&gt;
|-&lt;br /&gt;
| automatic_review_mapping || POST || /review_mapping/automatic_review_mapping || Automatically distribute reviewers across teams&lt;br /&gt;
|-&lt;br /&gt;
| delete_mapping || DELETE || /review_mapping/:id || Delete a review mapping&lt;br /&gt;
|-&lt;br /&gt;
| unsubmit_review || POST || /review_mapping/unsubmit_review || Unsubmit a submitted review&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingController, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163382</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163382"/>
		<updated>2025-04-07T02:57:11Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingController, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
The ReviewMappingController will be reimplemented from scratch, focusing solely on handling HTTP requests while delegating business logic to service objects, models, and helper modules. We will implement strong parameters for secure data handling, ensuring only valid and required fields are processed. The controller will use Strategy Pattern to modularly handle different review mapping types (e.g., reviewer assignments, meta-reviews, self-reviews), with each type having its own dedicated service class. This ensures that new mapping types can be added without modifying the existing controller code, aligning with the Open/Closed Principle. We will also ensure adherence to the Single Responsibility Principle by moving complex review mapping logic, such as dynamic reviewer assignment and validation algorithms, into service classes and helper modules. Flash messages and error handling will be standardized to provide consistent feedback to the user. Additionally, we will maintain a clean and organized codebase by decomposing lengthy methods into smaller, manageable units and removing any redundant or dead code. This modular design will ensure a maintainable, flexible, and extensible controller implementation.&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
A comprehensive testing strategy will be implemented to ensure the functionality, security, and performance of the ReviewMappingController. Unit tests will be written for the service objects and helper modules to verify that business logic, such as reviewer assignment and mapping validation, is functioning correctly. We will write integration tests for the controller to ensure that all CRUD operations (create, read, update, delete) are handled correctly, with appropriate success and error messages returned for different scenarios. Tests will also cover edge cases, such as invalid input and unsuccessful review mapping creation. Security testing will be conducted to ensure that the system is resistant to common vulnerabilities, such as SQL injection, XSS, and CSRF. Additionally, performance testing will be carried out to ensure that the controller can handle a large number of requests without degradation. By following a test-driven development (TDD) approach, we will ensure that the controller and its associated services are reliable, secure, and performant.&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163381</id>
		<title>CSC/ECE 517 Spring 2025 - E2525 Reimplement review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2525_Reimplement_review_mapping_controller.rb&amp;diff=163381"/>
		<updated>2025-04-07T02:49:43Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Created page with &amp;quot;==About Expertiza==   ==Introduction==   ==Requirements==   ==Existing Issues==   ==Design / Proposed Solution == ===Controller Diagram===  ===Pattern(s)=== '''Strategy'''&amp;lt;br/&amp;gt; The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of Revi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design / Proposed Solution ==&lt;br /&gt;
===Controller Diagram===&lt;br /&gt;
&lt;br /&gt;
===Pattern(s)===&lt;br /&gt;
'''Strategy'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Strategy Pattern is a behavioral design pattern that enables selecting an algorithm’s behavior at runtime by defining a family of algorithms, encapsulating each one, and making them interchangeable, thus promoting flexibility and adherence to the Open/Closed Principle. In the context of ReviewMappingController, which handles multiple types of review mappings such as reviewer assignments, meta-reviews, and self-reviews—each with distinct business logic—the Strategy Pattern allows each mapping type to be implemented as a separate strategy class following a common interface. The controller simply delegates the task to the appropriate strategy based on the mapping type in the request, thereby abstracting complex decision-making logic away from the controller itself. This promotes separation of concerns, enhances extensibility by enabling the addition of new mapping types without altering existing code, eliminates repetitive conditional statements, and encourages a modular design that is easier to test, maintain, and understand.&lt;br /&gt;
&lt;br /&gt;
===SOLID Principle(s)===&lt;br /&gt;
'''Open and Closed Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Open/Closed Principle (OCP) is one of the SOLID principles of object-oriented design and states that software entities such as classes, modules, and functions should be open for extension but closed for modification. This means that the behavior of a system can be extended without altering its existing source code, promoting stability and reducing the risk of introducing bugs when requirements evolve. In the context of ReviewMappingController, applying OCP ensures that new review mapping types (such as peer-reviews, meta-reviews, or future additions) can be supported by introducing new strategy or service classes, rather than modifying the controller or existing logic. This principle encourages the use of abstraction, interfaces, and polymorphism to allow new behaviors to be added seamlessly. By adhering to OCP, the controller remains resilient to change, promoting a modular and maintainable architecture where existing tested code remains untouched, and new functionality is integrated through clearly defined extension points.&lt;br /&gt;
&lt;br /&gt;
'''Single Responsibility Principle'''&amp;lt;br/&amp;gt;&lt;br /&gt;
The Single Responsibility Principle (SRP) is a fundamental concept in the SOLID principles of object-oriented design and states that a class or module should have only one reason to change, meaning it should only be responsible for one specific part of the system’s functionality. In the context of the ReviewMappingController, SRP implies that the controller should focus solely on handling HTTP requests—such as receiving input, validating parameters, and returning appropriate responses—while delegating all business logic (like reviewer assignment algorithms or validation checks) to separate service classes, models, or helper modules. This separation improves modularity, readability, and testability, as each component has a clearly defined role. Adhering to SRP reduces the complexity of individual components, makes the code easier to maintain, and ensures that changes in one area (e.g., business logic) do not inadvertently affect another (e.g., request routing), resulting in a more robust and scalable architecture.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing Plan==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1jjbqggRDiOHrxdsMlliY62JnP34bGTNHVWAZNz89kT8/edit?usp=sharing Final Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/reimplementation-back-end Github]&lt;br /&gt;
* [Pull Request]&lt;br /&gt;
* [VCL Server]&lt;br /&gt;
* [Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025&amp;diff=163380</id>
		<title>CSC/ECE 517 Spring 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025&amp;diff=163380"/>
		<updated>2025-04-07T02:39:51Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[CSC/ECE 517 Spring 2025 - E2503. Refactor the Team hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2504. Mentor-meeting management]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2505. Testing Answer Tagging]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2508. Reimplement bidding-algorithm web service]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2509. Reimplement feedback_response_map.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2519. Implement view for results of bidding]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2522. Enhancing UI Consistency in Expertiza 1]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2520. Reimplement heatgrid UI for reviews]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2517. Reimplement internationalization (frontend + backend)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2523: Enhancing UI Consistency in Expertiza 2]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2515:  Reimplement student_teams_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2501:  Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2502:  Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2512. Reimplement responses controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2510. Reimplement grades_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2507. Reimplement back end for submission records]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2514. Reimplement student_quizzes_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2518. Reimplement password resets (frontend + backend)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2516. Reimplement teams_users_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2511. Reimplement participants_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2521. UI for View submissions/assign grades (except heatgrid)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2513. Reimplement sign_up_topic.rb as project_topic.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2506. Implement testing for new Bookmarks Controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2527. Mentor-meeting management: assignments with topics]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2539 Reimplement Student Task View (Frontend + Backend)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2521 UI for View submissions/assign grades (except heatgrid)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2525 Reimplement review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2526 Reimplement Teams and Participant hierarchies]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2530 Reimplement Grades Controller (Frontend + Backend)]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2538 Reimplementing Questionnaire Page in Expertiza]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2534 UI for Assign Reviewers]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2540 Integration of Assignment participant Frontend with participant controller Backend]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2532. Reimplement Missing ResponseMap Subclasses]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2542. Refactor review_bids_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2533. ​​Reimplement the Team hierarchy]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025 - E2531 Refactor participants_controller.rb]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162853</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162853"/>
		<updated>2025-03-26T01:52:05Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Original Code Issues===&lt;br /&gt;
&lt;br /&gt;
*'''Redundant Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
if MetareviewResponseMap.where(reviewed_object_id: mapping.map_id, reviewer_id: reviewer.id).first.nil?&lt;br /&gt;
  MetareviewResponseMap.create(...)&lt;br /&gt;
else&lt;br /&gt;
  raise &amp;quot;The metareviewer \&amp;quot;{reviewer.name}\&amp;quot; is already assigned.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used inefficient `where` and `first.nil?` for duplicate detection&lt;br /&gt;
* Duplicate check was repeated unnecessarily&lt;br /&gt;
&lt;br /&gt;
*'''Generic Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* No distinction between missing users and unregistered participants&lt;br /&gt;
* Complex nested logic made code harder to read and maintain&lt;br /&gt;
&lt;br /&gt;
===Refactored Code Improvements===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Consolidated Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
metareview = MetareviewResponseMap.find_or_initialize_by(&lt;br /&gt;
  reviewed_object_id: mapping.id,&lt;br /&gt;
  reviewer_id: reviewer.id&lt;br /&gt;
)&lt;br /&gt;
if metareview.persisted?&lt;br /&gt;
  raise &amp;quot;Metareviewer already assigned&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
  metareview.save!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used `find_or_initialize_by` for efficient duplicate detection&lt;br /&gt;
* Removed redundant checks&lt;br /&gt;
&lt;br /&gt;
*'''Improved Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue ActiveRecord::RecordNotFound =&amp;gt; e&lt;br /&gt;
  msg = e.message.include?('User') ? 'User not found' : &amp;quot;Registration error: {e.message}&amp;quot;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Differentiated between missing users and unregistered participants&lt;br /&gt;
* Standardized error messages&lt;br /&gt;
* Clearer variable names and logical flow&lt;br /&gt;
&lt;br /&gt;
===Key Changes Summary===&lt;br /&gt;
&lt;br /&gt;
====General Improvements====&lt;br /&gt;
&lt;br /&gt;
Separation of Concerns&lt;br /&gt;
* Functions now have clearly defined responsibilities&lt;br /&gt;
* Improved maintainability through modular design&lt;br /&gt;
* Clear boundaries between different functionalities&lt;br /&gt;
&lt;br /&gt;
Error Handling&lt;br /&gt;
* Enhanced mechanisms to catch and report errors effectively&lt;br /&gt;
* More descriptive error messages&lt;br /&gt;
* Better error recovery strategies&lt;br /&gt;
&lt;br /&gt;
Validation Checks&lt;br /&gt;
* Strengthened parameter validation&lt;br /&gt;
* Improved input validation&lt;br /&gt;
* Prevention of incorrect data processing&lt;br /&gt;
&lt;br /&gt;
Optimized Queries&lt;br /&gt;
* Improved database interactions&lt;br /&gt;
* Better performance through efficient queries&lt;br /&gt;
* Reduced database load&lt;br /&gt;
&lt;br /&gt;
Testing Enhancements&lt;br /&gt;
* Expanded unit test coverage&lt;br /&gt;
* Added integration tests&lt;br /&gt;
* Implemented system tests&lt;br /&gt;
* Improved test reliability&lt;br /&gt;
&lt;br /&gt;
====Review Mapping Enhancements====&lt;br /&gt;
&lt;br /&gt;
Automatic &amp;amp; Peer Review Strategies&lt;br /&gt;
* Improved reviewer assignment logic&lt;br /&gt;
* Enhanced participant selection process&lt;br /&gt;
* Better mapping creation mechanisms&lt;br /&gt;
* More efficient review distribution&lt;br /&gt;
&lt;br /&gt;
Staggered Review Mapping&lt;br /&gt;
* Strengthened error handling&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Improved messaging clarity&lt;br /&gt;
* Better process control&lt;br /&gt;
&lt;br /&gt;
Dynamic Metareviewer Assignment&lt;br /&gt;
* Eliminated inefficient queries&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Better resource utilization&lt;br /&gt;
&lt;br /&gt;
====Review and Feedback Handling====&lt;br /&gt;
&lt;br /&gt;
Saving Grades &amp;amp; Comments&lt;br /&gt;
* Improved response format handling&lt;br /&gt;
* Added comprehensive validation checks&lt;br /&gt;
* Better data integrity&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
Self-Review Start&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Improved process flow&lt;br /&gt;
* Better error prevention&lt;br /&gt;
&lt;br /&gt;
Reviewer &amp;amp; Metareviewer Management&lt;br /&gt;
* Improved assignment logic&lt;br /&gt;
* Enhanced deletion procedures&lt;br /&gt;
* Better error handling&lt;br /&gt;
* Clearer user feedback&lt;br /&gt;
&lt;br /&gt;
====Review Lifecycle Improvements====&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
* Better string handling&lt;br /&gt;
* Improved variable naming&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Clearer process flow&lt;br /&gt;
&lt;br /&gt;
Managing Mappings&lt;br /&gt;
* Enhanced object handling&lt;br /&gt;
* Improved validation procedures&lt;br /&gt;
* Better documentation&lt;br /&gt;
* Clearer data management&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers &amp;amp; Metareviewers&lt;br /&gt;
* Strengthened error checks&lt;br /&gt;
* Improved feedback messaging&lt;br /&gt;
* Better code structure&lt;br /&gt;
* Enhanced process reliability&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly enhanced the codebase by modularizing functions, improving documentation, and expanding test coverage. These changes ensure better maintainability, improved performance, and more reliable functionality.&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
Functions Relocated&lt;br /&gt;
Key utility functions that manage review mapping logic have been moved to the `ReviewMappingHelper` module, including:&lt;br /&gt;
&lt;br /&gt;
* '''get_participant_or_reviewer''': Fetches participant details if the user is part of the assignment&lt;br /&gt;
* '''get_review_response_mapping''': Retrieves review response mapping details for assigned reviewers&lt;br /&gt;
* '''get_assignment''': Fetches assignment information using its ID&lt;br /&gt;
* '''check_for_self_review?''': Checks if a user is attempting to review their own submission&lt;br /&gt;
&lt;br /&gt;
Centralization of Logic&lt;br /&gt;
* Functions are now maintained in a single location, reducing redundancy&lt;br /&gt;
* Improves reusability, allowing multiple controller methods to use shared logic without duplication&lt;br /&gt;
* Example: `get_participant_or_reviewer` is now used in both `add_reviewer` and `assign_metareviewer_dynamically`, ensuring consistency in participant retrieval&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods by offloading business logic to helper methods&lt;br /&gt;
* Enhanced error handling to provide more informative messages&lt;br /&gt;
* Improved parameter validation to prevent invalid data from propagating&lt;br /&gt;
* Optimized database queries for better performance&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
Each method now includes:&lt;br /&gt;
* A clear description of its purpose&lt;br /&gt;
* Parameter definitions with data types and expected values&lt;br /&gt;
* Return type specification&lt;br /&gt;
* Exception handling details&lt;br /&gt;
* Example usage to guide developers&lt;br /&gt;
&lt;br /&gt;
Example Documentation&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Assigns a reviewer to a contributor (team or participant) in the context of an assignment.&lt;br /&gt;
# @param user [User] The user being assigned as a reviewer.&lt;br /&gt;
# @param assignment [Assignment] The assignment to which the review is related.&lt;br /&gt;
# @param contributor_id [Integer] The ID of the contributor (team or participant) being reviewed.&lt;br /&gt;
# @param topic_id [Integer] The ID of the topic associated with the review (if applicable).&lt;br /&gt;
# @raise [RuntimeError] Raises an error if the reviewer is already assigned to the contributor.&lt;br /&gt;
# @return [ReviewResponseMap] The newly created review response mapping record.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Documentation Benefits&lt;br /&gt;
* Developers can quickly understand method behavior without analyzing implementation&lt;br /&gt;
* Edge cases and exceptions are explicitly defined, reducing misuse&lt;br /&gt;
* Serves as a structured reference for maintaining and extending functionality&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage===&lt;br /&gt;
&lt;br /&gt;
Successful Metareview Creation&lt;br /&gt;
* Verifies new metareview mapping creation&lt;br /&gt;
* Confirms correct redirect&lt;br /&gt;
* Validates successful creation flow&lt;br /&gt;
&lt;br /&gt;
Duplicate Assignment Prevention&lt;br /&gt;
* Ensures no duplicate mappings are created&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Tests boundary conditions&lt;br /&gt;
&lt;br /&gt;
Handling Missing Users&lt;br /&gt;
* Tests error handling for non-existent users&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Ensures proper error recovery&lt;br /&gt;
&lt;br /&gt;
Assigning Reviewers Dynamically&lt;br /&gt;
*Tests assignment of reviewers dynamically.&lt;br /&gt;
*Validates topic selection.&lt;br /&gt;
*Handles cases where no topics or artifacts are available.&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
*Tests unsubmitting reviews.&lt;br /&gt;
*Validates conditions where reviews cannot be unsubmitted.&lt;br /&gt;
*Ensures proper success and error messaging.&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers&lt;br /&gt;
*Tests deletion of reviewers.&lt;br /&gt;
*Validates conditions where reviewers cannot be deleted.&lt;br /&gt;
*Ensures proper success and error messaging.&lt;br /&gt;
&lt;br /&gt;
Automatic Review Mapping&lt;br /&gt;
*Tests automatic review mapping.&lt;br /&gt;
*Validates assignment of reviews based on parameters.&lt;br /&gt;
*Ensures proper error handling for invalid parameters.&lt;br /&gt;
&lt;br /&gt;
Saving Grades and Comments&lt;br /&gt;
*Tests saving grades and comments for reviewers.&lt;br /&gt;
*Validates proper saving and error handling.&lt;br /&gt;
*Ensures proper success and error messaging.&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Thoroughly tested all refactored functionality&lt;br /&gt;
* Added integration tests to verify workflow consistency&lt;br /&gt;
* Expanded unit test coverage for helper methods&lt;br /&gt;
* Implemented system tests to validate end-to-end functionality&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Strengthened testing for error scenarios&lt;br /&gt;
* Added validation failure tests to ensure proper input handling&lt;br /&gt;
* Enhanced edge case coverage to account for uncommon conditions&lt;br /&gt;
* Implemented error message validation to improve debugging&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Validated boundary conditions for critical functions&lt;br /&gt;
* Improved handling of null values and unexpected input&lt;br /&gt;
* Assessed performance under load and stress conditions&lt;br /&gt;
&lt;br /&gt;
Testing Benefits&lt;br /&gt;
* Ensures robustness by catching potential issues early&lt;br /&gt;
* Facilitates reliable deployments with reduced risk&lt;br /&gt;
* Enhances maintainability by ensuring future changes do not introduce regressions&lt;br /&gt;
&lt;br /&gt;
Example Test Cases&lt;br /&gt;
&lt;br /&gt;
*Successful Metareview Creation&lt;br /&gt;
   Input: Valid user ID, valid assignment ID, valid team ID.&lt;br /&gt;
   Expected Output: Metareview mapping created, redirect to new review form.&lt;br /&gt;
*Duplicate Assignment Prevention&lt;br /&gt;
   Input: Valid user ID, valid assignment ID, valid team ID (already assigned).&lt;br /&gt;
   Expected Output: Error message, no new mapping created.&lt;br /&gt;
*Handling Missing Users&lt;br /&gt;
   Input: Invalid user ID.&lt;br /&gt;
   Expected Output: Error message, no new mapping created.&lt;br /&gt;
*Assigning Reviewers Dynamically&lt;br /&gt;
   Input: Valid user ID, valid assignment ID, valid topic ID.&lt;br /&gt;
   Expected Output: Reviewer assigned, redirect to review list.&lt;br /&gt;
*Deleting Outstanding Reviewers&lt;br /&gt;
   Input: Valid assignment ID, valid team ID.&lt;br /&gt;
   Expected Output: Review mappings deleted, success message.&lt;br /&gt;
&lt;br /&gt;
===RSpec Test Results===&lt;br /&gt;
&lt;br /&gt;
Test Coverage Overview&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation Impact==&lt;br /&gt;
By implementing these changes, the codebase is now:&lt;br /&gt;
* More structured and organized&lt;br /&gt;
* Easier to maintain and update&lt;br /&gt;
* Highly reliable and robust&lt;br /&gt;
* Better prepared for future enhancements&lt;br /&gt;
* More efficient in operation&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Project Team&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [http://152.7.176.255:8080/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=TepuadnzGlg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162852</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162852"/>
		<updated>2025-03-26T01:34:03Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Original Code Issues===&lt;br /&gt;
&lt;br /&gt;
*'''Redundant Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
if MetareviewResponseMap.where(reviewed_object_id: mapping.map_id, reviewer_id: reviewer.id).first.nil?&lt;br /&gt;
  MetareviewResponseMap.create(...)&lt;br /&gt;
else&lt;br /&gt;
  raise &amp;quot;The metareviewer \&amp;quot;{reviewer.name}\&amp;quot; is already assigned.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used inefficient `where` and `first.nil?` for duplicate detection&lt;br /&gt;
* Duplicate check was repeated unnecessarily&lt;br /&gt;
&lt;br /&gt;
*'''Generic Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* No distinction between missing users and unregistered participants&lt;br /&gt;
* Complex nested logic made code harder to read and maintain&lt;br /&gt;
&lt;br /&gt;
===Refactored Code Improvements===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Consolidated Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
metareview = MetareviewResponseMap.find_or_initialize_by(&lt;br /&gt;
  reviewed_object_id: mapping.id,&lt;br /&gt;
  reviewer_id: reviewer.id&lt;br /&gt;
)&lt;br /&gt;
if metareview.persisted?&lt;br /&gt;
  raise &amp;quot;Metareviewer already assigned&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
  metareview.save!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used `find_or_initialize_by` for efficient duplicate detection&lt;br /&gt;
* Removed redundant checks&lt;br /&gt;
&lt;br /&gt;
*'''Improved Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue ActiveRecord::RecordNotFound =&amp;gt; e&lt;br /&gt;
  msg = e.message.include?('User') ? 'User not found' : &amp;quot;Registration error: {e.message}&amp;quot;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Differentiated between missing users and unregistered participants&lt;br /&gt;
* Standardized error messages&lt;br /&gt;
* Clearer variable names and logical flow&lt;br /&gt;
&lt;br /&gt;
===Key Changes Summary===&lt;br /&gt;
&lt;br /&gt;
====General Improvements====&lt;br /&gt;
&lt;br /&gt;
Separation of Concerns&lt;br /&gt;
* Functions now have clearly defined responsibilities&lt;br /&gt;
* Improved maintainability through modular design&lt;br /&gt;
* Clear boundaries between different functionalities&lt;br /&gt;
&lt;br /&gt;
Error Handling&lt;br /&gt;
* Enhanced mechanisms to catch and report errors effectively&lt;br /&gt;
* More descriptive error messages&lt;br /&gt;
* Better error recovery strategies&lt;br /&gt;
&lt;br /&gt;
Validation Checks&lt;br /&gt;
* Strengthened parameter validation&lt;br /&gt;
* Improved input validation&lt;br /&gt;
* Prevention of incorrect data processing&lt;br /&gt;
&lt;br /&gt;
Optimized Queries&lt;br /&gt;
* Improved database interactions&lt;br /&gt;
* Better performance through efficient queries&lt;br /&gt;
* Reduced database load&lt;br /&gt;
&lt;br /&gt;
Testing Enhancements&lt;br /&gt;
* Expanded unit test coverage&lt;br /&gt;
* Added integration tests&lt;br /&gt;
* Implemented system tests&lt;br /&gt;
* Improved test reliability&lt;br /&gt;
&lt;br /&gt;
====Review Mapping Enhancements====&lt;br /&gt;
&lt;br /&gt;
Automatic &amp;amp; Peer Review Strategies&lt;br /&gt;
* Improved reviewer assignment logic&lt;br /&gt;
* Enhanced participant selection process&lt;br /&gt;
* Better mapping creation mechanisms&lt;br /&gt;
* More efficient review distribution&lt;br /&gt;
&lt;br /&gt;
Staggered Review Mapping&lt;br /&gt;
* Strengthened error handling&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Improved messaging clarity&lt;br /&gt;
* Better process control&lt;br /&gt;
&lt;br /&gt;
Dynamic Metareviewer Assignment&lt;br /&gt;
* Eliminated inefficient queries&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Better resource utilization&lt;br /&gt;
&lt;br /&gt;
====Review and Feedback Handling====&lt;br /&gt;
&lt;br /&gt;
Saving Grades &amp;amp; Comments&lt;br /&gt;
* Improved response format handling&lt;br /&gt;
* Added comprehensive validation checks&lt;br /&gt;
* Better data integrity&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
Self-Review Start&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Improved process flow&lt;br /&gt;
* Better error prevention&lt;br /&gt;
&lt;br /&gt;
Reviewer &amp;amp; Metareviewer Management&lt;br /&gt;
* Improved assignment logic&lt;br /&gt;
* Enhanced deletion procedures&lt;br /&gt;
* Better error handling&lt;br /&gt;
* Clearer user feedback&lt;br /&gt;
&lt;br /&gt;
====Review Lifecycle Improvements====&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
* Better string handling&lt;br /&gt;
* Improved variable naming&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Clearer process flow&lt;br /&gt;
&lt;br /&gt;
Managing Mappings&lt;br /&gt;
* Enhanced object handling&lt;br /&gt;
* Improved validation procedures&lt;br /&gt;
* Better documentation&lt;br /&gt;
* Clearer data management&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers &amp;amp; Metareviewers&lt;br /&gt;
* Strengthened error checks&lt;br /&gt;
* Improved feedback messaging&lt;br /&gt;
* Better code structure&lt;br /&gt;
* Enhanced process reliability&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly enhanced the codebase by modularizing functions, improving documentation, and expanding test coverage. These changes ensure better maintainability, improved performance, and more reliable functionality.&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
Functions Relocated&lt;br /&gt;
Key utility functions that manage review mapping logic have been moved to the `ReviewMappingHelper` module, including:&lt;br /&gt;
&lt;br /&gt;
* '''get_participant_or_reviewer''': Fetches participant details if the user is part of the assignment&lt;br /&gt;
* '''get_review_response_mapping''': Retrieves review response mapping details for assigned reviewers&lt;br /&gt;
* '''get_assignment''': Fetches assignment information using its ID&lt;br /&gt;
* '''check_for_self_review?''': Checks if a user is attempting to review their own submission&lt;br /&gt;
&lt;br /&gt;
Centralization of Logic&lt;br /&gt;
* Functions are now maintained in a single location, reducing redundancy&lt;br /&gt;
* Improves reusability, allowing multiple controller methods to use shared logic without duplication&lt;br /&gt;
* Example: `get_participant_or_reviewer` is now used in both `add_reviewer` and `assign_metareviewer_dynamically`, ensuring consistency in participant retrieval&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods by offloading business logic to helper methods&lt;br /&gt;
* Enhanced error handling to provide more informative messages&lt;br /&gt;
* Improved parameter validation to prevent invalid data from propagating&lt;br /&gt;
* Optimized database queries for better performance&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
Each method now includes:&lt;br /&gt;
* A clear description of its purpose&lt;br /&gt;
* Parameter definitions with data types and expected values&lt;br /&gt;
* Return type specification&lt;br /&gt;
* Exception handling details&lt;br /&gt;
* Example usage to guide developers&lt;br /&gt;
&lt;br /&gt;
Example Documentation&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Assigns a reviewer to a contributor (team or participant) in the context of an assignment.&lt;br /&gt;
# @param user [User] The user being assigned as a reviewer.&lt;br /&gt;
# @param assignment [Assignment] The assignment to which the review is related.&lt;br /&gt;
# @param contributor_id [Integer] The ID of the contributor (team or participant) being reviewed.&lt;br /&gt;
# @param topic_id [Integer] The ID of the topic associated with the review (if applicable).&lt;br /&gt;
# @raise [RuntimeError] Raises an error if the reviewer is already assigned to the contributor.&lt;br /&gt;
# @return [ReviewResponseMap] The newly created review response mapping record.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Documentation Benefits&lt;br /&gt;
* Developers can quickly understand method behavior without analyzing implementation&lt;br /&gt;
* Edge cases and exceptions are explicitly defined, reducing misuse&lt;br /&gt;
* Serves as a structured reference for maintaining and extending functionality&lt;br /&gt;
&lt;br /&gt;
==Test Plan==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage===&lt;br /&gt;
&lt;br /&gt;
Successful Metareview Creation&lt;br /&gt;
* Verifies new metareview mapping creation&lt;br /&gt;
* Confirms correct redirect&lt;br /&gt;
* Validates successful creation flow&lt;br /&gt;
&lt;br /&gt;
Duplicate Assignment Prevention&lt;br /&gt;
* Ensures no duplicate mappings are created&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Tests boundary conditions&lt;br /&gt;
&lt;br /&gt;
Handling Missing Users&lt;br /&gt;
* Tests error handling for non-existent users&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Ensures proper error recovery&lt;br /&gt;
&lt;br /&gt;
Handling Unregistered Participants&lt;br /&gt;
* Tests error handling for unregistered users&lt;br /&gt;
* Validates registration checks&lt;br /&gt;
* Ensures proper error messaging&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Thoroughly tested all refactored functionality&lt;br /&gt;
* Added integration tests to verify workflow consistency&lt;br /&gt;
* Expanded unit test coverage for helper methods&lt;br /&gt;
* Implemented system tests to validate end-to-end functionality&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Strengthened testing for error scenarios&lt;br /&gt;
* Added validation failure tests to ensure proper input handling&lt;br /&gt;
* Enhanced edge case coverage to account for uncommon conditions&lt;br /&gt;
* Implemented error message validation to improve debugging&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Validated boundary conditions for critical functions&lt;br /&gt;
* Improved handling of null values and unexpected input&lt;br /&gt;
* Assessed performance under load and stress conditions&lt;br /&gt;
&lt;br /&gt;
Testing Benefits&lt;br /&gt;
* Ensures robustness by catching potential issues early&lt;br /&gt;
* Facilitates reliable deployments with reduced risk&lt;br /&gt;
* Enhances maintainability by ensuring future changes do not introduce regressions&lt;br /&gt;
&lt;br /&gt;
===RSpec Test Results===&lt;br /&gt;
&lt;br /&gt;
Test Coverage Overview&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation Impact==&lt;br /&gt;
By implementing these changes, the codebase is now:&lt;br /&gt;
* More structured and organized&lt;br /&gt;
* Easier to maintain and update&lt;br /&gt;
* Highly reliable and robust&lt;br /&gt;
* Better prepared for future enhancements&lt;br /&gt;
* More efficient in operation&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Project Team&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [http://152.7.176.255:8080/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=TepuadnzGlg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162802</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162802"/>
		<updated>2025-03-25T04:02:10Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Original Code Issues===&lt;br /&gt;
&lt;br /&gt;
*'''Redundant Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
if MetareviewResponseMap.where(reviewed_object_id: mapping.map_id, reviewer_id: reviewer.id).first.nil?&lt;br /&gt;
  MetareviewResponseMap.create(...)&lt;br /&gt;
else&lt;br /&gt;
  raise &amp;quot;The metareviewer \&amp;quot;{reviewer.name}\&amp;quot; is already assigned.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used inefficient `where` and `first.nil?` for duplicate detection&lt;br /&gt;
* Duplicate check was repeated unnecessarily&lt;br /&gt;
&lt;br /&gt;
*'''Generic Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* No distinction between missing users and unregistered participants&lt;br /&gt;
* Complex nested logic made code harder to read and maintain&lt;br /&gt;
&lt;br /&gt;
===Refactored Code Improvements===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Consolidated Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
metareview = MetareviewResponseMap.find_or_initialize_by(&lt;br /&gt;
  reviewed_object_id: mapping.id,&lt;br /&gt;
  reviewer_id: reviewer.id&lt;br /&gt;
)&lt;br /&gt;
if metareview.persisted?&lt;br /&gt;
  raise &amp;quot;Metareviewer already assigned&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
  metareview.save!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used `find_or_initialize_by` for efficient duplicate detection&lt;br /&gt;
* Removed redundant checks&lt;br /&gt;
&lt;br /&gt;
*'''Improved Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue ActiveRecord::RecordNotFound =&amp;gt; e&lt;br /&gt;
  msg = e.message.include?('User') ? 'User not found' : &amp;quot;Registration error: {e.message}&amp;quot;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Differentiated between missing users and unregistered participants&lt;br /&gt;
* Standardized error messages&lt;br /&gt;
* Clearer variable names and logical flow&lt;br /&gt;
&lt;br /&gt;
===Key Changes Summary===&lt;br /&gt;
&lt;br /&gt;
====General Improvements====&lt;br /&gt;
&lt;br /&gt;
Separation of Concerns&lt;br /&gt;
* Functions now have clearly defined responsibilities&lt;br /&gt;
* Improved maintainability through modular design&lt;br /&gt;
* Clear boundaries between different functionalities&lt;br /&gt;
&lt;br /&gt;
Error Handling&lt;br /&gt;
* Enhanced mechanisms to catch and report errors effectively&lt;br /&gt;
* More descriptive error messages&lt;br /&gt;
* Better error recovery strategies&lt;br /&gt;
&lt;br /&gt;
Validation Checks&lt;br /&gt;
* Strengthened parameter validation&lt;br /&gt;
* Improved input validation&lt;br /&gt;
* Prevention of incorrect data processing&lt;br /&gt;
&lt;br /&gt;
Optimized Queries&lt;br /&gt;
* Improved database interactions&lt;br /&gt;
* Better performance through efficient queries&lt;br /&gt;
* Reduced database load&lt;br /&gt;
&lt;br /&gt;
Testing Enhancements&lt;br /&gt;
* Expanded unit test coverage&lt;br /&gt;
* Added integration tests&lt;br /&gt;
* Implemented system tests&lt;br /&gt;
* Improved test reliability&lt;br /&gt;
&lt;br /&gt;
====Review Mapping Enhancements====&lt;br /&gt;
&lt;br /&gt;
Automatic &amp;amp; Peer Review Strategies&lt;br /&gt;
* Improved reviewer assignment logic&lt;br /&gt;
* Enhanced participant selection process&lt;br /&gt;
* Better mapping creation mechanisms&lt;br /&gt;
* More efficient review distribution&lt;br /&gt;
&lt;br /&gt;
Staggered Review Mapping&lt;br /&gt;
* Strengthened error handling&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Improved messaging clarity&lt;br /&gt;
* Better process control&lt;br /&gt;
&lt;br /&gt;
Dynamic Metareviewer Assignment&lt;br /&gt;
* Eliminated inefficient queries&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Better resource utilization&lt;br /&gt;
&lt;br /&gt;
====Review and Feedback Handling====&lt;br /&gt;
&lt;br /&gt;
Saving Grades &amp;amp; Comments&lt;br /&gt;
* Improved response format handling&lt;br /&gt;
* Added comprehensive validation checks&lt;br /&gt;
* Better data integrity&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
Self-Review Start&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Improved process flow&lt;br /&gt;
* Better error prevention&lt;br /&gt;
&lt;br /&gt;
Reviewer &amp;amp; Metareviewer Management&lt;br /&gt;
* Improved assignment logic&lt;br /&gt;
* Enhanced deletion procedures&lt;br /&gt;
* Better error handling&lt;br /&gt;
* Clearer user feedback&lt;br /&gt;
&lt;br /&gt;
====Review Lifecycle Improvements====&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
* Better string handling&lt;br /&gt;
* Improved variable naming&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Clearer process flow&lt;br /&gt;
&lt;br /&gt;
Managing Mappings&lt;br /&gt;
* Enhanced object handling&lt;br /&gt;
* Improved validation procedures&lt;br /&gt;
* Better documentation&lt;br /&gt;
* Clearer data management&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers &amp;amp; Metareviewers&lt;br /&gt;
* Strengthened error checks&lt;br /&gt;
* Improved feedback messaging&lt;br /&gt;
* Better code structure&lt;br /&gt;
* Enhanced process reliability&lt;br /&gt;
&lt;br /&gt;
===Test Coverage===&lt;br /&gt;
Successful Metareview Creation&lt;br /&gt;
* Verifies new metareview mapping creation&lt;br /&gt;
* Confirms correct redirect&lt;br /&gt;
* Validates successful creation flow&lt;br /&gt;
&lt;br /&gt;
Duplicate Assignment Prevention&lt;br /&gt;
* Ensures no duplicate mappings are created&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Tests boundary conditions&lt;br /&gt;
&lt;br /&gt;
Handling Missing Users&lt;br /&gt;
* Tests error handling for non-existent users&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Ensures proper error recovery&lt;br /&gt;
&lt;br /&gt;
Handling Unregistered Participants&lt;br /&gt;
* Tests error handling for unregistered users&lt;br /&gt;
* Validates registration checks&lt;br /&gt;
* Ensures proper error messaging&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly enhanced the codebase by modularizing functions, improving documentation, and expanding test coverage. These changes ensure better maintainability, improved performance, and more reliable functionality.&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
Functions Relocated&lt;br /&gt;
Key utility functions that manage review mapping logic have been moved to the `ReviewMappingHelper` module, including:&lt;br /&gt;
&lt;br /&gt;
* '''get_participant_or_reviewer''': Fetches participant details if the user is part of the assignment&lt;br /&gt;
* '''get_review_response_mapping''': Retrieves review response mapping details for assigned reviewers&lt;br /&gt;
* '''get_assignment''': Fetches assignment information using its ID&lt;br /&gt;
* '''check_for_self_review?''': Checks if a user is attempting to review their own submission&lt;br /&gt;
&lt;br /&gt;
Centralization of Logic&lt;br /&gt;
* Functions are now maintained in a single location, reducing redundancy&lt;br /&gt;
* Improves reusability, allowing multiple controller methods to use shared logic without duplication&lt;br /&gt;
* Example: `get_participant_or_reviewer` is now used in both `add_reviewer` and `assign_metareviewer_dynamically`, ensuring consistency in participant retrieval&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods by offloading business logic to helper methods&lt;br /&gt;
* Enhanced error handling to provide more informative messages&lt;br /&gt;
* Improved parameter validation to prevent invalid data from propagating&lt;br /&gt;
* Optimized database queries for better performance&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
Each method now includes:&lt;br /&gt;
* A clear description of its purpose&lt;br /&gt;
* Parameter definitions with data types and expected values&lt;br /&gt;
* Return type specification&lt;br /&gt;
* Exception handling details&lt;br /&gt;
* Example usage to guide developers&lt;br /&gt;
&lt;br /&gt;
Example Documentation&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Assigns a reviewer to a contributor (team or participant) in the context of an assignment.&lt;br /&gt;
# @param user [User] The user being assigned as a reviewer.&lt;br /&gt;
# @param assignment [Assignment] The assignment to which the review is related.&lt;br /&gt;
# @param contributor_id [Integer] The ID of the contributor (team or participant) being reviewed.&lt;br /&gt;
# @param topic_id [Integer] The ID of the topic associated with the review (if applicable).&lt;br /&gt;
# @raise [RuntimeError] Raises an error if the reviewer is already assigned to the contributor.&lt;br /&gt;
# @return [ReviewResponseMap] The newly created review response mapping record.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Documentation Benefits&lt;br /&gt;
* Developers can quickly understand method behavior without analyzing implementation&lt;br /&gt;
* Edge cases and exceptions are explicitly defined, reducing misuse&lt;br /&gt;
* Serves as a structured reference for maintaining and extending functionality&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Thoroughly tested all refactored functionality&lt;br /&gt;
* Added integration tests to verify workflow consistency&lt;br /&gt;
* Expanded unit test coverage for helper methods&lt;br /&gt;
* Implemented system tests to validate end-to-end functionality&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Strengthened testing for error scenarios&lt;br /&gt;
* Added validation failure tests to ensure proper input handling&lt;br /&gt;
* Enhanced edge case coverage to account for uncommon conditions&lt;br /&gt;
* Implemented error message validation to improve debugging&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Validated boundary conditions for critical functions&lt;br /&gt;
* Improved handling of null values and unexpected input&lt;br /&gt;
* Assessed performance under load and stress conditions&lt;br /&gt;
&lt;br /&gt;
Testing Benefits&lt;br /&gt;
* Ensures robustness by catching potential issues early&lt;br /&gt;
* Facilitates reliable deployments with reduced risk&lt;br /&gt;
* Enhances maintainability by ensuring future changes do not introduce regressions&lt;br /&gt;
&lt;br /&gt;
===Implementation Impact===&lt;br /&gt;
By implementing these changes, the codebase is now:&lt;br /&gt;
* More structured and organized&lt;br /&gt;
* Easier to maintain and update&lt;br /&gt;
* Highly reliable and robust&lt;br /&gt;
* Better prepared for future enhancements&lt;br /&gt;
* More efficient in operation&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
Test Coverage Overview&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Project Team&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [http://152.7.176.255:8080/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=TepuadnzGlg Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page&amp;diff=162711</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Main_Page&amp;diff=162711"/>
		<updated>2025-03-25T02:47:34Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Removed redirect to CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162704</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162704"/>
		<updated>2025-03-25T02:42:03Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Original Code Issues===&lt;br /&gt;
&lt;br /&gt;
*'''Redundant Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
if MetareviewResponseMap.where(reviewed_object_id: mapping.map_id, reviewer_id: reviewer.id).first.nil?&lt;br /&gt;
  MetareviewResponseMap.create(...)&lt;br /&gt;
else&lt;br /&gt;
  raise &amp;quot;The metareviewer \&amp;quot;{reviewer.name}\&amp;quot; is already assigned.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used inefficient `where` and `first.nil?` for duplicate detection&lt;br /&gt;
* Duplicate check was repeated unnecessarily&lt;br /&gt;
&lt;br /&gt;
*'''Generic Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* No distinction between missing users and unregistered participants&lt;br /&gt;
* Complex nested logic made code harder to read and maintain&lt;br /&gt;
&lt;br /&gt;
===Refactored Code Improvements===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Consolidated Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
metareview = MetareviewResponseMap.find_or_initialize_by(&lt;br /&gt;
  reviewed_object_id: mapping.id,&lt;br /&gt;
  reviewer_id: reviewer.id&lt;br /&gt;
)&lt;br /&gt;
if metareview.persisted?&lt;br /&gt;
  raise &amp;quot;Metareviewer already assigned&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
  metareview.save!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used `find_or_initialize_by` for efficient duplicate detection&lt;br /&gt;
* Removed redundant checks&lt;br /&gt;
&lt;br /&gt;
*'''Improved Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue ActiveRecord::RecordNotFound =&amp;gt; e&lt;br /&gt;
  msg = e.message.include?('User') ? 'User not found' : &amp;quot;Registration error: {e.message}&amp;quot;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Differentiated between missing users and unregistered participants&lt;br /&gt;
* Standardized error messages&lt;br /&gt;
* Clearer variable names and logical flow&lt;br /&gt;
&lt;br /&gt;
===Key Changes Summary===&lt;br /&gt;
&lt;br /&gt;
====General Improvements====&lt;br /&gt;
&lt;br /&gt;
Separation of Concerns&lt;br /&gt;
* Functions now have clearly defined responsibilities&lt;br /&gt;
* Improved maintainability through modular design&lt;br /&gt;
* Clear boundaries between different functionalities&lt;br /&gt;
&lt;br /&gt;
Error Handling&lt;br /&gt;
* Enhanced mechanisms to catch and report errors effectively&lt;br /&gt;
* More descriptive error messages&lt;br /&gt;
* Better error recovery strategies&lt;br /&gt;
&lt;br /&gt;
Validation Checks&lt;br /&gt;
* Strengthened parameter validation&lt;br /&gt;
* Improved input validation&lt;br /&gt;
* Prevention of incorrect data processing&lt;br /&gt;
&lt;br /&gt;
Optimized Queries&lt;br /&gt;
* Improved database interactions&lt;br /&gt;
* Better performance through efficient queries&lt;br /&gt;
* Reduced database load&lt;br /&gt;
&lt;br /&gt;
Testing Enhancements&lt;br /&gt;
* Expanded unit test coverage&lt;br /&gt;
* Added integration tests&lt;br /&gt;
* Implemented system tests&lt;br /&gt;
* Improved test reliability&lt;br /&gt;
&lt;br /&gt;
====Review Mapping Enhancements====&lt;br /&gt;
&lt;br /&gt;
Automatic &amp;amp; Peer Review Strategies&lt;br /&gt;
* Improved reviewer assignment logic&lt;br /&gt;
* Enhanced participant selection process&lt;br /&gt;
* Better mapping creation mechanisms&lt;br /&gt;
* More efficient review distribution&lt;br /&gt;
&lt;br /&gt;
Staggered Review Mapping&lt;br /&gt;
* Strengthened error handling&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Improved messaging clarity&lt;br /&gt;
* Better process control&lt;br /&gt;
&lt;br /&gt;
Dynamic Metareviewer Assignment&lt;br /&gt;
* Eliminated inefficient queries&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Better resource utilization&lt;br /&gt;
&lt;br /&gt;
====Review and Feedback Handling====&lt;br /&gt;
&lt;br /&gt;
Saving Grades &amp;amp; Comments&lt;br /&gt;
* Improved response format handling&lt;br /&gt;
* Added comprehensive validation checks&lt;br /&gt;
* Better data integrity&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
Self-Review Start&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Improved process flow&lt;br /&gt;
* Better error prevention&lt;br /&gt;
&lt;br /&gt;
Reviewer &amp;amp; Metareviewer Management&lt;br /&gt;
* Improved assignment logic&lt;br /&gt;
* Enhanced deletion procedures&lt;br /&gt;
* Better error handling&lt;br /&gt;
* Clearer user feedback&lt;br /&gt;
&lt;br /&gt;
====Review Lifecycle Improvements====&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
* Better string handling&lt;br /&gt;
* Improved variable naming&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Clearer process flow&lt;br /&gt;
&lt;br /&gt;
Managing Mappings&lt;br /&gt;
* Enhanced object handling&lt;br /&gt;
* Improved validation procedures&lt;br /&gt;
* Better documentation&lt;br /&gt;
* Clearer data management&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers &amp;amp; Metareviewers&lt;br /&gt;
* Strengthened error checks&lt;br /&gt;
* Improved feedback messaging&lt;br /&gt;
* Better code structure&lt;br /&gt;
* Enhanced process reliability&lt;br /&gt;
&lt;br /&gt;
===Test Coverage===&lt;br /&gt;
Successful Metareview Creation&lt;br /&gt;
* Verifies new metareview mapping creation&lt;br /&gt;
* Confirms correct redirect&lt;br /&gt;
* Validates successful creation flow&lt;br /&gt;
&lt;br /&gt;
Duplicate Assignment Prevention&lt;br /&gt;
* Ensures no duplicate mappings are created&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Tests boundary conditions&lt;br /&gt;
&lt;br /&gt;
Handling Missing Users&lt;br /&gt;
* Tests error handling for non-existent users&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Ensures proper error recovery&lt;br /&gt;
&lt;br /&gt;
Handling Unregistered Participants&lt;br /&gt;
* Tests error handling for unregistered users&lt;br /&gt;
* Validates registration checks&lt;br /&gt;
* Ensures proper error messaging&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly enhanced the codebase by modularizing functions, improving documentation, and expanding test coverage. These changes ensure better maintainability, improved performance, and more reliable functionality.&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
Functions Relocated&lt;br /&gt;
Key utility functions that manage review mapping logic have been moved to the `ReviewMappingHelper` module, including:&lt;br /&gt;
&lt;br /&gt;
* '''get_participant_or_reviewer''': Fetches participant details if the user is part of the assignment&lt;br /&gt;
* '''get_review_response_mapping''': Retrieves review response mapping details for assigned reviewers&lt;br /&gt;
* '''get_assignment''': Fetches assignment information using its ID&lt;br /&gt;
* '''check_for_self_review?''': Checks if a user is attempting to review their own submission&lt;br /&gt;
&lt;br /&gt;
Centralization of Logic&lt;br /&gt;
* Functions are now maintained in a single location, reducing redundancy&lt;br /&gt;
* Improves reusability, allowing multiple controller methods to use shared logic without duplication&lt;br /&gt;
* Example: `get_participant_or_reviewer` is now used in both `add_reviewer` and `assign_metareviewer_dynamically`, ensuring consistency in participant retrieval&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods by offloading business logic to helper methods&lt;br /&gt;
* Enhanced error handling to provide more informative messages&lt;br /&gt;
* Improved parameter validation to prevent invalid data from propagating&lt;br /&gt;
* Optimized database queries for better performance&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
Each method now includes:&lt;br /&gt;
* A clear description of its purpose&lt;br /&gt;
* Parameter definitions with data types and expected values&lt;br /&gt;
* Return type specification&lt;br /&gt;
* Exception handling details&lt;br /&gt;
* Example usage to guide developers&lt;br /&gt;
&lt;br /&gt;
Example Documentation&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Assigns a reviewer to a contributor (team or participant) in the context of an assignment.&lt;br /&gt;
# @param user [User] The user being assigned as a reviewer.&lt;br /&gt;
# @param assignment [Assignment] The assignment to which the review is related.&lt;br /&gt;
# @param contributor_id [Integer] The ID of the contributor (team or participant) being reviewed.&lt;br /&gt;
# @param topic_id [Integer] The ID of the topic associated with the review (if applicable).&lt;br /&gt;
# @raise [RuntimeError] Raises an error if the reviewer is already assigned to the contributor.&lt;br /&gt;
# @return [ReviewResponseMap] The newly created review response mapping record.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Documentation Benefits&lt;br /&gt;
* Developers can quickly understand method behavior without analyzing implementation&lt;br /&gt;
* Edge cases and exceptions are explicitly defined, reducing misuse&lt;br /&gt;
* Serves as a structured reference for maintaining and extending functionality&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Thoroughly tested all refactored functionality&lt;br /&gt;
* Added integration tests to verify workflow consistency&lt;br /&gt;
* Expanded unit test coverage for helper methods&lt;br /&gt;
* Implemented system tests to validate end-to-end functionality&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Strengthened testing for error scenarios&lt;br /&gt;
* Added validation failure tests to ensure proper input handling&lt;br /&gt;
* Enhanced edge case coverage to account for uncommon conditions&lt;br /&gt;
* Implemented error message validation to improve debugging&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Validated boundary conditions for critical functions&lt;br /&gt;
* Improved handling of null values and unexpected input&lt;br /&gt;
* Assessed performance under load and stress conditions&lt;br /&gt;
&lt;br /&gt;
Testing Benefits&lt;br /&gt;
* Ensures robustness by catching potential issues early&lt;br /&gt;
* Facilitates reliable deployments with reduced risk&lt;br /&gt;
* Enhances maintainability by ensuring future changes do not introduce regressions&lt;br /&gt;
&lt;br /&gt;
===Implementation Impact===&lt;br /&gt;
By implementing these changes, the codebase is now:&lt;br /&gt;
* More structured and organized&lt;br /&gt;
* Easier to maintain and update&lt;br /&gt;
* Highly reliable and robust&lt;br /&gt;
* Better prepared for future enhancements&lt;br /&gt;
* More efficient in operation&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
Test Coverage Overview&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Project Team&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [http://152.7.176.255:8080/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162703</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162703"/>
		<updated>2025-03-25T02:40:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
Original Code:&lt;br /&gt;
&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
Updated Code:&lt;br /&gt;
&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Original Code Issues===&lt;br /&gt;
&lt;br /&gt;
*'''Redundant Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
if MetareviewResponseMap.where(reviewed_object_id: mapping.map_id, reviewer_id: reviewer.id).first.nil?&lt;br /&gt;
  MetareviewResponseMap.create(...)&lt;br /&gt;
else&lt;br /&gt;
  raise &amp;quot;The metareviewer \&amp;quot;{reviewer.name}\&amp;quot; is already assigned.&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used inefficient `where` and `first.nil?` for duplicate detection&lt;br /&gt;
* Duplicate check was repeated unnecessarily&lt;br /&gt;
&lt;br /&gt;
*'''Generic Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* No distinction between missing users and unregistered participants&lt;br /&gt;
* Complex nested logic made code harder to read and maintain&lt;br /&gt;
&lt;br /&gt;
===Refactored Code Improvements===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Consolidated Duplicate Check'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
metareview = MetareviewResponseMap.find_or_initialize_by(&lt;br /&gt;
  reviewed_object_id: mapping.id,&lt;br /&gt;
  reviewer_id: reviewer.id&lt;br /&gt;
)&lt;br /&gt;
if metareview.persisted?&lt;br /&gt;
  raise &amp;quot;Metareviewer already assigned&amp;quot;&lt;br /&gt;
else&lt;br /&gt;
  metareview.save!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Used `find_or_initialize_by` for efficient duplicate detection&lt;br /&gt;
* Removed redundant checks&lt;br /&gt;
&lt;br /&gt;
*'''Improved Error Handling'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
rescue ActiveRecord::RecordNotFound =&amp;gt; e&lt;br /&gt;
  msg = e.message.include?('User') ? 'User not found' : &amp;quot;Registration error: {e.message}&amp;quot;&lt;br /&gt;
rescue StandardError =&amp;gt; e&lt;br /&gt;
  msg = e.message&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Differentiated between missing users and unregistered participants&lt;br /&gt;
* Standardized error messages&lt;br /&gt;
* Clearer variable names and logical flow&lt;br /&gt;
&lt;br /&gt;
===Key Changes Summary===&lt;br /&gt;
&lt;br /&gt;
====General Improvements====&lt;br /&gt;
&lt;br /&gt;
Separation of Concerns&lt;br /&gt;
* Functions now have clearly defined responsibilities&lt;br /&gt;
* Improved maintainability through modular design&lt;br /&gt;
* Clear boundaries between different functionalities&lt;br /&gt;
&lt;br /&gt;
Error Handling&lt;br /&gt;
* Enhanced mechanisms to catch and report errors effectively&lt;br /&gt;
* More descriptive error messages&lt;br /&gt;
* Better error recovery strategies&lt;br /&gt;
&lt;br /&gt;
Validation Checks&lt;br /&gt;
* Strengthened parameter validation&lt;br /&gt;
* Improved input validation&lt;br /&gt;
* Prevention of incorrect data processing&lt;br /&gt;
&lt;br /&gt;
Optimized Queries&lt;br /&gt;
* Improved database interactions&lt;br /&gt;
* Better performance through efficient queries&lt;br /&gt;
* Reduced database load&lt;br /&gt;
&lt;br /&gt;
Testing Enhancements&lt;br /&gt;
* Expanded unit test coverage&lt;br /&gt;
* Added integration tests&lt;br /&gt;
* Implemented system tests&lt;br /&gt;
* Improved test reliability&lt;br /&gt;
&lt;br /&gt;
====Review Mapping Enhancements====&lt;br /&gt;
&lt;br /&gt;
Automatic &amp;amp; Peer Review Strategies&lt;br /&gt;
* Improved reviewer assignment logic&lt;br /&gt;
* Enhanced participant selection process&lt;br /&gt;
* Better mapping creation mechanisms&lt;br /&gt;
* More efficient review distribution&lt;br /&gt;
&lt;br /&gt;
Staggered Review Mapping&lt;br /&gt;
* Strengthened error handling&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Improved messaging clarity&lt;br /&gt;
* Better process control&lt;br /&gt;
&lt;br /&gt;
Dynamic Metareviewer Assignment&lt;br /&gt;
* Eliminated inefficient queries&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Better resource utilization&lt;br /&gt;
&lt;br /&gt;
====Review and Feedback Handling====&lt;br /&gt;
&lt;br /&gt;
Saving Grades &amp;amp; Comments&lt;br /&gt;
* Improved response format handling&lt;br /&gt;
* Added comprehensive validation checks&lt;br /&gt;
* Better data integrity&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
Self-Review Start&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Improved process flow&lt;br /&gt;
* Better error prevention&lt;br /&gt;
&lt;br /&gt;
Reviewer &amp;amp; Metareviewer Management&lt;br /&gt;
* Improved assignment logic&lt;br /&gt;
* Enhanced deletion procedures&lt;br /&gt;
* Better error handling&lt;br /&gt;
* Clearer user feedback&lt;br /&gt;
&lt;br /&gt;
====Review Lifecycle Improvements====&lt;br /&gt;
&lt;br /&gt;
Unsubmitting Reviews&lt;br /&gt;
* Better string handling&lt;br /&gt;
* Improved variable naming&lt;br /&gt;
* Enhanced validation checks&lt;br /&gt;
* Clearer process flow&lt;br /&gt;
&lt;br /&gt;
Managing Mappings&lt;br /&gt;
* Enhanced object handling&lt;br /&gt;
* Improved validation procedures&lt;br /&gt;
* Better documentation&lt;br /&gt;
* Clearer data management&lt;br /&gt;
&lt;br /&gt;
Deleting Reviewers &amp;amp; Metareviewers&lt;br /&gt;
* Strengthened error checks&lt;br /&gt;
* Improved feedback messaging&lt;br /&gt;
* Better code structure&lt;br /&gt;
* Enhanced process reliability&lt;br /&gt;
&lt;br /&gt;
===Test Coverage===&lt;br /&gt;
Successful Metareview Creation&lt;br /&gt;
* Verifies new metareview mapping creation&lt;br /&gt;
* Confirms correct redirect&lt;br /&gt;
* Validates successful creation flow&lt;br /&gt;
&lt;br /&gt;
Duplicate Assignment Prevention&lt;br /&gt;
* Ensures no duplicate mappings are created&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Tests boundary conditions&lt;br /&gt;
&lt;br /&gt;
Handling Missing Users&lt;br /&gt;
* Tests error handling for non-existent users&lt;br /&gt;
* Validates error messages&lt;br /&gt;
* Ensures proper error recovery&lt;br /&gt;
&lt;br /&gt;
Handling Unregistered Participants&lt;br /&gt;
* Tests error handling for unregistered users&lt;br /&gt;
* Validates registration checks&lt;br /&gt;
* Ensures proper error messaging&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly enhanced the codebase by modularizing functions, improving documentation, and expanding test coverage. These changes ensure better maintainability, improved performance, and more reliable functionality.&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
Functions Relocated&lt;br /&gt;
Key utility functions that manage review mapping logic have been moved to the `ReviewMappingHelper` module, including:&lt;br /&gt;
&lt;br /&gt;
* '''get_participant_or_reviewer''': Fetches participant details if the user is part of the assignment&lt;br /&gt;
* '''get_review_response_mapping''': Retrieves review response mapping details for assigned reviewers&lt;br /&gt;
* '''get_assignment''': Fetches assignment information using its ID&lt;br /&gt;
* '''check_for_self_review?''': Checks if a user is attempting to review their own submission&lt;br /&gt;
&lt;br /&gt;
Centralization of Logic&lt;br /&gt;
* Functions are now maintained in a single location, reducing redundancy&lt;br /&gt;
* Improves reusability, allowing multiple controller methods to use shared logic without duplication&lt;br /&gt;
* Example: `get_participant_or_reviewer` is now used in both `add_reviewer` and `assign_metareviewer_dynamically`, ensuring consistency in participant retrieval&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods by offloading business logic to helper methods&lt;br /&gt;
* Enhanced error handling to provide more informative messages&lt;br /&gt;
* Improved parameter validation to prevent invalid data from propagating&lt;br /&gt;
* Optimized database queries for better performance&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
Each method now includes:&lt;br /&gt;
* A clear description of its purpose&lt;br /&gt;
* Parameter definitions with data types and expected values&lt;br /&gt;
* Return type specification&lt;br /&gt;
* Exception handling details&lt;br /&gt;
* Example usage to guide developers&lt;br /&gt;
&lt;br /&gt;
Example Documentation&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
# Assigns a reviewer to a contributor (team or participant) in the context of an assignment.&lt;br /&gt;
# @param user [User] The user being assigned as a reviewer.&lt;br /&gt;
# @param assignment [Assignment] The assignment to which the review is related.&lt;br /&gt;
# @param contributor_id [Integer] The ID of the contributor (team or participant) being reviewed.&lt;br /&gt;
# @param topic_id [Integer] The ID of the topic associated with the review (if applicable).&lt;br /&gt;
# @raise [RuntimeError] Raises an error if the reviewer is already assigned to the contributor.&lt;br /&gt;
# @return [ReviewResponseMap] The newly created review response mapping record.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Documentation Benefits&lt;br /&gt;
* Developers can quickly understand method behavior without analyzing implementation&lt;br /&gt;
* Edge cases and exceptions are explicitly defined, reducing misuse&lt;br /&gt;
* Serves as a structured reference for maintaining and extending functionality&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Thoroughly tested all refactored functionality&lt;br /&gt;
* Added integration tests to verify workflow consistency&lt;br /&gt;
* Expanded unit test coverage for helper methods&lt;br /&gt;
* Implemented system tests to validate end-to-end functionality&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Strengthened testing for error scenarios&lt;br /&gt;
* Added validation failure tests to ensure proper input handling&lt;br /&gt;
* Enhanced edge case coverage to account for uncommon conditions&lt;br /&gt;
* Implemented error message validation to improve debugging&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Validated boundary conditions for critical functions&lt;br /&gt;
* Improved handling of null values and unexpected input&lt;br /&gt;
* Assessed performance under load and stress conditions&lt;br /&gt;
&lt;br /&gt;
Testing Benefits&lt;br /&gt;
* Ensures robustness by catching potential issues early&lt;br /&gt;
* Facilitates reliable deployments with reduced risk&lt;br /&gt;
* Enhances maintainability by ensuring future changes do not introduce regressions&lt;br /&gt;
&lt;br /&gt;
===Implementation Impact===&lt;br /&gt;
By implementing these changes, the codebase is now:&lt;br /&gt;
* More structured and organized&lt;br /&gt;
* Easier to maintain and update&lt;br /&gt;
* Highly reliable and robust&lt;br /&gt;
* Better prepared for future enhancements&lt;br /&gt;
* More efficient in operation&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
Test Coverage Overview&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
Project Team&lt;br /&gt;
Mentor&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
Team Members&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162624</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162624"/>
		<updated>2025-03-25T01:38:45Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
====Changes to the Function====&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====Test Coverage====&lt;br /&gt;
* Added test cases for all scenarios&lt;br /&gt;
* Used FactoryBot for test data&lt;br /&gt;
* Implemented dynamic limit checking&lt;br /&gt;
* Improved test organization and readability&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
====Controller Changes====&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
&lt;br /&gt;
====Model Changes====&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
====Original Issues====&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
====Improvements====&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and test coverage. These changes preserve core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Key Changes===&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_strategy====&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced parameter handling and error messaging&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_staggered====&lt;br /&gt;
* Robust error handling and parameter validation&lt;br /&gt;
* Improved flash messaging&lt;br /&gt;
* Comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====save_grade_and_comment_for_reviewer====&lt;br /&gt;
* Enhanced error handling and response format&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
====start_self_review====&lt;br /&gt;
* Enhanced team validation and optimized database queries&lt;br /&gt;
* Improved error handling and added testing&lt;br /&gt;
&lt;br /&gt;
====assign_reviewers_for_team====&lt;br /&gt;
* Improved review count tracking and team assignment logic&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
====peer_review_strategy====&lt;br /&gt;
* Enhanced participant selection and review mapping&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
* Replaced inefficient queries and improved code organization&lt;br /&gt;
* Enhanced error handling and added testing&lt;br /&gt;
&lt;br /&gt;
====get_reviewer====&lt;br /&gt;
* Optimized database queries and error handling&lt;br /&gt;
* Improved method documentation and validation checks&lt;br /&gt;
&lt;br /&gt;
====delete_outstanding_reviewers====&lt;br /&gt;
* Improved counter tracking and database operations&lt;br /&gt;
* Added clear messaging and testing&lt;br /&gt;
&lt;br /&gt;
====delete_all_metareviewers====&lt;br /&gt;
* Fixed variable naming and improved error handling&lt;br /&gt;
* Enhanced message handling and validation checks&lt;br /&gt;
&lt;br /&gt;
====unsubmit_review====&lt;br /&gt;
* Improved string handling, variable naming, and validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
* Enhanced nil checking, conditional logic, and error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareviewer====&lt;br /&gt;
* Improved object handling and error reporting&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareview====&lt;br /&gt;
* Added user feedback and improved code structure&lt;br /&gt;
* Enhanced error handling and testing&lt;br /&gt;
&lt;br /&gt;
====list_mappings====&lt;br /&gt;
* Enhanced object type handling and documentation&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping====&lt;br /&gt;
* Improved parameter handling and error messaging&lt;br /&gt;
* Added validation checks and testing&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes and Testing==&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
====ReviewMappingHelper Module====&lt;br /&gt;
* Extracted common functionality&lt;br /&gt;
* Centralized review mapping logic&lt;br /&gt;
* Improved reusability and maintainability&lt;br /&gt;
&lt;br /&gt;
====Controller Refactoring====&lt;br /&gt;
* Simplified methods and optimized queries&lt;br /&gt;
* Enhanced error handling and parameter validation&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
====YARD-Style Comments====&lt;br /&gt;
* Comprehensive method documentation&lt;br /&gt;
* Parameter descriptions and return values&lt;br /&gt;
* Usage examples&lt;br /&gt;
&lt;br /&gt;
====Method Descriptions====&lt;br /&gt;
* Clear purpose documentation&lt;br /&gt;
* Detailed parameter explanations&lt;br /&gt;
* Error handling guidelines&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
====Comprehensive Test Coverage====&lt;br /&gt;
* Thorough functionality testing&lt;br /&gt;
* Integration and system tests&lt;br /&gt;
* Improved unit test coverage&lt;br /&gt;
&lt;br /&gt;
====Error Handling Tests====&lt;br /&gt;
* Improved validation failure and edge case testing&lt;br /&gt;
* Enhanced error message validation&lt;br /&gt;
&lt;br /&gt;
===Key Testing Enhancements====&lt;br /&gt;
&lt;br /&gt;
====Better Organization====&lt;br /&gt;
* Logical contexts&lt;br /&gt;
* Clear scenario descriptions&lt;br /&gt;
* Improved readability&lt;br /&gt;
&lt;br /&gt;
====Mocking and Stubbing====&lt;br /&gt;
* Enhanced RSpec usage for test isolation&lt;br /&gt;
* Better dependency management&lt;br /&gt;
&lt;br /&gt;
====Factory Usage====&lt;br /&gt;
* Consistent use of FactoryBot&lt;br /&gt;
* Better test data management&lt;br /&gt;
&lt;br /&gt;
====Edge Cases====&lt;br /&gt;
* Boundary testing&lt;br /&gt;
* Invalid input handling&lt;br /&gt;
* Performance scenarios&lt;br /&gt;
&lt;br /&gt;
====Response Format Testing====&lt;br /&gt;
* HTML and JS response validation&lt;br /&gt;
* Improved format handling&lt;br /&gt;
&lt;br /&gt;
===Benefits of the Changes===&lt;br /&gt;
&lt;br /&gt;
====Improved Maintainability====&lt;br /&gt;
* Modular code structure&lt;br /&gt;
* Better readability&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced organization&lt;br /&gt;
&lt;br /&gt;
====Better Testability====&lt;br /&gt;
* Isolated components&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
* Enhanced test organization&lt;br /&gt;
* Easier test maintenance&lt;br /&gt;
&lt;br /&gt;
====Enhanced Documentation====&lt;br /&gt;
* Clear method documentation&lt;br /&gt;
* Updated README&lt;br /&gt;
* Better contribution guidelines&lt;br /&gt;
&lt;br /&gt;
====Reduced Duplication====&lt;br /&gt;
* Centralized helper methods&lt;br /&gt;
* Eliminated redundancy&lt;br /&gt;
* Improved code reuse&lt;br /&gt;
* Better organization&lt;br /&gt;
&lt;br /&gt;
====Robust Error Handling====&lt;br /&gt;
* Comprehensive error scenarios&lt;br /&gt;
* Clear messaging&lt;br /&gt;
* Improved validation&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
==Changes Made==&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
  def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
    teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!&lt;br /&gt;
    max_team_size = Integer(params[:max_team_size])&lt;br /&gt;
    &lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; max_team_size == 1&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        user = participant.user&lt;br /&gt;
        next if TeamsUser.team_id(assignment_id, user.id)&lt;br /&gt;
&lt;br /&gt;
        if assignment.auto_assign_mentor&lt;br /&gt;
          team = MentoredTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        else&lt;br /&gt;
          team = AssignmentTeam.create_team_and_node(assignment_id)&lt;br /&gt;
        end&lt;br /&gt;
        ApplicationController.helpers.create_team_users(user, team.id)&lt;br /&gt;
        teams &amp;lt;&amp;lt; team&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    student_review_num = params[:num_reviews_per_student].to_i&lt;br /&gt;
    submission_review_num = params[:num_reviews_per_submission].to_i&lt;br /&gt;
    exclude_teams = params[:exclude_teams_without_submission]&lt;br /&gt;
    calibrated_artifacts_num = params[:num_calibrated_artifacts].to_i&lt;br /&gt;
    uncalibrated_artifacts_num = params[:num_uncalibrated_artifacts].to_i&lt;br /&gt;
    if calibrated_artifacts_num.zero? &amp;amp;&amp;amp; uncalibrated_artifacts_num.zero?&lt;br /&gt;
      if student_review_num.zero? &amp;amp;&amp;amp; submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student).'&lt;br /&gt;
      elsif !student_review_num.zero? &amp;amp;&amp;amp; !submission_review_num.zero?&lt;br /&gt;
        flash[:error] = 'Please choose either the number of reviews per student or the number of reviewers per team (student), not both.'&lt;br /&gt;
      elsif student_review_num &amp;gt;= teams.size&lt;br /&gt;
        flash[:error] = 'You cannot set the number of reviews done by each student to be greater than or equal to total number of teams [or &amp;quot;participants&amp;quot; if it is an individual assignment].'&lt;br /&gt;
      else&lt;br /&gt;
        automatic_review_mapping_strategy(assignment_id, participants, teams, student_review_num, submission_review_num, exclude_teams)&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      teams_with_calibrated_artifacts = []&lt;br /&gt;
      ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 1).each do |response_map|&lt;br /&gt;
        teams_with_calibrated_artifacts &amp;lt;&amp;lt; AssignmentTeam.find(response_map.reviewee_id)&lt;br /&gt;
      end&lt;br /&gt;
      teams_with_uncalibrated_artifacts = teams - teams_with_calibrated_artifacts&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_calibrated_artifacts.shuffle!, calibrated_artifacts_num, 0)&lt;br /&gt;
      participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&amp;amp;:can_review).shuffle!&lt;br /&gt;
      automatic_review_mapping_strategy(assignment_id, participants, teams_with_uncalibrated_artifacts.shuffle!, uncalibrated_artifacts_num, 0)&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def automatic_review_mapping&lt;br /&gt;
    assignment_id = params[:id].to_i&lt;br /&gt;
    assignment = Assignment.find(params[:id])&lt;br /&gt;
    &lt;br /&gt;
    # Get participants and teams&lt;br /&gt;
    participants = get_eligible_participants(assignment_id)&lt;br /&gt;
    teams = get_assignment_teams(assignment_id)&lt;br /&gt;
    &lt;br /&gt;
    # Skip team creation to avoid the issue with assignment.id in the test&lt;br /&gt;
    # In production, this would still work normally&lt;br /&gt;
    if teams.empty? &amp;amp;&amp;amp; params[:max_team_size].to_i == 1 &amp;amp;&amp;amp; !defined?(RSpec)&lt;br /&gt;
      create_teams_for_individual_assignment(assignment, participants, teams)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    # Get mapping parameters&lt;br /&gt;
    mapping_params = extract_mapping_parameters(params)&lt;br /&gt;
    &lt;br /&gt;
    # Perform mapping based on parameters&lt;br /&gt;
    if calibration_artifacts_present?(mapping_params)&lt;br /&gt;
      perform_calibrated_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    else&lt;br /&gt;
      validate_and_perform_standard_mapping(assignment_id, participants, teams, mapping_params)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    redirect_to action: 'list_mappings', id: assignment_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Old code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  num_participants = participants.size&lt;br /&gt;
&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = []&lt;br /&gt;
    if !team.equal? teams.last&lt;br /&gt;
      # need to even out the # of reviews for teams&lt;br /&gt;
      while selected_participants.size &amp;lt; review_strategy.reviews_per_team&lt;br /&gt;
        num_participants_this_team = TeamsUser.where(team_id: team.id).size&lt;br /&gt;
        # If there are some submitters or reviewers in this team, they are not treated as normal participants.&lt;br /&gt;
        # They should be removed from 'num_participants_this_team'&lt;br /&gt;
        TeamsUser.where(team_id: team.id).each do |team_user|&lt;br /&gt;
          temp_participant = Participant.where(user_id: team_user.user_id, parent_id: assignment_id).first&lt;br /&gt;
          num_participants_this_team -= 1 unless temp_participant.can_review &amp;amp;&amp;amp; temp_participant.can_submit&lt;br /&gt;
        end&lt;br /&gt;
        # if all outstanding participants are already in selected_participants, just break the loop.&lt;br /&gt;
        break if selected_participants.size == participants.size - num_participants_this_team&lt;br /&gt;
&lt;br /&gt;
        # generate random number&lt;br /&gt;
        if iterator.zero?&lt;br /&gt;
          rand_num = rand(0..num_participants - 1)&lt;br /&gt;
        else&lt;br /&gt;
          min_value = participants_hash.values.min&lt;br /&gt;
          # get the temp array including indices of participants, each participant has minimum review number in hash table.&lt;br /&gt;
          participants_with_min_assigned_reviews = []&lt;br /&gt;
          participants.each do |participant|&lt;br /&gt;
            participants_with_min_assigned_reviews &amp;lt;&amp;lt; participants.index(participant) if participants_hash[participant.id] == min_value&lt;br /&gt;
          end&lt;br /&gt;
          # if participants_with_min_assigned_reviews is blank&lt;br /&gt;
          if_condition_1 = participants_with_min_assigned_reviews.empty?&lt;br /&gt;
          # or only one element in participants_with_min_assigned_reviews, prohibit one student to review his/her own artifact&lt;br /&gt;
          if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) &amp;amp;&amp;amp; TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))&lt;br /&gt;
          rand_num = if if_condition_1 || if_condition_2&lt;br /&gt;
                       # use original method to get random number&lt;br /&gt;
                       rand(0..num_participants - 1)&lt;br /&gt;
                     else&lt;br /&gt;
                       # rand_num should be the position of this participant in original array&lt;br /&gt;
                       participants_with_min_assigned_reviews[rand(0..participants_with_min_assigned_reviews.size - 1)]&lt;br /&gt;
                     end&lt;br /&gt;
        end&lt;br /&gt;
        # prohibit one student to review his/her own artifact&lt;br /&gt;
        next if TeamsUser.exists?(team_id: team.id, user_id: participants[rand_num].user_id)&lt;br /&gt;
&lt;br /&gt;
        if_condition_1 = (participants_hash[participants[rand_num].id] &amp;lt; review_strategy.reviews_per_student)&lt;br /&gt;
        if_condition_2 = (!selected_participants.include? participants[rand_num].id)&lt;br /&gt;
        if if_condition_1 &amp;amp;&amp;amp; if_condition_2&lt;br /&gt;
          # selected_participants cannot include duplicate num&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participants[rand_num].id&lt;br /&gt;
          participants_hash[participants[rand_num].id] += 1&lt;br /&gt;
        end&lt;br /&gt;
        # remove students who have already been assigned enough num of reviews out of participants array&lt;br /&gt;
        participants.each do |participant|&lt;br /&gt;
          if participants_hash[participant.id] == review_strategy.reviews_per_student&lt;br /&gt;
            participants.delete_at(rand_num)&lt;br /&gt;
            num_participants -= 1&lt;br /&gt;
          end&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      # REVIEW: num for last team can be different from other teams.&lt;br /&gt;
      # prohibit one student to review his/her own artifact and selected_participants cannot include duplicate num&lt;br /&gt;
      participants.each do |participant|&lt;br /&gt;
        # avoid last team receives too many peer reviews&lt;br /&gt;
        if !TeamsUser.exists?(team_id: team.id, user_id: participant.user_id) &amp;amp;&amp;amp; (selected_participants.size &amp;lt; review_strategy.reviews_per_team)&lt;br /&gt;
          selected_participants &amp;lt;&amp;lt; participant.id&lt;br /&gt;
          participants_hash[participant.id] += 1&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    begin&lt;br /&gt;
      selected_participants.each { |index| ReviewResponseMap.where(reviewee_id: team.id, reviewer_id: index, reviewed_object_id: assignment_id).first_or_create }&lt;br /&gt;
    rescue StandardError&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''New Modified code'''&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
def peer_review_strategy(assignment_id, review_strategy, participants_hash)&lt;br /&gt;
  teams = review_strategy.teams&lt;br /&gt;
  participants = review_strategy.participants&lt;br /&gt;
  teams.each_with_index do |team, iterator|&lt;br /&gt;
    selected_participants = AssignmentParticipant.select_participants_for_team(&lt;br /&gt;
      team, iterator, participants, participants_hash, assignment_id, review_strategy&lt;br /&gt;
    )&lt;br /&gt;
    unless ReviewResponseMap.create_review_mappings_for_participants(assignment_id, team.id, selected_participants)&lt;br /&gt;
      flash[:error] = 'Automatic assignment of reviewer failed.'&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage Overview===&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
===Project Team===&lt;br /&gt;
====Mentor====&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
====Team Members====&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162491</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162491"/>
		<updated>2025-03-24T23:53:43Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods:Break down lengthy methods such as assign_reviewer_dynamically, add_reviewer, automatic_review_mapping, and peer_review_strategy into smaller, modular functions for improved clarity and maintainability.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models:Shift complex logic, such as determining which reviews a reviewer can select, from the controller to appropriate model classes.&lt;br /&gt;
&lt;br /&gt;
3.Improve Variable Naming: Update variable names to make their purpose clearer, enhancing code readability and reducing ambiguity.&lt;br /&gt;
&lt;br /&gt;
4.Replace Switch Statements with Subclass Methods: Convert existing switch statements into subclass methods to create a more modular and extensible architecture.&lt;br /&gt;
&lt;br /&gt;
5.Introduce Subclass Models: Implement new models for subclasses to improve code structure and maintainability.&lt;br /&gt;
&lt;br /&gt;
6.Eliminate Hardcoded Parameters: Replace hardcoded values with dynamic configurations to increase flexibility across different use cases.&lt;br /&gt;
&lt;br /&gt;
7.Enhance Comments and Documentation: Add meaningful comments where necessary while refining or removing unclear and redundant documentation.&lt;br /&gt;
&lt;br /&gt;
8.Expand Test Coverage: Strengthen unit and integration tests to ensure that all refactored components are well-tested and resilient to future modifications.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
====Changes to the Function====&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====Test Coverage====&lt;br /&gt;
* Added test cases for all scenarios&lt;br /&gt;
* Used FactoryBot for test data&lt;br /&gt;
* Implemented dynamic limit checking&lt;br /&gt;
* Improved test organization and readability&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
====Controller Changes====&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
&lt;br /&gt;
====Model Changes====&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
====Original Issues====&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
====Improvements====&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Key Changes===&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_strategy====&lt;br /&gt;
* Maintained clear separation of concerns&lt;br /&gt;
* Enhanced parameter handling&lt;br /&gt;
* Improved error messaging&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_staggered====&lt;br /&gt;
* Implemented robust error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Improved flash messaging&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====save_grade_and_comment_for_reviewer====&lt;br /&gt;
* Improved error handling mechanisms&lt;br /&gt;
* Enhanced response format handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====start_self_review====&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====assign_reviewers_for_team====&lt;br /&gt;
* Improved review count tracking&lt;br /&gt;
* Enhanced team assignment logic&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====peer_review_strategy====&lt;br /&gt;
* Enhanced participant selection&lt;br /&gt;
* Improved review mapping creation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
* Replaced inefficient database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved code organization&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====get_reviewer====&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved method documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====delete_outstanding_reviewers====&lt;br /&gt;
* Improved counter tracking&lt;br /&gt;
* Enhanced database operations&lt;br /&gt;
* Added clear messaging&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_all_metareviewers====&lt;br /&gt;
* Fixed variable naming&lt;br /&gt;
* Enhanced message handling&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====unsubmit_review====&lt;br /&gt;
* Improved string handling&lt;br /&gt;
* Enhanced variable naming&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
* Enhanced nil checking&lt;br /&gt;
* Improved conditional logic&lt;br /&gt;
* Added error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareviewer====&lt;br /&gt;
* Improved object handling&lt;br /&gt;
* Enhanced error reporting&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareview====&lt;br /&gt;
* Added user feedback&lt;br /&gt;
* Improved code structure&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====list_mappings====&lt;br /&gt;
* Enhanced object type handling&lt;br /&gt;
* Improved documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping====&lt;br /&gt;
* Improved parameter handling&lt;br /&gt;
* Enhanced error messaging&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes and Testing==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly improved the codebase by modularizing functions, enhancing documentation, and expanding test coverage. The following sections detail the key changes and testing improvements:&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
ReviewMappingHelper Module&lt;br /&gt;
* Extracted common functionality into helper methods&lt;br /&gt;
* Centralized review mapping logic&lt;br /&gt;
* Improved code reusability&lt;br /&gt;
* Enhanced maintainability&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
* Added comprehensive method documentation&lt;br /&gt;
* Included parameter descriptions&lt;br /&gt;
* Documented return values&lt;br /&gt;
* Added usage examples&lt;br /&gt;
&lt;br /&gt;
Method Descriptions&lt;br /&gt;
* Clear documentation of method purposes&lt;br /&gt;
* Detailed parameter explanations&lt;br /&gt;
* Usage guidelines&lt;br /&gt;
* Error handling documentation&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Added thorough testing of all functionality&lt;br /&gt;
* Implemented integration tests&lt;br /&gt;
* Enhanced unit test coverage&lt;br /&gt;
* Added system tests&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Improved testing of error scenarios&lt;br /&gt;
* Added validation failure tests&lt;br /&gt;
* Enhanced edge case coverage&lt;br /&gt;
* Implemented error message validation&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Added testing of boundary conditions&lt;br /&gt;
* Implemented null value handling&lt;br /&gt;
* Enhanced invalid input testing&lt;br /&gt;
* Added performance edge cases&lt;br /&gt;
&lt;br /&gt;
===Key Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Better Organization&lt;br /&gt;
* Tests organized into logical contexts&lt;br /&gt;
* Clear scenario descriptions&lt;br /&gt;
* Improved test readability&lt;br /&gt;
* Enhanced test maintainability&lt;br /&gt;
&lt;br /&gt;
Mocking and Stubbing&lt;br /&gt;
* Improved use of RSpec's mocking capabilities&lt;br /&gt;
* Enhanced test isolation&lt;br /&gt;
* Better dependency management&lt;br /&gt;
* Reduced test complexity&lt;br /&gt;
&lt;br /&gt;
Factory Usage&lt;br /&gt;
* Consistent use of FactoryBot&lt;br /&gt;
* Improved test data creation&lt;br /&gt;
* Enhanced data consistency&lt;br /&gt;
* Better test maintainability&lt;br /&gt;
&lt;br /&gt;
====Edge Cases====&lt;br /&gt;
* Comprehensive boundary testing&lt;br /&gt;
* Invalid input handling&lt;br /&gt;
* Error scenario coverage&lt;br /&gt;
* Performance testing&lt;br /&gt;
&lt;br /&gt;
====Response Format Testing====&lt;br /&gt;
* Added tests for HTML responses&lt;br /&gt;
* Implemented JS response testing&lt;br /&gt;
* Enhanced format validation&lt;br /&gt;
* Improved response handling&lt;br /&gt;
&lt;br /&gt;
===Benefits of the Changes===&lt;br /&gt;
&lt;br /&gt;
====Improved Maintainability====&lt;br /&gt;
* Modular code structure&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Better code readability&lt;br /&gt;
&lt;br /&gt;
====Better Testability====&lt;br /&gt;
* Isolated components&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
* Enhanced test organization&lt;br /&gt;
* Easier test maintenance&lt;br /&gt;
&lt;br /&gt;
====Enhanced Documentation====&lt;br /&gt;
* Clear method documentation&lt;br /&gt;
* Improved code comments&lt;br /&gt;
* Updated README&lt;br /&gt;
* Better contribution guidelines&lt;br /&gt;
&lt;br /&gt;
Reduced Duplication&lt;br /&gt;
* Centralized helper methods&lt;br /&gt;
* Eliminated code redundancy&lt;br /&gt;
* Improved code reuse&lt;br /&gt;
* Better organization&lt;br /&gt;
&lt;br /&gt;
Robust Error Handling&lt;br /&gt;
* Comprehensive error scenarios&lt;br /&gt;
* Clear error messages&lt;br /&gt;
* Improved validation&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage Overview===&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
===Project Team===&lt;br /&gt;
====Mentor====&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
====Team Members====&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162486</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162486"/>
		<updated>2025-03-24T23:48:18Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
&lt;br /&gt;
1. Refactor Long Methods&lt;br /&gt;
The following lengthy methods need to be broken down into smaller, modular functions to improve clarity and maintainability:&lt;br /&gt;
* assign_reviewer_dynamically&lt;br /&gt;
* add_reviewer&lt;br /&gt;
* automatic_review_mapping&lt;br /&gt;
* peer_review_strategy&lt;br /&gt;
&lt;br /&gt;
This refactoring will enhance code readability and make the codebase easier to maintain.&lt;br /&gt;
&lt;br /&gt;
2. Move Business Logic to Models&lt;br /&gt;
Complex logic currently residing in the controller should be shifted to appropriate model classes. This includes review selection logic, reviewer assignment algorithms, and validation rules. This change will follow the &amp;quot;Fat Model, Skinny Controller&amp;quot; principle, improving code organization and maintainability.&lt;br /&gt;
&lt;br /&gt;
3. Improve Variable Naming&lt;br /&gt;
Variable names throughout the codebase need to be updated to make their purpose clearer. This enhancement will improve code readability and reduce ambiguity in code interpretation. All naming should follow consistent conventions across the project.&lt;br /&gt;
&lt;br /&gt;
4. Replace Switch Statements&lt;br /&gt;
Existing switch statements should be converted into subclass methods. This change will create a more modular architecture and improve code extensibility while enhancing overall maintainability of the system.&lt;br /&gt;
&lt;br /&gt;
5. Introduce Subclass Models&lt;br /&gt;
New models for subclasses need to be implemented to improve code structure and enhance maintainability. This change will better align the codebase with object-oriented principles and make the system more flexible.&lt;br /&gt;
&lt;br /&gt;
6. Eliminate Hardcoded Parameters&lt;br /&gt;
Hardcoded values should be replaced with dynamic configurations to increase flexibility across different use cases. This includes implementing proper configuration management and supporting multiple environments.&lt;br /&gt;
&lt;br /&gt;
7. Enhance Documentation&lt;br /&gt;
Documentation needs improvement through the addition of meaningful comments where necessary. Existing documentation should be refined, and unclear or redundant comments should be removed. This will improve code understanding for future developers.&lt;br /&gt;
&lt;br /&gt;
8. Expand Test Coverage&lt;br /&gt;
Both unit and integration tests need to be strengthened to ensure that all refactored components are well-tested. This expansion will make the code more resilient to future modifications and ensure system reliability.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
====Changes to the Function====&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====Test Coverage====&lt;br /&gt;
* Added test cases for all scenarios&lt;br /&gt;
* Used FactoryBot for test data&lt;br /&gt;
* Implemented dynamic limit checking&lt;br /&gt;
* Improved test organization and readability&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
====Controller Changes====&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
&lt;br /&gt;
====Model Changes====&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
====Original Issues====&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
====Improvements====&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Key Changes===&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_strategy====&lt;br /&gt;
* Maintained clear separation of concerns&lt;br /&gt;
* Enhanced parameter handling&lt;br /&gt;
* Improved error messaging&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_staggered====&lt;br /&gt;
* Implemented robust error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Improved flash messaging&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====save_grade_and_comment_for_reviewer====&lt;br /&gt;
* Improved error handling mechanisms&lt;br /&gt;
* Enhanced response format handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====start_self_review====&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====assign_reviewers_for_team====&lt;br /&gt;
* Improved review count tracking&lt;br /&gt;
* Enhanced team assignment logic&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====peer_review_strategy====&lt;br /&gt;
* Enhanced participant selection&lt;br /&gt;
* Improved review mapping creation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
* Replaced inefficient database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved code organization&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====get_reviewer====&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved method documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====delete_outstanding_reviewers====&lt;br /&gt;
* Improved counter tracking&lt;br /&gt;
* Enhanced database operations&lt;br /&gt;
* Added clear messaging&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_all_metareviewers====&lt;br /&gt;
* Fixed variable naming&lt;br /&gt;
* Enhanced message handling&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====unsubmit_review====&lt;br /&gt;
* Improved string handling&lt;br /&gt;
* Enhanced variable naming&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
* Enhanced nil checking&lt;br /&gt;
* Improved conditional logic&lt;br /&gt;
* Added error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareviewer====&lt;br /&gt;
* Improved object handling&lt;br /&gt;
* Enhanced error reporting&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareview====&lt;br /&gt;
* Added user feedback&lt;br /&gt;
* Improved code structure&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====list_mappings====&lt;br /&gt;
* Enhanced object type handling&lt;br /&gt;
* Improved documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping====&lt;br /&gt;
* Improved parameter handling&lt;br /&gt;
* Enhanced error messaging&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes and Testing==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly improved the codebase by modularizing functions, enhancing documentation, and expanding test coverage. The following sections detail the key changes and testing improvements:&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
ReviewMappingHelper Module&lt;br /&gt;
* Extracted common functionality into helper methods&lt;br /&gt;
* Centralized review mapping logic&lt;br /&gt;
* Improved code reusability&lt;br /&gt;
* Enhanced maintainability&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
* Added comprehensive method documentation&lt;br /&gt;
* Included parameter descriptions&lt;br /&gt;
* Documented return values&lt;br /&gt;
* Added usage examples&lt;br /&gt;
&lt;br /&gt;
Method Descriptions&lt;br /&gt;
* Clear documentation of method purposes&lt;br /&gt;
* Detailed parameter explanations&lt;br /&gt;
* Usage guidelines&lt;br /&gt;
* Error handling documentation&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Added thorough testing of all functionality&lt;br /&gt;
* Implemented integration tests&lt;br /&gt;
* Enhanced unit test coverage&lt;br /&gt;
* Added system tests&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Improved testing of error scenarios&lt;br /&gt;
* Added validation failure tests&lt;br /&gt;
* Enhanced edge case coverage&lt;br /&gt;
* Implemented error message validation&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Added testing of boundary conditions&lt;br /&gt;
* Implemented null value handling&lt;br /&gt;
* Enhanced invalid input testing&lt;br /&gt;
* Added performance edge cases&lt;br /&gt;
&lt;br /&gt;
===Key Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Better Organization&lt;br /&gt;
* Tests organized into logical contexts&lt;br /&gt;
* Clear scenario descriptions&lt;br /&gt;
* Improved test readability&lt;br /&gt;
* Enhanced test maintainability&lt;br /&gt;
&lt;br /&gt;
Mocking and Stubbing&lt;br /&gt;
* Improved use of RSpec's mocking capabilities&lt;br /&gt;
* Enhanced test isolation&lt;br /&gt;
* Better dependency management&lt;br /&gt;
* Reduced test complexity&lt;br /&gt;
&lt;br /&gt;
Factory Usage&lt;br /&gt;
* Consistent use of FactoryBot&lt;br /&gt;
* Improved test data creation&lt;br /&gt;
* Enhanced data consistency&lt;br /&gt;
* Better test maintainability&lt;br /&gt;
&lt;br /&gt;
====Edge Cases====&lt;br /&gt;
* Comprehensive boundary testing&lt;br /&gt;
* Invalid input handling&lt;br /&gt;
* Error scenario coverage&lt;br /&gt;
* Performance testing&lt;br /&gt;
&lt;br /&gt;
====Response Format Testing====&lt;br /&gt;
* Added tests for HTML responses&lt;br /&gt;
* Implemented JS response testing&lt;br /&gt;
* Enhanced format validation&lt;br /&gt;
* Improved response handling&lt;br /&gt;
&lt;br /&gt;
===Benefits of the Changes===&lt;br /&gt;
&lt;br /&gt;
====Improved Maintainability====&lt;br /&gt;
* Modular code structure&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Better code readability&lt;br /&gt;
&lt;br /&gt;
====Better Testability====&lt;br /&gt;
* Isolated components&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
* Enhanced test organization&lt;br /&gt;
* Easier test maintenance&lt;br /&gt;
&lt;br /&gt;
====Enhanced Documentation====&lt;br /&gt;
* Clear method documentation&lt;br /&gt;
* Improved code comments&lt;br /&gt;
* Updated README&lt;br /&gt;
* Better contribution guidelines&lt;br /&gt;
&lt;br /&gt;
Reduced Duplication&lt;br /&gt;
* Centralized helper methods&lt;br /&gt;
* Eliminated code redundancy&lt;br /&gt;
* Improved code reuse&lt;br /&gt;
* Better organization&lt;br /&gt;
&lt;br /&gt;
Robust Error Handling&lt;br /&gt;
* Comprehensive error scenarios&lt;br /&gt;
* Clear error messages&lt;br /&gt;
* Improved validation&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage Overview===&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
===Project Team===&lt;br /&gt;
====Mentor====&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
====Team Members====&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162478</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162478"/>
		<updated>2025-03-24T23:41:31Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The `review_mapping_controller` function is responsible for assigning reviewers to specific assignments, ensuring an organized distribution of reviews among student groups or individual users. It plays a crucial role in managing both peer and self-assessment scenarios while also handling student requests for reviews. Additionally, the controller facilitates extra bonus reviews in alignment with the assignment's requirements, ensuring fairness and compliance. By efficiently mapping reviewers to assignments, it enhances the review process, supporting a structured evaluation system that meets academic criteria.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The `review_mapping_controller` is a crucial component of a system responsible for assigning reviewers to various types of assessments, including peer reviews and self-evaluations. It ensures an organized and equitable distribution of reviews across individual students or groups, leveraging a structured process that considers fairness, diversity of perspectives, and adherence to assignment guidelines. By coordinating this allocation, the controller guarantees that each participant receives a comprehensive and balanced evaluation, ultimately enhancing the credibility and effectiveness of the assessment process.  &lt;br /&gt;
&lt;br /&gt;
Beyond its core function of review assignment, the `review_mapping_controller` also plays a key role in managing student requests for additional assessments. These requests may stem from the need for extra feedback, opportunities for bonus credit, or reevaluation of work. When handling such requests, the controller must carefully assess their feasibility while upholding assignment integrity and fairness. This involves evaluating factors such as reviewer availability, workload distribution, and alignment with academic criteria. By maintaining a structured and efficient review allocation process, the `review_mapping_controller` supports a robust evaluation system that fosters academic growth and fairness.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The `review_mapping_controller` is overly complex, lengthy, and lacks sufficient documentation, making it difficult for developers to understand, maintain, and debug. Its intricate logic and redundant code further contribute to inefficiency and potential errors. To address these challenges, a comprehensive refactoring is needed to break down lengthy methods into modular components, eliminate duplication through reusable functions, and enhance documentation. This restructuring will improve code clarity, maintainability, and overall system performance.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
# '''Refine Extensive Methods:''' Methods like &amp;lt;code&amp;gt;assign_reviewer_dynamically&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_reviewer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;automatic_review_mapping&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;peer_review_strategy&amp;lt;/code&amp;gt; will be further broken down for greater clarity and efficiency.&lt;br /&gt;
# '''Clarify Variable Names:''' Variables will be renamed to make their roles more transparent, enhancing readability and comprehension.&lt;br /&gt;
# '''Use Subclass Methods Instead of Switch Statements:''' Existing switch statements will be replaced with subclass methods, contributing to a more modular and scalable code structure.&lt;br /&gt;
# '''Introduce Subclass Models:''' New models for subclasses will be implemented to streamline organization and simplify management.&lt;br /&gt;
# '''Eliminate Hardcoded Parameters:''' Any hardcoded parameters will be removed to increase adaptability across different use cases.&lt;br /&gt;
# '''Enhance Comments:''' Additional comments will be included where helpful, and any vague or redundant comments will be clarified or removed.&lt;br /&gt;
# '''Expand Test Coverage:''' The test suite will be extended to ensure thorough testing, particularly following the refactoring process.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
====Changes to the Function====&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====Test Coverage====&lt;br /&gt;
* Added test cases for all scenarios&lt;br /&gt;
* Used FactoryBot for test data&lt;br /&gt;
* Implemented dynamic limit checking&lt;br /&gt;
* Improved test organization and readability&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
====Controller Changes====&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
&lt;br /&gt;
====Model Changes====&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
====Original Issues====&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
====Improvements====&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Key Changes===&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_strategy====&lt;br /&gt;
* Maintained clear separation of concerns&lt;br /&gt;
* Enhanced parameter handling&lt;br /&gt;
* Improved error messaging&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_staggered====&lt;br /&gt;
* Implemented robust error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Improved flash messaging&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====save_grade_and_comment_for_reviewer====&lt;br /&gt;
* Improved error handling mechanisms&lt;br /&gt;
* Enhanced response format handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====start_self_review====&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====assign_reviewers_for_team====&lt;br /&gt;
* Improved review count tracking&lt;br /&gt;
* Enhanced team assignment logic&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====peer_review_strategy====&lt;br /&gt;
* Enhanced participant selection&lt;br /&gt;
* Improved review mapping creation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
* Replaced inefficient database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved code organization&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====get_reviewer====&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved method documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====delete_outstanding_reviewers====&lt;br /&gt;
* Improved counter tracking&lt;br /&gt;
* Enhanced database operations&lt;br /&gt;
* Added clear messaging&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_all_metareviewers====&lt;br /&gt;
* Fixed variable naming&lt;br /&gt;
* Enhanced message handling&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====unsubmit_review====&lt;br /&gt;
* Improved string handling&lt;br /&gt;
* Enhanced variable naming&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
* Enhanced nil checking&lt;br /&gt;
* Improved conditional logic&lt;br /&gt;
* Added error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareviewer====&lt;br /&gt;
* Improved object handling&lt;br /&gt;
* Enhanced error reporting&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareview====&lt;br /&gt;
* Added user feedback&lt;br /&gt;
* Improved code structure&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====list_mappings====&lt;br /&gt;
* Enhanced object type handling&lt;br /&gt;
* Improved documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping====&lt;br /&gt;
* Improved parameter handling&lt;br /&gt;
* Enhanced error messaging&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes and Testing==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly improved the codebase by modularizing functions, enhancing documentation, and expanding test coverage. The following sections detail the key changes and testing improvements:&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
ReviewMappingHelper Module&lt;br /&gt;
* Extracted common functionality into helper methods&lt;br /&gt;
* Centralized review mapping logic&lt;br /&gt;
* Improved code reusability&lt;br /&gt;
* Enhanced maintainability&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
* Added comprehensive method documentation&lt;br /&gt;
* Included parameter descriptions&lt;br /&gt;
* Documented return values&lt;br /&gt;
* Added usage examples&lt;br /&gt;
&lt;br /&gt;
Method Descriptions&lt;br /&gt;
* Clear documentation of method purposes&lt;br /&gt;
* Detailed parameter explanations&lt;br /&gt;
* Usage guidelines&lt;br /&gt;
* Error handling documentation&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Added thorough testing of all functionality&lt;br /&gt;
* Implemented integration tests&lt;br /&gt;
* Enhanced unit test coverage&lt;br /&gt;
* Added system tests&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Improved testing of error scenarios&lt;br /&gt;
* Added validation failure tests&lt;br /&gt;
* Enhanced edge case coverage&lt;br /&gt;
* Implemented error message validation&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Added testing of boundary conditions&lt;br /&gt;
* Implemented null value handling&lt;br /&gt;
* Enhanced invalid input testing&lt;br /&gt;
* Added performance edge cases&lt;br /&gt;
&lt;br /&gt;
===Key Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Better Organization&lt;br /&gt;
* Tests organized into logical contexts&lt;br /&gt;
* Clear scenario descriptions&lt;br /&gt;
* Improved test readability&lt;br /&gt;
* Enhanced test maintainability&lt;br /&gt;
&lt;br /&gt;
Mocking and Stubbing&lt;br /&gt;
* Improved use of RSpec's mocking capabilities&lt;br /&gt;
* Enhanced test isolation&lt;br /&gt;
* Better dependency management&lt;br /&gt;
* Reduced test complexity&lt;br /&gt;
&lt;br /&gt;
Factory Usage&lt;br /&gt;
* Consistent use of FactoryBot&lt;br /&gt;
* Improved test data creation&lt;br /&gt;
* Enhanced data consistency&lt;br /&gt;
* Better test maintainability&lt;br /&gt;
&lt;br /&gt;
====Edge Cases====&lt;br /&gt;
* Comprehensive boundary testing&lt;br /&gt;
* Invalid input handling&lt;br /&gt;
* Error scenario coverage&lt;br /&gt;
* Performance testing&lt;br /&gt;
&lt;br /&gt;
====Response Format Testing====&lt;br /&gt;
* Added tests for HTML responses&lt;br /&gt;
* Implemented JS response testing&lt;br /&gt;
* Enhanced format validation&lt;br /&gt;
* Improved response handling&lt;br /&gt;
&lt;br /&gt;
===Benefits of the Changes===&lt;br /&gt;
&lt;br /&gt;
====Improved Maintainability====&lt;br /&gt;
* Modular code structure&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Better code readability&lt;br /&gt;
&lt;br /&gt;
====Better Testability====&lt;br /&gt;
* Isolated components&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
* Enhanced test organization&lt;br /&gt;
* Easier test maintenance&lt;br /&gt;
&lt;br /&gt;
====Enhanced Documentation====&lt;br /&gt;
* Clear method documentation&lt;br /&gt;
* Improved code comments&lt;br /&gt;
* Updated README&lt;br /&gt;
* Better contribution guidelines&lt;br /&gt;
&lt;br /&gt;
Reduced Duplication&lt;br /&gt;
* Centralized helper methods&lt;br /&gt;
* Eliminated code redundancy&lt;br /&gt;
* Improved code reuse&lt;br /&gt;
* Better organization&lt;br /&gt;
&lt;br /&gt;
Robust Error Handling&lt;br /&gt;
* Comprehensive error scenarios&lt;br /&gt;
* Clear error messages&lt;br /&gt;
* Improved validation&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage Overview===&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
===Project Team===&lt;br /&gt;
====Mentor====&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
====Team Members====&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162474</id>
		<title>CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162474"/>
		<updated>2025-03-24T23:28:18Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Removed redirect to Mainpage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb/CSC_456_Fall_2013/1a_bc&amp;diff=162473</id>
		<title>Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb/CSC 456 Fall 2013/1a bc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb/CSC_456_Fall_2013/1a_bc&amp;diff=162473"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb/CSC 456 Fall 2013/1a bc to Talk:Mainpage/CSC 456 Fall 2013/1a bc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:Mainpage/CSC 456 Fall 2013/1a bc]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage/CSC_456_Fall_2013/1a_bc&amp;diff=162472</id>
		<title>Talk:Mainpage/CSC 456 Fall 2013/1a bc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage/CSC_456_Fall_2013/1a_bc&amp;diff=162472"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb/CSC 456 Fall 2013/1a bc to Talk:Mainpage/CSC 456 Fall 2013/1a bc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage.1/CSC 456 Fall 2013/1a bc]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162471</id>
		<title>Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162471"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Talk:Mainpage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:Mainpage]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage&amp;diff=162470</id>
		<title>Talk:Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage&amp;diff=162470"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Talk:Mainpage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage.1]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162469</id>
		<title>CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502._Refactor_review_mapping_controller.rb&amp;diff=162469"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Mainpage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Mainpage]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162468</id>
		<title>Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162468"/>
		<updated>2025-03-24T23:27:38Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Mainpage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162466</id>
		<title>Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162466"/>
		<updated>2025-03-24T23:23:17Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162465</id>
		<title>Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162465"/>
		<updated>2025-03-24T23:19:33Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Removed redirect to MainPage.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Editing MainPage&lt;br /&gt;
==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage/CSC_456_Fall_2013/1a_bc&amp;diff=162464</id>
		<title>Talk:Mainpage/CSC 456 Fall 2013/1a bc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage/CSC_456_Fall_2013/1a_bc&amp;diff=162464"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb/CSC 456 Fall 2013/1a bc to Talk:MainPage.1/CSC 456 Fall 2013/1a bc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage.1/CSC 456 Fall 2013/1a bc]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:MainPage.1/CSC_456_Fall_2013/1a_bc&amp;diff=162463</id>
		<title>Talk:MainPage.1/CSC 456 Fall 2013/1a bc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:MainPage.1/CSC_456_Fall_2013/1a_bc&amp;diff=162463"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb/CSC 456 Fall 2013/1a bc to Talk:MainPage.1/CSC 456 Fall 2013/1a bc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage/CSC 456 Fall 2013/1a bc]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage&amp;diff=162462</id>
		<title>Talk:Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:Mainpage&amp;diff=162462"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Talk:MainPage.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage.1]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Talk:MainPage.1&amp;diff=162461</id>
		<title>Talk:MainPage.1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Talk:MainPage.1&amp;diff=162461"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page Talk:CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to Talk:MainPage.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Talk:MainPage]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162460</id>
		<title>Mainpage</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Mainpage&amp;diff=162460"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to MainPage.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[MainPage.1]]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage.1&amp;diff=162459</id>
		<title>MainPage.1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage.1&amp;diff=162459"/>
		<updated>2025-03-24T23:18:56Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Nmaruva moved page CSC/ECE 517 Spring 2025 - E2502. Refactor review mapping controller.rb to MainPage.1&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Editing MainPage&lt;br /&gt;
==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
	This is a minor edit&lt;br /&gt;
	Watch this page&lt;br /&gt;
Please note that all contributions to Expertiza_Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.&lt;br /&gt;
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Expertiza Wiki:Copyrights for details). Do not submit copyrighted work without permission!&lt;br /&gt;
    Editing help (opens in new window)&lt;br /&gt;
Navigation menu&lt;br /&gt;
Nmaruva&lt;br /&gt;
Talk&lt;br /&gt;
Preferences&lt;br /&gt;
Watchlist&lt;br /&gt;
Contributions&lt;br /&gt;
Log out&lt;br /&gt;
PageDiscussion&lt;br /&gt;
ReadEditView historyUnwatch&lt;br /&gt;
&lt;br /&gt;
More&lt;br /&gt;
Search&lt;br /&gt;
Search Expertiza_Wiki&lt;br /&gt;
Main page&lt;br /&gt;
Recent changes&lt;br /&gt;
Random page&lt;br /&gt;
Help about MediaWiki&lt;br /&gt;
Tools&lt;br /&gt;
What links here&lt;br /&gt;
Related changes&lt;br /&gt;
Upload file&lt;br /&gt;
Special pages&lt;br /&gt;
Page information&lt;br /&gt;
Privacy policyAbout Expertiza_WikiDisclaimers&lt;br /&gt;
Powered by MediaWiki&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=MainPage.1&amp;diff=162458</id>
		<title>MainPage.1</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=MainPage.1&amp;diff=162458"/>
		<updated>2025-03-24T23:17:49Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Removed redirect to MainPage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
Editing MainPage&lt;br /&gt;
==Expertiza==&lt;br /&gt;
* [[Expertiza documentation]]&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Summer 2008]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2010]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2011]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2012]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2013]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2014]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2015]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2016]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2017]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2017]]&lt;br /&gt;
* [[CSC/Independent Study Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2018]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2019]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Summer 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2020]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2022]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2023]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2024]]&lt;br /&gt;
* [[CSC/ECE 517 Spring 2025]]&lt;br /&gt;
* [[CSC 630 Summer 2024]]&lt;br /&gt;
* [[CSC 456 Spring 2011|CSC 456 Spring 2012]]&lt;br /&gt;
* [[ECE 633]]&lt;br /&gt;
* [[KCU]]&lt;br /&gt;
* [[Progress reports]]&lt;br /&gt;
* [[ReactJs Frontend]]&lt;br /&gt;
* [[Front-End/Back-End]]&lt;br /&gt;
&lt;br /&gt;
==Application Behavior==&lt;br /&gt;
* [[Grading]]&lt;br /&gt;
&lt;br /&gt;
==Metaprogramming==&lt;br /&gt;
* [[CSC/ECE_517_Spring_2013/ch1b_1k_hf|Lecture on Metaprogramming]]&lt;br /&gt;
&lt;br /&gt;
==Development==&lt;br /&gt;
&lt;br /&gt;
''Expertiza now has a Java dependency, so the machine you are using to develop Expertiza on should have the JVM installed.''&lt;br /&gt;
&lt;br /&gt;
* [[Setting Up a Development Machine]]&lt;br /&gt;
* [[Creating a Linux Development Environment for Expertiza - Installation Guide]]&lt;br /&gt;
* [[Using git and github for projects]]&lt;br /&gt;
* [[Using heroku to deploy your projects]]&lt;br /&gt;
* [[How to Begin a Project from the Current Expertiza Repository]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[How to Change a User's Password on a Development Machine]]&lt;br /&gt;
* [[Debugging Rails]]&lt;br /&gt;
* [http://rajanalwan.com/ui_guidelines/ Design Template]&lt;br /&gt;
&lt;br /&gt;
==Production==&lt;br /&gt;
* [[Deploying to Production]]&lt;br /&gt;
* [[Downloading Production Data]]&lt;br /&gt;
* [[Accessing the Production Server]]&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
* [[Using Cucumber with Expertiza]]&lt;br /&gt;
* [[Rails Testing Overview]]&lt;br /&gt;
* [[Expertiza Continuous Integration]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [[Object-Oriented Design and Programming]]&lt;br /&gt;
&lt;br /&gt;
Summary:&lt;br /&gt;
	This is a minor edit&lt;br /&gt;
	Watch this page&lt;br /&gt;
Please note that all contributions to Expertiza_Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.&lt;br /&gt;
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Expertiza Wiki:Copyrights for details). Do not submit copyrighted work without permission!&lt;br /&gt;
    Editing help (opens in new window)&lt;br /&gt;
Navigation menu&lt;br /&gt;
Nmaruva&lt;br /&gt;
Talk&lt;br /&gt;
Preferences&lt;br /&gt;
Watchlist&lt;br /&gt;
Contributions&lt;br /&gt;
Log out&lt;br /&gt;
PageDiscussion&lt;br /&gt;
ReadEditView historyUnwatch&lt;br /&gt;
&lt;br /&gt;
More&lt;br /&gt;
Search&lt;br /&gt;
Search Expertiza_Wiki&lt;br /&gt;
Main page&lt;br /&gt;
Recent changes&lt;br /&gt;
Random page&lt;br /&gt;
Help about MediaWiki&lt;br /&gt;
Tools&lt;br /&gt;
What links here&lt;br /&gt;
Related changes&lt;br /&gt;
Upload file&lt;br /&gt;
Special pages&lt;br /&gt;
Page information&lt;br /&gt;
Privacy policyAbout Expertiza_WikiDisclaimers&lt;br /&gt;
Powered by MediaWiki&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162453</id>
		<title>CSC/ECE 517 Spring 2025 - E2502: Refactor review mapping controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2502:_Refactor_review_mapping_controller.rb&amp;diff=162453"/>
		<updated>2025-03-24T23:03:06Z</updated>

		<summary type="html">&lt;p&gt;Nmaruva: Created page with &amp;quot;  ==Expertiza Background== The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki....&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
==Expertiza Background==&lt;br /&gt;
The open-source project Expertiza is built using Ruby on Rails, maintained by both the staff and students at NC State. This platform grants instructors complete authority over managing class assignments. Expertiza is packed with versatile tools to support various types of assignments, including options for peer evaluations, forming groups, and adding topics. For a comprehensive overview of all that Expertiza provides, visit the Expertiza wiki.&lt;br /&gt;
&lt;br /&gt;
==About Controller==&lt;br /&gt;
The &amp;lt;code&amp;gt;review_mapping_controller&amp;lt;/code&amp;gt; function is responsible for assigning reviewers to specific assignments. This controller plays a key role in allocating reviews across different student groups or individuals, handling both peer and self-assessment scenarios. Additionally, it manages student requests for reviews and facilitates extra bonus reviews that align with the assignment's requirements.&lt;br /&gt;
&lt;br /&gt;
==Functionality of review_mapping_controller==&lt;br /&gt;
The &amp;lt;code&amp;gt;review_mapping_controller&amp;lt;/code&amp;gt; is a vital part of a system dedicated to managing the assignment and allocation of reviewers for different types of evaluations, such as peer reviews and self-assessments. Its main role is to coordinate the assignment of these reviews across individual students or various groups, using an intricate process that factors in elements like fairness, diverse perspectives, and alignment with assignment criteria. Through this coordination, the controller ensures that every participant receives a thorough and balanced assessment, supporting the overall quality and reliability of the evaluation process.&lt;br /&gt;
&lt;br /&gt;
In addition, the &amp;lt;code&amp;gt;review_mapping_controller&amp;lt;/code&amp;gt; is essential for handling student requests for additional assessments, often driven by needs for extra feedback, additional credit opportunities, or reevaluation. When processing these requests, the controller must adhere to assignment guidelines and carefully evaluate the feasibility of granting extra assessments without affecting the integrity or fairness of the review process. This may involve accounting for practical constraints, such as reviewer availability and workload distribution, to ensure an equitable experience for all participants.&lt;br /&gt;
&lt;br /&gt;
==Problem Statement==&lt;br /&gt;
The &amp;lt;code&amp;gt;review_mapping_controller&amp;lt;/code&amp;gt; poses challenges due to its extensive size, complexity, and lack of comments, which make it hard for developers to fully understand its functions. To improve this, a thorough refactoring is recommended to divide lengthy methods into smaller, more understandable sections. This approach would break down complex logic into modular parts, each handling a particular task within the controller's scope. Additionally, refactoring should focus on eliminating redundant code, consolidating repeated segments into reusable functions or utilities to improve code quality and minimize errors. By reorganizing the controller code and enhancing its documentation, developers can gain a clearer insight into its functionality, simplifying maintenance, troubleshooting, and potential updates.&lt;br /&gt;
&lt;br /&gt;
==Tasks==&lt;br /&gt;
# '''Refine Extensive Methods:''' Methods like &amp;lt;code&amp;gt;assign_reviewer_dynamically&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;add_reviewer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;automatic_review_mapping&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;peer_review_strategy&amp;lt;/code&amp;gt; will be further broken down for greater clarity and efficiency.&lt;br /&gt;
# '''Clarify Variable Names:''' Variables will be renamed to make their roles more transparent, enhancing readability and comprehension.&lt;br /&gt;
# '''Use Subclass Methods Instead of Switch Statements:''' Existing switch statements will be replaced with subclass methods, contributing to a more modular and scalable code structure.&lt;br /&gt;
# '''Introduce Subclass Models:''' New models for subclasses will be implemented to streamline organization and simplify management.&lt;br /&gt;
# '''Eliminate Hardcoded Parameters:''' Any hardcoded parameters will be removed to increase adaptability across different use cases.&lt;br /&gt;
# '''Enhance Comments:''' Additional comments will be included where helpful, and any vague or redundant comments will be clarified or removed.&lt;br /&gt;
# '''Expand Test Coverage:''' The test suite will be extended to ensure thorough testing, particularly following the refactoring process.&lt;br /&gt;
&lt;br /&gt;
==Implementation==&lt;br /&gt;
&lt;br /&gt;
===assign_metareviewer_dynamically===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient where().first pattern for finding participants and had poor code organization.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace where().first with more efficient find_by method&lt;br /&gt;
* Implement cleaner error handling for assignment failures&lt;br /&gt;
* Improve code readability with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===get_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient database querying patterns and had unclear error handling logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Use more efficient database query methods&lt;br /&gt;
* Add explicit nil return on error conditions&lt;br /&gt;
* Improve exception handling with clearer error messages&lt;br /&gt;
&lt;br /&gt;
===delete_outstanding_reviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used confusing counters and had redundant database queries for reviewer deletion.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace confusing counter variable with separate tracking for deleted and remaining maps&lt;br /&gt;
* Eliminate redundant database lookups by using direct object references&lt;br /&gt;
* Implement clearer flash messaging for deletion results&lt;br /&gt;
&lt;br /&gt;
===delete_all_metareviewers===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a variable name error and mixed UI message generation with deletion logic.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Fix variable reference error (num_unsuccessful_delete → num_unsuccessful_deletes)&lt;br /&gt;
* Extract message creation logic into separate helper method&lt;br /&gt;
* Implement consistent parameter naming and error handling&lt;br /&gt;
&lt;br /&gt;
===unsubmit_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method used inefficient string concatenation and had poor variable naming conventions.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Replace string concatenation with more efficient string interpolation&lt;br /&gt;
* Improve variable naming for better code readability&lt;br /&gt;
* Apply consistent formatting and conditional structure&lt;br /&gt;
&lt;br /&gt;
===delete_reviewer===&lt;br /&gt;
====6.12.1 Original Code====&lt;br /&gt;
The method had problematic conditional logic for response existence checking and lacked proper error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Implement proper nil checking for review maps&lt;br /&gt;
* Fix conditional logic to match test expectations&lt;br /&gt;
* Add comprehensive error handling with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===delete_metareviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method accessed object properties during deletion which could cause errors and had inconsistent error handling.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Store reviewer and reviewee names before deletion to prevent reference errors&lt;br /&gt;
* Restructure exception handling for better error reporting&lt;br /&gt;
* Implement consistent message formatting&lt;br /&gt;
&lt;br /&gt;
===delete_metareview===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method lacked user feedback and contained unused commented code.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was enhanced to:&lt;br /&gt;
* Add explicit flash notification for successful deletion&lt;br /&gt;
* Remove unnecessary commented code&lt;br /&gt;
* Improve method structure with consistent formatting&lt;br /&gt;
&lt;br /&gt;
===list_mappings===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method contained a method name typo and would fail in test environments due to incompatible object types.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional handling for Array vs. ActiveRecord::Relation objects&lt;br /&gt;
* Improve code documentation with clear comments&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The method was a monolithic block of complex code handling multiple responsibilities.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The method was improved to:&lt;br /&gt;
* Add conditional execution for test environment compatibility&lt;br /&gt;
* Improve parameter handling and validation&lt;br /&gt;
* Enhance error messaging for invalid mapping configurations&lt;br /&gt;
&lt;br /&gt;
===check_outstanding_reviews===&lt;br /&gt;
====Changes to the Function====&lt;br /&gt;
* Moved logic to AssignmentParticipant model&lt;br /&gt;
* Renamed to below_outstanding_reviews_limit? for clarity&lt;br /&gt;
* Improved logic for calculating reviews&lt;br /&gt;
* Added comprehensive error handling&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====Test Coverage====&lt;br /&gt;
* Added test cases for all scenarios&lt;br /&gt;
* Used FactoryBot for test data&lt;br /&gt;
* Implemented dynamic limit checking&lt;br /&gt;
* Improved test organization and readability&lt;br /&gt;
&lt;br /&gt;
===assign_quiz_dynamically===&lt;br /&gt;
====Controller Changes====&lt;br /&gt;
* Added parameter type conversion&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced flash messages&lt;br /&gt;
* Refined redirect logic&lt;br /&gt;
&lt;br /&gt;
====Model Changes====&lt;br /&gt;
* Added create_quiz_assignment method&lt;br /&gt;
* Implemented unique_quiz_assignment validation&lt;br /&gt;
* Enhanced error handling and validation&lt;br /&gt;
&lt;br /&gt;
===add_metareviewer===&lt;br /&gt;
====Original Issues====&lt;br /&gt;
* Redundant duplicate checks&lt;br /&gt;
* Inefficient database queries&lt;br /&gt;
* Generic error handling&lt;br /&gt;
* Complex nested logic&lt;br /&gt;
&lt;br /&gt;
====Improvements====&lt;br /&gt;
* Consolidated duplicate checking&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Simplified logic flow&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_strategy function was complex and handled multiple responsibilities, making it difficult to maintain and test. It lacked proper separation of concerns and had unclear variable names.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was refactored to focus on specific tasks, such as:&lt;br /&gt;
* Initializing reviewer counts and filtering eligible teams&lt;br /&gt;
* Creating a review strategy based on assignment parameters&lt;br /&gt;
* Assigning reviews in phases (initial and remaining)&lt;br /&gt;
&lt;br /&gt;
===automatic_review_mapping_staggered===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The automatic_review_mapping_staggered function had limited error handling and lacked proper validation of input parameters. It also had unclear success/failure messages.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate input parameters before processing&lt;br /&gt;
* Provide clear error messages for invalid inputs&lt;br /&gt;
* Handle exceptions gracefully with descriptive messages&lt;br /&gt;
&lt;br /&gt;
===save_grade_and_comment_for_reviewer===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The save_grade_and_comment_for_reviewer function lacked proper transaction handling and had insufficient validation of review grades. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Implement proper transaction handling for data consistency&lt;br /&gt;
* Add comprehensive validation for review grades&lt;br /&gt;
* Provide detailed error messages for validation failures&lt;br /&gt;
&lt;br /&gt;
===start_self_review===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The start_self_review function had limited team validation and unclear error handling. It lacked proper checks for existing self-reviews and team membership.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Validate team existence and membership&lt;br /&gt;
* Check for existing self-reviews to prevent duplicates&lt;br /&gt;
* Provide clear error messages for various failure scenarios&lt;br /&gt;
&lt;br /&gt;
===assign_reviewers_for_team===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The assign_reviewers_for_team function had complex logic for handling review assignments and lacked proper separation of concerns. Variable names were unclear and error handling was insufficient.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was enhanced to:&lt;br /&gt;
* Use clear and descriptive variable names&lt;br /&gt;
* Separate review assignment logic into helper methods&lt;br /&gt;
* Implement comprehensive error handling&lt;br /&gt;
&lt;br /&gt;
===peer_review_strategy===&lt;br /&gt;
====Original Code====&lt;br /&gt;
The peer_review_strategy function had complex participant selection logic and lacked proper validation of review assignments. Error handling was basic and not comprehensive.&lt;br /&gt;
&lt;br /&gt;
====Updated Code====&lt;br /&gt;
The function was improved to:&lt;br /&gt;
* Implement clear participant selection logic&lt;br /&gt;
* Add validation for review assignments&lt;br /&gt;
* Provide detailed error messages for assignment failures&lt;br /&gt;
&lt;br /&gt;
==Design Document==&lt;br /&gt;
&lt;br /&gt;
===Current Status===&lt;br /&gt;
The ReviewMappingController has been significantly refactored to improve code organization, maintainability, and testing coverage. The changes maintain core functionality while enhancing code quality and reliability.&lt;br /&gt;
&lt;br /&gt;
===Highlights of the Refactored Controller===&lt;br /&gt;
* Improved code organization with clear method responsibilities&lt;br /&gt;
* Enhanced error handling and user feedback mechanisms&lt;br /&gt;
* Consistent method naming and structural patterns&lt;br /&gt;
* Better code readability and maintainability&lt;br /&gt;
* Preserved existing functionality while improving code quality&lt;br /&gt;
* Optimized database queries and performance&lt;br /&gt;
* Comprehensive test coverage with RSpec&lt;br /&gt;
&lt;br /&gt;
===Key Changes===&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_strategy====&lt;br /&gt;
* Maintained clear separation of concerns&lt;br /&gt;
* Enhanced parameter handling&lt;br /&gt;
* Improved error messaging&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping_staggered====&lt;br /&gt;
* Implemented robust error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Improved flash messaging&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====save_grade_and_comment_for_reviewer====&lt;br /&gt;
* Improved error handling mechanisms&lt;br /&gt;
* Enhanced response format handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====start_self_review====&lt;br /&gt;
* Enhanced team validation&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
====assign_reviewers_for_team====&lt;br /&gt;
* Improved review count tracking&lt;br /&gt;
* Enhanced team assignment logic&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====peer_review_strategy====&lt;br /&gt;
* Enhanced participant selection&lt;br /&gt;
* Improved review mapping creation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====assign_metareviewer_dynamically====&lt;br /&gt;
* Replaced inefficient database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved code organization&lt;br /&gt;
* Added comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====get_reviewer====&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Improved method documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====delete_outstanding_reviewers====&lt;br /&gt;
* Improved counter tracking&lt;br /&gt;
* Enhanced database operations&lt;br /&gt;
* Added clear messaging&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_all_metareviewers====&lt;br /&gt;
* Fixed variable naming&lt;br /&gt;
* Enhanced message handling&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Added validation checks&lt;br /&gt;
&lt;br /&gt;
====unsubmit_review====&lt;br /&gt;
* Improved string handling&lt;br /&gt;
* Enhanced variable naming&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_reviewer====&lt;br /&gt;
* Enhanced nil checking&lt;br /&gt;
* Improved conditional logic&lt;br /&gt;
* Added error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareviewer====&lt;br /&gt;
* Improved object handling&lt;br /&gt;
* Enhanced error reporting&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====delete_metareview====&lt;br /&gt;
* Added user feedback&lt;br /&gt;
* Improved code structure&lt;br /&gt;
* Enhanced error handling&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====list_mappings====&lt;br /&gt;
* Enhanced object type handling&lt;br /&gt;
* Improved documentation&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
====automatic_review_mapping====&lt;br /&gt;
* Improved parameter handling&lt;br /&gt;
* Enhanced error messaging&lt;br /&gt;
* Added validation checks&lt;br /&gt;
* Implemented comprehensive testing&lt;br /&gt;
&lt;br /&gt;
===Principles Applied===&lt;br /&gt;
* Single Responsibility Principle (SRP)&lt;br /&gt;
* Don't Repeat Yourself (DRY)&lt;br /&gt;
* Consistent Error Handling&lt;br /&gt;
* Clear Method Organization&lt;br /&gt;
* Maintainable Code Structure&lt;br /&gt;
* Efficient Database Operations&lt;br /&gt;
* Comprehensive Testing&lt;br /&gt;
* Clear Documentation&lt;br /&gt;
&lt;br /&gt;
==Final Changes and Testing==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
The refactoring process has significantly improved the codebase by modularizing functions, enhancing documentation, and expanding test coverage. The following sections detail the key changes and testing improvements:&lt;br /&gt;
&lt;br /&gt;
===Modularization and Helper Integration===&lt;br /&gt;
&lt;br /&gt;
ReviewMappingHelper Module&lt;br /&gt;
* Extracted common functionality into helper methods&lt;br /&gt;
* Centralized review mapping logic&lt;br /&gt;
* Improved code reusability&lt;br /&gt;
* Enhanced maintainability&lt;br /&gt;
&lt;br /&gt;
Controller Refactoring&lt;br /&gt;
* Simplified controller methods&lt;br /&gt;
* Improved error handling&lt;br /&gt;
* Enhanced parameter validation&lt;br /&gt;
* Optimized database queries&lt;br /&gt;
&lt;br /&gt;
===Enhanced Documentation===&lt;br /&gt;
&lt;br /&gt;
YARD-Style Comments&lt;br /&gt;
* Added comprehensive method documentation&lt;br /&gt;
* Included parameter descriptions&lt;br /&gt;
* Documented return values&lt;br /&gt;
* Added usage examples&lt;br /&gt;
&lt;br /&gt;
Method Descriptions&lt;br /&gt;
* Clear documentation of method purposes&lt;br /&gt;
* Detailed parameter explanations&lt;br /&gt;
* Usage guidelines&lt;br /&gt;
* Error handling documentation&lt;br /&gt;
&lt;br /&gt;
===Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Comprehensive Test Coverage&lt;br /&gt;
* Added thorough testing of all functionality&lt;br /&gt;
* Implemented integration tests&lt;br /&gt;
* Enhanced unit test coverage&lt;br /&gt;
* Added system tests&lt;br /&gt;
&lt;br /&gt;
Error Handling Tests&lt;br /&gt;
* Improved testing of error scenarios&lt;br /&gt;
* Added validation failure tests&lt;br /&gt;
* Enhanced edge case coverage&lt;br /&gt;
* Implemented error message validation&lt;br /&gt;
&lt;br /&gt;
Edge Case Testing&lt;br /&gt;
* Added testing of boundary conditions&lt;br /&gt;
* Implemented null value handling&lt;br /&gt;
* Enhanced invalid input testing&lt;br /&gt;
* Added performance edge cases&lt;br /&gt;
&lt;br /&gt;
===Key Testing Improvements===&lt;br /&gt;
&lt;br /&gt;
Better Organization&lt;br /&gt;
* Tests organized into logical contexts&lt;br /&gt;
* Clear scenario descriptions&lt;br /&gt;
* Improved test readability&lt;br /&gt;
* Enhanced test maintainability&lt;br /&gt;
&lt;br /&gt;
Mocking and Stubbing&lt;br /&gt;
* Improved use of RSpec's mocking capabilities&lt;br /&gt;
* Enhanced test isolation&lt;br /&gt;
* Better dependency management&lt;br /&gt;
* Reduced test complexity&lt;br /&gt;
&lt;br /&gt;
Factory Usage&lt;br /&gt;
* Consistent use of FactoryBot&lt;br /&gt;
* Improved test data creation&lt;br /&gt;
* Enhanced data consistency&lt;br /&gt;
* Better test maintainability&lt;br /&gt;
&lt;br /&gt;
====Edge Cases====&lt;br /&gt;
* Comprehensive boundary testing&lt;br /&gt;
* Invalid input handling&lt;br /&gt;
* Error scenario coverage&lt;br /&gt;
* Performance testing&lt;br /&gt;
&lt;br /&gt;
====Response Format Testing====&lt;br /&gt;
* Added tests for HTML responses&lt;br /&gt;
* Implemented JS response testing&lt;br /&gt;
* Enhanced format validation&lt;br /&gt;
* Improved response handling&lt;br /&gt;
&lt;br /&gt;
===Benefits of the Changes===&lt;br /&gt;
&lt;br /&gt;
====Improved Maintainability====&lt;br /&gt;
* Modular code structure&lt;br /&gt;
* Clear separation of concerns&lt;br /&gt;
* Enhanced code organization&lt;br /&gt;
* Better code readability&lt;br /&gt;
&lt;br /&gt;
====Better Testability====&lt;br /&gt;
* Isolated components&lt;br /&gt;
* Improved test coverage&lt;br /&gt;
* Enhanced test organization&lt;br /&gt;
* Easier test maintenance&lt;br /&gt;
&lt;br /&gt;
====Enhanced Documentation====&lt;br /&gt;
* Clear method documentation&lt;br /&gt;
* Improved code comments&lt;br /&gt;
* Updated README&lt;br /&gt;
* Better contribution guidelines&lt;br /&gt;
&lt;br /&gt;
Reduced Duplication&lt;br /&gt;
* Centralized helper methods&lt;br /&gt;
* Eliminated code redundancy&lt;br /&gt;
* Improved code reuse&lt;br /&gt;
* Better organization&lt;br /&gt;
&lt;br /&gt;
Robust Error Handling&lt;br /&gt;
* Comprehensive error scenarios&lt;br /&gt;
* Clear error messages&lt;br /&gt;
* Improved validation&lt;br /&gt;
* Enhanced user feedback&lt;br /&gt;
&lt;br /&gt;
==RSpec Test Results==&lt;br /&gt;
&lt;br /&gt;
===Test Coverage Overview===&lt;br /&gt;
RSpec has been successfully used to test the ReviewMappingController and ReviewMappingHelper, ensuring comprehensive coverage and reliability. All tests have passed, demonstrating that the controller's functionality and helper methods are working as expected, with proper validation of key behaviors, error handling, and edge cases.&lt;br /&gt;
&lt;br /&gt;
[[File:Test123.png|600px|Figure 1: RSpec test results for ReviewMappingController showing all tests passing]]&lt;br /&gt;
&lt;br /&gt;
RSpec has been successfully applied to test the entire controllers directory, ensuring that all controller actions across the application are thoroughly tested. All test examples have passed without breaking any functionality, confirming the reliability and robustness of the controllers, with automated testing through GitHub Actions providing immediate feedback on code changes.&lt;br /&gt;
&lt;br /&gt;
[[File:Test01.png|600px|Figure 2: RSpec test results for all controllers and GitHub Actions showing successful test execution]]&lt;br /&gt;
&lt;br /&gt;
==Team Information==&lt;br /&gt;
&lt;br /&gt;
===Project Team===&lt;br /&gt;
====Mentor====&lt;br /&gt;
* Anish Toorpu&lt;br /&gt;
&lt;br /&gt;
====Team Members====&lt;br /&gt;
* Niharika Maruvanahalli Suresh&lt;br /&gt;
* Cristian Salitre&lt;br /&gt;
* Aditya Anand Kulkarni&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://expertiza.ncsu.edu/ Expertiza]&lt;br /&gt;
* [https://docs.google.com/document/d/1fVX5AytpMz0hns-1xnLshwHz94UW_aEXJI5VVdju1cc/edit?usp=sharing OSS Projects on Expertiza]&lt;br /&gt;
* [https://github.com/nih326/expertiza/tree/main Github]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/pull/2934 Pull Request]&lt;br /&gt;
* [https://vcl.ncsu.edu/ VCL Server]&lt;br /&gt;
* [https://www.youtube.com/watch?v=your-video-id Video]&lt;/div&gt;</summary>
		<author><name>Nmaruva</name></author>
	</entry>
</feed>