iLLcheff

ShowComments

Jan 2nd, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. package com.telerikacademy.oop.teamproject.commands.show;
  2.  
  3. import com.telerikacademy.oop.teamproject.commands.contracts.Command;
  4. import com.telerikacademy.oop.teamproject.core.contracts.TaskManagementSystemRepository;
  5. import com.telerikacademy.oop.teamproject.models.contracts.Board;
  6. import com.telerikacademy.oop.teamproject.models.contracts.Task;
  7. import com.telerikacademy.oop.teamproject.models.contracts.Team;
  8. import com.telerikacademy.oop.teamproject.utils.ParsingHelpers;
  9. import com.telerikacademy.oop.teamproject.utils.ValidationHelpers;
  10.  
  11. import java.util.List;
  12.  
  13. public class ShowCommentsCommand implements Command {
  14.     private static final int EXPECTED_NUMBER_OF_ARGUMENTS = 3;
  15.     private TaskManagementSystemRepository taskManagementSystemRepository;
  16.     String teamName;
  17.     String boardName;
  18.     int taskId;
  19.  
  20.     public ShowCommentsCommand(TaskManagementSystemRepository taskManagementSystemRepository) {
  21.         this.taskManagementSystemRepository = taskManagementSystemRepository;
  22.     }
  23.  
  24.     @Override
  25.     public String execute(List<String> parameters) {
  26.         ValidationHelpers.validateArgumentsCount(parameters, EXPECTED_NUMBER_OF_ARGUMENTS);
  27.  
  28.         teamName = parameters.get(0);
  29.         boardName = parameters.get(1);
  30.         taskId = ParsingHelpers.tryParseInt(parameters.get(2), "id");
  31.  
  32.         Team team = taskManagementSystemRepository.findTeamByTeamName(teamName);
  33.         Board board = team.findBoardByName(boardName);
  34.         Task task = board.findTaskById(board.getAllTasks(), taskId);
  35.  
  36.         return task.getComments();
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment