From 9e0d686b0e1f39394eff95e067a7c15745cb2623 Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 19:08:57 -0500 Subject: [PATCH 1/6] Made changes to collaborative task and modified use case --- .idea/misc.xml | 5 +- src/main/java/entities/CollaborativeTask.java | 278 ++++++++++++++++++ .../EnterTimeAndTask.java | 69 +++++ .../scheduling_ct_screens/LabelTextPanel.java | 12 + .../scheduling_ct_screens/PresentOutput.java | 20 ++ .../ScheduleCTController.java | 28 ++ .../ScheduleCTPresenter.java | 18 ++ .../SchedulingTimesFailed.java | 7 + .../ScheduleCTInputBoundary.java | 11 + .../ScheduleCTInteractor.java | 256 ++++++++++++++++ .../ScheduleCTOutputBoundary.java | 8 + .../ScheduleCTRequestModel.java | 40 +++ .../ScheduleCTResponseModel.java | 23 ++ 13 files changed, 774 insertions(+), 1 deletion(-) create mode 100644 src/main/java/entities/CollaborativeTask.java create mode 100644 src/main/java/scheduling_ct_screens/EnterTimeAndTask.java create mode 100644 src/main/java/scheduling_ct_screens/LabelTextPanel.java create mode 100644 src/main/java/scheduling_ct_screens/PresentOutput.java create mode 100644 src/main/java/scheduling_ct_screens/ScheduleCTController.java create mode 100644 src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java create mode 100644 src/main/java/scheduling_ct_screens/SchedulingTimesFailed.java create mode 100644 src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java create mode 100644 src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java create mode 100644 src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java create mode 100644 src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java create mode 100644 src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java diff --git a/.idea/misc.xml b/.idea/misc.xml index c643c23..08a0d19 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,8 @@ - + + + + \ No newline at end of file diff --git a/src/main/java/entities/CollaborativeTask.java b/src/main/java/entities/CollaborativeTask.java new file mode 100644 index 0000000..a84fe1c --- /dev/null +++ b/src/main/java/entities/CollaborativeTask.java @@ -0,0 +1,278 @@ +package entities; + +import java.time.LocalDateTime; +import java.util.ArrayList; + +public class CollaborativeTask extends Task implements Timeblockable { + private boolean recurring; + private String frequency; + private LocalDateTime startTime; + private LocalDateTime endTime; + private LocalDateTime deadline; + private ArrayList> timeBlocks; + private ArrayList teammates; + private ArrayList pendingTeammates; + private ArrayList declinedTeammates; + private StudentUser leader; + + /** + * Create a CollaborativeTask with a title, priority, and deadline + * If the collaborative task is recurring, indicate the frequency (eg "daily", "weekly", "monthly) + * Otherwise, the frequency is blank + * + * @param title - the title of the Collaborative Task + * @param id - the unique ID of the Collaborative Task + * @param recurring - whether the Collaborative Task is recurring + * @param frequency - the frequency at which the Collaborative Task occurs (if recurring) + * @param startTime = the start time and date of the first occurrence of the Collaborative Task + * @param endTime = the end time and date of the first occurrence of the Collaborative Task + * @param deadline - the time at which the Collaborative Task is due + * @param creator - the Student User who creates the Collaborative Task + */ + public CollaborativeTask(String title, String id, int priority, boolean recurring, String frequency, LocalDateTime startTime, LocalDateTime endTime, LocalDateTime deadline, StudentUser creator) { + super(title, id, priority); + this.recurring = recurring; + if (recurring) { + this.frequency = frequency; + } else { + this.frequency = ""; + } + this.startTime = startTime; + this.endTime = endTime; + this.deadline = deadline; + this.leader = creator; + } + + /** + * @return whether the Collaborative Task is reoccurring or not. + */ + public boolean getRecurring() { + return this.recurring; + } + + /** + * @return frequency of Collaborative Task. + */ + public String getFrequency() { + return this.frequency; + } + + /** + * Set a Collaborative Task as recurring/not + * Set its new frequency if it is recurring + * + * @param recurring - whether the Collaborative Task is recurring + * @param frequency - the frequency at which the Collaborative Task occurs (if recurring) + */ + public void setRecurringAndFrequency(boolean recurring, String frequency) { + this.recurring = recurring; + if (recurring) { + this.frequency = frequency; + } else { + this.frequency = ""; + } + } + + /** + * @return start time for the initial occurrence of the Collaborative Task. + */ + public LocalDateTime getStartTime() { + return this.startTime; + } + + /** + * Set a start time for Collaborative Task. + * + * @param startTime - start time for the initial occurrence of the Collaborative Task. + */ + public void setStartTime(LocalDateTime startTime) { + this.startTime = startTime; + } + + /** + * @return end time for the initial occurrence of the Collaborative Task. + */ + public LocalDateTime getEndTime() { + return this.endTime; + } + + /** + * Set a end time for Collaborative Task. + * + * @param endTime - end time for the initial occurrence of the Collaborative Task. + */ + public void setEndTime(LocalDateTime endTime) { + this.endTime = endTime; + } + + /** + * @return deadline for Collaborative Task. + */ + public LocalDateTime getDeadline() { + return this.deadline; + } + + /** + * Set a deadline for a Collaborative Task. + * + * @param deadline - deadline for Collaborative Task. + */ + public void setDeadline(LocalDateTime deadline) { + this.deadline = deadline; + } + + // The following four methods (getTimeBlock, setTimeBlock, scheduleTimeBlock, and removeTimeBlock) are here because this class implements Timeblockable/ + // Based on the way Collaborative Tasks are scheduled (Feature 5), not sure if they remain necessary. + /** + * Set the time block of a Collaborative Task + * @return - the time block of the Collaborative Task + * - in array form: {startTime, endTime} + */ + public LocalDateTime[] getTimeBlock() { + return new LocalDateTime[] {this.startTime, this.endTime}; + } + + /** + * Set a new time block and then schedule it + * @param startTime - the start of the time block + * @param endTime - the end of the time block + */ + public void setTimeBlock(LocalDateTime startTime, LocalDateTime endTime) { + this.startTime = startTime; + this.endTime = endTime; + scheduleTimeBlock(); + } + + /** + * Schedule a time block for the user + * @return - whether the time block has been successfully scheduled + */ + public boolean scheduleTimeBlock() { + return true; + } + + /** + * Remove a time block from the user's schedule + * @return - whether the time block has been successfully removed + */ + public boolean removeTimeBlock() { + return true; + } + + /** + * Get the time blocks of a Collaborative Task. + * + * @return - the time blocks of the Collaborative task in an Array List of Array Losts of LocalDateTimes. + */ + public ArrayList> getTimeBlocks() { + return this.timeBlocks; + } + + /** + * Set new time blocks + * + * @param timeBlocks - Array List of Array Lists of time blocks of the Collaborative Task. + */ + public void setTimeBlocks(ArrayList> timeBlocks) { + this.timeBlocks = timeBlocks; + } + + /** + * @return leader of the Collaborative Task + */ + public StudentUser getLeader() { + return this.leader; + } + + /** + * Set a new leader of the Collaborative Task. + * This method should only be used by the current leader of the Collaborative Task. + * + * @param leader - the Student User who is going to replace the current leader of the Collaborative Task. + */ + public void setLeader(StudentUser leader) { + this.leader = leader; + } + + /** + * @return an Array List of all Student Users who are teammates on this Collaborative Task, including the leader. + */ + public ArrayList getTeammates() { + return this.teammates; + } + + /** + * To be used when invitations to join a Collaborative Task are accepted. + * + * @param newTeammates - an Array List of Student Users who are to be added as teammates. + */ + public void addTeammates(ArrayList newTeammates) { + this.teammates.addAll(newTeammates); + } + + /** + * When this method is used by the leader of the Collaborative Task, + * the oldTeammates parameter can contain any Student User in the Collaborative Task's teammates list. + * When this method is used by any other teammate of the Collaborative Task, + * the oldTeammates parameter can only contain themselves. + * + * @param oldTeammates - an Array List of Student Users who are to be removed as teammates. + */ + public void removeTeammates(ArrayList oldTeammates) { + this.teammates.removeAll(oldTeammates); + } + + /** + * @return an Array List of all Student Users who have received invitations to join + * the Collaborative Task but not responded. + */ + public ArrayList getPendingTeammates() { + return this.pendingTeammates; + } + + /** + * To be used when invitations to join a Collaborative Task are sent. + * + * @param newTeammates - an Array List of Student Users who are being invited to join the Collaborative Task. + */ + public void addPendingTeammates(ArrayList newTeammates) { + this.pendingTeammates.addAll(newTeammates); + } + + /** + * To be used when invitations to join a Collaborative Task are canceled or responded to. + * + * @param oldTeammates - an Array List of Student Users who are no longer undergoing the process of being + * invited to join the Collaborative Task. + */ + public void removePendingTeammates(ArrayList oldTeammates) { + this.pendingTeammates.removeAll(oldTeammates); + } + + /** + * @return an Array List of all Student Users who have declined invitations to join the Collaborative Task. + */ + public ArrayList getDeclinedTeammates() { + return this.declinedTeammates; + } + + /** + * To be used when invitations to join a Collaborative Task are declined. + * + * @param newTeammates - an Array List of Student Users who have declined invitations to join the Collaborative Task. + */ + public void addDeclinedTeammates(ArrayList newTeammates) { + this.declinedTeammates.addAll(newTeammates); + } + + /** + * To be used when a Student User who has previously declined an invitation to join the Collaborative Task has + * accepted a reinvitation to join. + * + * @param oldTeammates - an Array List of Student Users who have accepted an invitation to join the Collaborative + * Task after previously declining such an invitation. + */ + public void removeDeclinedTeammates(ArrayList oldTeammates) { + this.declinedTeammates.removeAll(oldTeammates); + } +} \ No newline at end of file diff --git a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java new file mode 100644 index 0000000..893b5a1 --- /dev/null +++ b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java @@ -0,0 +1,69 @@ +package scheduling_ct_screens; + +import scheduling_ct_use_case.*; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + + + + +public class EnterTimeAndTask extends JFrame implements ActionListener { + + ScheduleCTController scheduleCTController; + JTextField taskTitle = new JTextField(15); + JTextField username = new JTextField(15); + JTextField startTime = new JTextField(15); + JTextField endTime = new JTextField(15); + + + public EnterTimeAndTask(ScheduleCTController scheduleCTController) { + + this.scheduleCTController = scheduleCTController; + + + JLabel title = new JLabel("Scheduling Collaborative Tasks"); + title.setAlignmentX(Component.CENTER_ALIGNMENT); + + LabelTextPanel taskInfo = new LabelTextPanel(new JLabel("Enter task title"), taskTitle); + + LabelTextPanel userInfo = new LabelTextPanel(new JLabel("Enter task title"), taskTitle); + + LabelTextPanel startInfo = new LabelTextPanel(new JLabel("Enter start time"), startTime); + + LabelTextPanel endInfo = new LabelTextPanel(new JLabel("Enter end time"), endTime); + + + JButton submit = new JButton("Submit"); + + JPanel buttons = new JPanel(); + buttons.add(submit); + + submit.addActionListener(this); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + JPanel main = new JPanel(); + main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); + + main.add(title); + main.add(taskInfo); + main.add(userInfo); + main.add(startInfo); + main.add(endInfo); + main.add(buttons); + this.setContentPane(main); + + this.pack(); + setVisible(true); + } + + // React to button click that results in evt + public void actionPerformed(ActionEvent evt) { +// System.out.println("Click" + evt.getActionCommand()); + scheduleCTController.isConflict(taskTitle.getText(), username.getText(), startTime.getText(), endTime.getText()); + + + } +} diff --git a/src/main/java/scheduling_ct_screens/LabelTextPanel.java b/src/main/java/scheduling_ct_screens/LabelTextPanel.java new file mode 100644 index 0000000..a5ba101 --- /dev/null +++ b/src/main/java/scheduling_ct_screens/LabelTextPanel.java @@ -0,0 +1,12 @@ +package scheduling_ct_screens; + +import javax.swing.*; + +// Frameworks/Drivers layer + +public class LabelTextPanel extends JPanel { + public LabelTextPanel(JLabel label, JTextField textField) { + this.add(label); + this.add(textField); + } +} \ No newline at end of file diff --git a/src/main/java/scheduling_ct_screens/PresentOutput.java b/src/main/java/scheduling_ct_screens/PresentOutput.java new file mode 100644 index 0000000..609433d --- /dev/null +++ b/src/main/java/scheduling_ct_screens/PresentOutput.java @@ -0,0 +1,20 @@ +package scheduling_ct_screens; + +import javax.swing.*; + +public class PresentOutput extends JFrame { + + String message; + + public PresentOutput(String message) { + this.message = message; + + JLabel text = new JLabel(message); + + JPanel main = new JPanel(); + main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS)); + + main.add(text); + setVisible(true); + } +} diff --git a/src/main/java/scheduling_ct_screens/ScheduleCTController.java b/src/main/java/scheduling_ct_screens/ScheduleCTController.java new file mode 100644 index 0000000..ccf318e --- /dev/null +++ b/src/main/java/scheduling_ct_screens/ScheduleCTController.java @@ -0,0 +1,28 @@ +package scheduling_ct_screens; +import entities.Task; +import scheduling_ct_use_case.*; +import entities.TaskMap; + +import java.util.HashMap; + +public class ScheduleCTController { + + final ScheduleCTInputBoundary scheduleInput; + + private final HashMap hashMap; + + public ScheduleCTController(ScheduleCTInputBoundary scheduleInput, HashMap hashMap) { + this.scheduleInput = scheduleInput; + this.hashMap = hashMap; + } + + public HashMap getTaskMap() { + return hashMap; + } + + public ScheduleCTResponseModel isConflict(String taskName, String username, String startTime, String endTime) { + ScheduleCTRequestModel inputData = new ScheduleCTRequestModel(taskName, username, startTime, endTime); + return scheduleInput.schedule(inputData, this.hashMap); + } + +} diff --git a/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java b/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java new file mode 100644 index 0000000..ddff186 --- /dev/null +++ b/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java @@ -0,0 +1,18 @@ +package scheduling_ct_screens; +import scheduling_ct_use_case.*; + +public class ScheduleCTPresenter implements ScheduleCTOutputBoundary { + + @Override + public ScheduleCTResponseModel prepareNoConflictView(ScheduleCTResponseModel responseModel) { + if ((!responseModel.getIsConflict())) { + responseModel.setDisplayString("Successful input"); + } + return responseModel; + } + + @Override + public ScheduleCTResponseModel prepareFailView(String error) { + throw new SchedulingTimesFailed(error); + } +} diff --git a/src/main/java/scheduling_ct_screens/SchedulingTimesFailed.java b/src/main/java/scheduling_ct_screens/SchedulingTimesFailed.java new file mode 100644 index 0000000..758bd09 --- /dev/null +++ b/src/main/java/scheduling_ct_screens/SchedulingTimesFailed.java @@ -0,0 +1,7 @@ +package scheduling_ct_screens; + +public class SchedulingTimesFailed extends RuntimeException{ + public SchedulingTimesFailed(String error){ + super(error); + } +} diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java new file mode 100644 index 0000000..60ea67e --- /dev/null +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java @@ -0,0 +1,11 @@ +package scheduling_ct_use_case; + +import entities.Task; +import java.util.HashMap; + +// use case layer + +public interface ScheduleCTInputBoundary { + + ScheduleCTResponseModel schedule(ScheduleCTRequestModel scheduleCTRequestModel, HashMap hashMap); +} diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java new file mode 100644 index 0000000..3bafa7a --- /dev/null +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java @@ -0,0 +1,256 @@ +package scheduling_ct_use_case; + +import entities.*; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; + +public class ScheduleCTInteractor implements ScheduleCTInputBoundary { + private final ScheduleCTOutputBoundary scheduleCTOutputBoundary; + + public ScheduleCTInteractor(ScheduleCTOutputBoundary scheduleCTOutputBoundary) { + this.scheduleCTOutputBoundary = scheduleCTOutputBoundary; + } + + @Override + public ScheduleCTResponseModel schedule(ScheduleCTRequestModel requestModel, HashMap hashMap) { + // returns that this has conflict + // otherwise will automatically schedule and return a success view + + CollaborativeTask task = getTaskObjectFromName(requestModel.getTaskName(), hashMap); + ArrayList users = task.getTeammates(); + users.add(task.getLeader()); + + ArrayList unavailableUsers = new ArrayList<>(); + + LocalDateTime startTime = convertStringToLocalDateTime(requestModel.getStartTime()); + LocalDateTime endTime = convertStringToLocalDateTime(requestModel.getEndTime()); + + for (StudentUser user : users) { + ArrayList userTasks = getTaskFromId(user, hashMap); + if (!isUserAvailableAtDateTime(user, userTasks, startTime, endTime)) { + unavailableUsers.add(user); + } + } + if (!unavailableUsers.isEmpty()) { + if (task.getFrequency().equals("")) { + ArrayList> oneDate = new ArrayList<>(); + ArrayList theDate = new ArrayList<>(); + theDate.add(startTime); + theDate.add(endTime); + oneDate.add(theDate); + task.setTimeBlocks(oneDate); + } else { + ArrayList> dates = getDates(task.getFrequency(), startTime, endTime, task.getDeadline()); + task.setTimeBlocks(dates); + } + ScheduleCTResponseModel scheduleCTResponseModel = new ScheduleCTResponseModel(false); + return scheduleCTOutputBoundary.prepareNoConflictView(scheduleCTResponseModel); + } else { + ScheduleCTResponseModel scheduleCTResponseModel = new ScheduleCTResponseModel(true); + return scheduleCTOutputBoundary.prepareFailView("Cannot schedule due to conflict"); + } + } + + public ArrayList> getDates(String frequency, LocalDateTime startTime, LocalDateTime endTime, LocalDateTime deadline) { + ArrayList> times = new ArrayList<>(); + ArrayList initialTime = new ArrayList<>(); + initialTime.add(startTime); + initialTime.add(endTime); + times.add(initialTime); + + LocalDateTime currStart = startTime; + LocalDateTime currEnd = endTime; + + switch (frequency) { + case "daily": + do { + ArrayList date = new ArrayList<>(); + currStart = currStart.plusDays(1); + currEnd = currEnd.plusDays(1); + + date.add(currStart); + date.add(currEnd); + times.add(date); + } while (endTime.isBefore(deadline)); + break; + case "weekly": + do { + ArrayList date = new ArrayList<>(); + currStart = currStart.plusWeeks(1); + currEnd = currEnd.plusWeeks(1); + + date.add(currStart); + date.add(currEnd); + times.add(date); + } while (endTime.isBefore(deadline)); + break; + case "monthly": + do { + ArrayList date = new ArrayList<>(); + currStart = currStart.plusMonths(1); + currEnd = currEnd.plusMonths(1); + + date.add(currStart); + date.add(currEnd); + times.add(date); + } while (endTime.isBefore(deadline)); + break; + } + return times; + } + + + public boolean isUserAvailableAtDateTime(StudentUser user, ArrayList tasks, LocalDateTime start, + LocalDateTime end) { + // assume there's a method in TaskUseCase that gets all the tasks a student has + + boolean is_task_free = true; + boolean is_working_hours_free = true; + for (Task task : tasks) { + + if (task instanceof Event) { + if (((Event) task).getTimeBlock() != null) { + LocalDateTime[] timeBlock = ((Event) task).getTimeBlock(); + LocalDateTime timeBlockStart = timeBlock[0]; + LocalDateTime timeBlockEnd = timeBlock[1]; + is_task_free = is_task_free && givenTime(timeBlockStart, timeBlockEnd, start, end); + } + } else if (task instanceof Test) { + if (((Test) task).getTimeBlock() != null) { + + LocalDateTime[] timeBlock = ((Test) task).getTimeBlock(); + LocalDateTime timeBlockStart = timeBlock[0]; + LocalDateTime timeBlockEnd = timeBlock[1]; + + is_task_free = is_task_free && givenTime(timeBlockStart, timeBlockEnd, start, end); + + if (((Test) task).getPrepTimeScheduled() != null) { + ArrayList> scheduledPrep = ((Test) task).getPrepTimeScheduled(); + for (ArrayList prep : scheduledPrep) { + LocalDateTime prepStart = prep.get(0); + LocalDateTime prepEnd = prep.get(1); + + is_task_free = is_task_free && givenTime(prepStart, prepEnd, start, end); + } + + } + } + } else if (task instanceof Assignment) { + + if (((Assignment) task).getPrepTimeScheduled() != null) { + ArrayList> scheduledPrep = ((Assignment) task).getPrepTimeScheduled(); + for (ArrayList prep : scheduledPrep) { + LocalDateTime prepStart = prep.get(0); + LocalDateTime prepEnd = prep.get(1); + + is_task_free = is_task_free && givenTime(prepStart, prepEnd, start, end); + } + } + } + + } + if (user.getWorkingHours() != null) { + ArrayList workingHours = user.getWorkingHours(); + LocalTime workingHoursStart = workingHours.get(0); + LocalTime workingHoursEnd = workingHours.get(1); + is_working_hours_free = workingHoursFree(start, end, workingHoursStart, workingHoursEnd); + } + return is_task_free && is_working_hours_free; + } + + // required methods: + // - for each user determine if they have conflict with time given from their tasks + // - for each user determine if they have conflict with time given with their working hours + + public boolean workingHoursFree(LocalDateTime timeBlockStart, LocalDateTime timeBlockEnd, + LocalTime workingHoursStart, LocalTime workingHoursEnd) { + // if timeBlock is within working hours + // timeBlockStart.isAfter(ChronoLocalDateTime.from(workingHoursStart)) && + // timeBlockEnd.isBefore(ChronoLocalDateTime.from(workingHoursEnd)) + if (timeBlockStart.getHour() > workingHoursStart.getHour() && + timeBlockEnd.getHour() < workingHoursEnd.getHour()) { + return false; + // if timeBlock covers the whole period of working hours + // timeBlockStart.isBefore(ChronoLocalDateTime.from(workingHoursStart)) && + // timeBlockEnd.isAfter(ChronoLocalDateTime.from(workingHoursEnd)) + } else if (timeBlockStart.getHour() < workingHoursStart.getHour() && + timeBlockEnd.getHour() > workingHoursEnd.getHour()) { + return false; + // if timeBlockStart is before workingHoursStart and timeBlockEnd is before workingHoursEnd + } else if (timeBlockStart.getHour()< workingHoursStart.getHour() && + timeBlockEnd.getHour() < workingHoursEnd.getHour()) { + return false; + // if timeBlockStart is the same as workingHoursStart + } else if (timeBlockStart.getHour() == workingHoursStart.getHour()) { + return false; + // if timeBlockEnd is the same as workingHoursEnd + } else if (timeBlockEnd.getHour() == workingHoursEnd.getHour()) { + return false; + // if timeBlockStart is after workingHoursStart and timeBlockEnd is after workingHoursEnd + } else return !(timeBlockStart.getHour() > workingHoursStart.getHour() && + timeBlockEnd.getHour() > workingHoursEnd.getHour()); + } + public boolean givenTime(LocalDateTime timeBlockStart, LocalDateTime timeBlockEnd, + LocalDateTime start, LocalDateTime end) { + // in the case where the time block is within the time of start and end + if (timeBlockStart.isAfter(start) && timeBlockEnd.isBefore(end)) { + return false; + // in the case where it covers the time period + } else if (timeBlockStart.isBefore(start) && timeBlockEnd.isAfter(end)) { + return false; + // in the case where timeBlockStart is before start and timeBlockEnd is before end + } else if (timeBlockStart.isBefore(start) && timeBlockEnd.isBefore(end)) { + return false; + // if the start time same as start time of block, return false + } else if (timeBlockStart.isEqual(start)) { + return false; + // if the end time same as end time of block, return false + } else if (timeBlockEnd.isEqual(end)) { + return false; + // in the case where timeBlockStart is after start time and timeBlockEnd is after end time + } else return !(timeBlockStart.isAfter(start) && timeBlockEnd.isAfter(end)); + } + + + public ArrayList getTaskFromId(StudentUser user, HashMap hashMap) { + ArrayList userTasks = new ArrayList<>(); + + ArrayList toDoList = user.getToDoList(); + + for (String taskId : toDoList) { + Task task_value = hashMap.get(taskId); + userTasks.add(task_value); + } + return userTasks; + } + + /** + * Get the task object from the task map given the name of the task + * @param taskName - the name of the task + * @param hashMap - hashmap of task ids to tasks + * @return the task object that corresponds to the task name + */ + public CollaborativeTask getTaskObjectFromName(String taskName, HashMap hashMap) { + for (Task task : hashMap.values()) { + if (task.getTitle().equals(taskName) && task instanceof CollaborativeTask) { + return (CollaborativeTask) task; + } + } + throw new RuntimeException("Task does not exist"); + } + + /** + * Convert the given string to a LocalDateTime object + * @param stringTime - the string representation of a date time + * @return the string formatted as LocalDateTime + */ + public LocalDateTime convertStringToLocalDateTime(String stringTime) { + DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + return LocalDateTime.parse(stringTime, format); + } + +} diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java b/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java new file mode 100644 index 0000000..5c0941c --- /dev/null +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java @@ -0,0 +1,8 @@ +package scheduling_ct_use_case; + +public interface ScheduleCTOutputBoundary { + + ScheduleCTResponseModel prepareNoConflictView(ScheduleCTResponseModel responseModel); + + ScheduleCTResponseModel prepareFailView(String error); +} diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java new file mode 100644 index 0000000..a4ded81 --- /dev/null +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java @@ -0,0 +1,40 @@ +package scheduling_ct_use_case; + +// use case layer + +/* + Notes: + - requests what is needed for its input data (what person in front of computer enters) + - do NOT depend on anything NOR have any references to Entity objects: violates SRP + */ + +public class ScheduleCTRequestModel { + + private final String taskName; + + private final String username; + + private final String startTime; + + private final String endTime; + + public ScheduleCTRequestModel(String taskName, String username, String startTime, String endTime) { + this.taskName = taskName; + this.username = username; + this.startTime = startTime; + this.endTime = endTime; + } + + public String getTaskName() { + return taskName; + } + public String getUsername() { return username; } + public String getStartTime() { + return startTime; + } + public String getEndTime() { + return endTime; + } + + +} diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java b/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java new file mode 100644 index 0000000..8cb80ba --- /dev/null +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java @@ -0,0 +1,23 @@ +package scheduling_ct_use_case; + +public class ScheduleCTResponseModel { + + private final boolean isConflict; + private String displayString; + + public ScheduleCTResponseModel(boolean isConflict) { + + this.isConflict = isConflict; + } + + public boolean getIsConflict() { + return isConflict; + } + + public String getDisplayString() { + return displayString; + } + public void setDisplayString(String displayString) { + this.displayString = displayString; + } +} From e48ecaf0cb6b3a65687e4cd9c0904d9c45fbf8d4 Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 19:19:23 -0500 Subject: [PATCH 2/6] Added javadocs --- .../ScheduleCTInteractor.java | 51 ++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java index 3bafa7a..76d4791 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java @@ -15,6 +15,12 @@ public ScheduleCTInteractor(ScheduleCTOutputBoundary scheduleCTOutputBoundary) { this.scheduleCTOutputBoundary = scheduleCTOutputBoundary; } + /** + * Overriding the method in input boundary + * @param requestModel - input that user enters (includes task name, username, start, end) + * @param hashMap - a hash map of all task ids mapped to tasks + * @return a response model + */ @Override public ScheduleCTResponseModel schedule(ScheduleCTRequestModel requestModel, HashMap hashMap) { // returns that this has conflict @@ -55,6 +61,14 @@ public ScheduleCTResponseModel schedule(ScheduleCTRequestModel requestModel, Has } } + /** + * Finds all the dates to meet up given the frequency of a task + * @param frequency - either "daily", "weekly" or "monthly" + * @param startTime - the start time of the time block + * @param endTime - the end time of the time block + * @param deadline - the deadline of the task + * @return an array list of array lists of local date time (i.e. the dates to meet up) + */ public ArrayList> getDates(String frequency, LocalDateTime startTime, LocalDateTime endTime, LocalDateTime deadline) { ArrayList> times = new ArrayList<>(); ArrayList initialTime = new ArrayList<>(); @@ -103,7 +117,14 @@ public ArrayList> getDates(String frequency, LocalDateT return times; } - + /** + * Check if a user is available at a fixed date time + * @param user - the student user + * @param tasks - an array list of a user's tasks + * @param start - the start time of the time block + * @param end -the end time of the time block + * @return whether or not the user is available at this date time + */ public boolean isUserAvailableAtDateTime(StudentUser user, ArrayList tasks, LocalDateTime start, LocalDateTime end) { // assume there's a method in TaskUseCase that gets all the tasks a student has @@ -162,10 +183,14 @@ public boolean isUserAvailableAtDateTime(StudentUser user, ArrayList tasks return is_task_free && is_working_hours_free; } - // required methods: - // - for each user determine if they have conflict with time given from their tasks - // - for each user determine if they have conflict with time given with their working hours - + /** + * Check if a time block conflicts with a user's working hours + * @param timeBlockStart - the start of the time block + * @param timeBlockEnd - the end of the time block + * @param workingHoursStart - the start of a user's working hours + * @param workingHoursEnd - the end of a user's working hours + * @return whether or not a time block conflicts with a user's working hours + */ public boolean workingHoursFree(LocalDateTime timeBlockStart, LocalDateTime timeBlockEnd, LocalTime workingHoursStart, LocalTime workingHoursEnd) { // if timeBlock is within working hours @@ -194,6 +219,15 @@ public boolean workingHoursFree(LocalDateTime timeBlockStart, LocalDateTime time } else return !(timeBlockStart.getHour() > workingHoursStart.getHour() && timeBlockEnd.getHour() > workingHoursEnd.getHour()); } + + /** + * Check if two time blocks conflict + * @param timeBlockStart - the start of the time block + * @param timeBlockEnd - the end of the time block + * @param start - the start of another time block + * @param end - the end of another time block + * @return whether or not two time blocks conflict + */ public boolean givenTime(LocalDateTime timeBlockStart, LocalDateTime timeBlockEnd, LocalDateTime start, LocalDateTime end) { // in the case where the time block is within the time of start and end @@ -215,7 +249,12 @@ public boolean givenTime(LocalDateTime timeBlockStart, LocalDateTime timeBlockEn } else return !(timeBlockStart.isAfter(start) && timeBlockEnd.isAfter(end)); } - + /** + * Retrieve the tasks associated with a user from the given hash map + * @param user - the student user + * @param hashMap - a hash map of all task ids to tasks + * @return an array list of tasks + */ public ArrayList getTaskFromId(StudentUser user, HashMap hashMap) { ArrayList userTasks = new ArrayList<>(); From 2bf87fed6c312e0568171bfa3581b7b77c4bd003 Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 19:32:11 -0500 Subject: [PATCH 3/6] Fixed an error (mislabeled text panel) --- src/main/java/scheduling_ct_screens/EnterTimeAndTask.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java index 893b5a1..877bce8 100644 --- a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java +++ b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java @@ -28,7 +28,7 @@ public EnterTimeAndTask(ScheduleCTController scheduleCTController) { LabelTextPanel taskInfo = new LabelTextPanel(new JLabel("Enter task title"), taskTitle); - LabelTextPanel userInfo = new LabelTextPanel(new JLabel("Enter task title"), taskTitle); + LabelTextPanel userInfo = new LabelTextPanel(new JLabel("Enter user name"), username); LabelTextPanel startInfo = new LabelTextPanel(new JLabel("Enter start time"), startTime); From 99ec1950e65d77da9758c852944649006d3230c6 Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 19:42:31 -0500 Subject: [PATCH 4/6] Added some javadocs for files --- .../java/scheduling_ct_screens/EnterTimeAndTask.java | 6 +++--- .../java/scheduling_ct_screens/LabelTextPanel.java | 4 ++++ .../scheduling_ct_screens/ScheduleCTController.java | 6 +++++- .../scheduling_ct_screens/ScheduleCTPresenter.java | 5 +++++ .../ScheduleCTInputBoundary.java | 5 ++++- .../scheduling_ct_use_case/ScheduleCTInteractor.java | 10 ++++++---- .../ScheduleCTOutputBoundary.java | 5 +++++ .../scheduling_ct_use_case/ScheduleCTRequestModel.java | 9 +++------ .../ScheduleCTResponseModel.java | 7 ++++++- 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java index 877bce8..bcc3f5d 100644 --- a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java +++ b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java @@ -1,13 +1,13 @@ package scheduling_ct_screens; -import scheduling_ct_use_case.*; import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; - - +/** + * The View for the Scheduling Collaborative Tasks Use Case + */ public class EnterTimeAndTask extends JFrame implements ActionListener { diff --git a/src/main/java/scheduling_ct_screens/LabelTextPanel.java b/src/main/java/scheduling_ct_screens/LabelTextPanel.java index a5ba101..d6dc19a 100644 --- a/src/main/java/scheduling_ct_screens/LabelTextPanel.java +++ b/src/main/java/scheduling_ct_screens/LabelTextPanel.java @@ -4,6 +4,10 @@ // Frameworks/Drivers layer +/** + * UI helper class that creates labeled text panel + */ + public class LabelTextPanel extends JPanel { public LabelTextPanel(JLabel label, JTextField textField) { this.add(label); diff --git a/src/main/java/scheduling_ct_screens/ScheduleCTController.java b/src/main/java/scheduling_ct_screens/ScheduleCTController.java index ccf318e..22c6fb0 100644 --- a/src/main/java/scheduling_ct_screens/ScheduleCTController.java +++ b/src/main/java/scheduling_ct_screens/ScheduleCTController.java @@ -1,10 +1,14 @@ package scheduling_ct_screens; import entities.Task; import scheduling_ct_use_case.*; -import entities.TaskMap; import java.util.HashMap; +/** + * Controller for the Scheduling Collaborative Tasks Use Case + * Triggers the interactor + */ + public class ScheduleCTController { final ScheduleCTInputBoundary scheduleInput; diff --git a/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java b/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java index ddff186..a5e0104 100644 --- a/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java +++ b/src/main/java/scheduling_ct_screens/ScheduleCTPresenter.java @@ -1,6 +1,11 @@ package scheduling_ct_screens; import scheduling_ct_use_case.*; +/** + * Presenter for the Collaborative Scheduling Use Case + * Implements the Output Boundary as part of the dependency inversion + */ + public class ScheduleCTPresenter implements ScheduleCTOutputBoundary { @Override diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java index 60ea67e..12b8365 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInputBoundary.java @@ -3,7 +3,10 @@ import entities.Task; import java.util.HashMap; -// use case layer +/** + * Input Boundary interface for the Scheduling Collaborative Tasks Use Case + * (inverts dependency from Controller to Interactor) + */ public interface ScheduleCTInputBoundary { diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java index 76d4791..b155080 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java @@ -8,6 +8,11 @@ import java.util.ArrayList; import java.util.HashMap; +/** + * Scheduling Collaborative Tasks Use Case Interactor (use case layer) + * Implements business logic on entities + */ + public class ScheduleCTInteractor implements ScheduleCTInputBoundary { private final ScheduleCTOutputBoundary scheduleCTOutputBoundary; @@ -16,10 +21,7 @@ public ScheduleCTInteractor(ScheduleCTOutputBoundary scheduleCTOutputBoundary) { } /** - * Overriding the method in input boundary - * @param requestModel - input that user enters (includes task name, username, start, end) - * @param hashMap - a hash map of all task ids mapped to tasks - * @return a response model + * The main controller of this interactor that calls the helper methods */ @Override public ScheduleCTResponseModel schedule(ScheduleCTRequestModel requestModel, HashMap hashMap) { diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java b/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java index 5c0941c..03c9ca0 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTOutputBoundary.java @@ -1,5 +1,10 @@ package scheduling_ct_use_case; +/** + * Output Boundary for the Scheduling Collaborative Tasks Use Case + * (inverts dependency for interactor to presenter) + */ + public interface ScheduleCTOutputBoundary { ScheduleCTResponseModel prepareNoConflictView(ScheduleCTResponseModel responseModel); diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java index a4ded81..1d35931 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java @@ -1,11 +1,8 @@ package scheduling_ct_use_case; -// use case layer - -/* - Notes: - - requests what is needed for its input data (what person in front of computer enters) - - do NOT depend on anything NOR have any references to Entity objects: violates SRP +/** + * Request Model for the Scheduling Collaborative Tasks Use Case + * Acts as the input data object in the use case layer */ public class ScheduleCTRequestModel { diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java b/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java index 8cb80ba..17c4b24 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTResponseModel.java @@ -1,9 +1,14 @@ package scheduling_ct_use_case; +/** + * Response Model for the Scheduling Collaborative Tasks Use Case + * Acts as the output data object in the use case layer + */ + public class ScheduleCTResponseModel { private final boolean isConflict; - private String displayString; + String displayString; public ScheduleCTResponseModel(boolean isConflict) { From 905b3b617ed0cd57be2dcfbdf96549cbeb79d8f2 Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 20:33:36 -0500 Subject: [PATCH 5/6] Modified files to take in a StudentUser parameter --- .../scheduling_ct_screens/EnterTimeAndTask.java | 6 +----- .../ScheduleCTController.java | 14 +++++++++++--- .../ScheduleCTInteractor.java | 7 +++++++ .../ScheduleCTRequestModel.java | 15 ++++++++++----- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java index bcc3f5d..172c81e 100644 --- a/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java +++ b/src/main/java/scheduling_ct_screens/EnterTimeAndTask.java @@ -13,7 +13,6 @@ public class EnterTimeAndTask extends JFrame implements ActionListener { ScheduleCTController scheduleCTController; JTextField taskTitle = new JTextField(15); - JTextField username = new JTextField(15); JTextField startTime = new JTextField(15); JTextField endTime = new JTextField(15); @@ -28,8 +27,6 @@ public EnterTimeAndTask(ScheduleCTController scheduleCTController) { LabelTextPanel taskInfo = new LabelTextPanel(new JLabel("Enter task title"), taskTitle); - LabelTextPanel userInfo = new LabelTextPanel(new JLabel("Enter user name"), username); - LabelTextPanel startInfo = new LabelTextPanel(new JLabel("Enter start time"), startTime); LabelTextPanel endInfo = new LabelTextPanel(new JLabel("Enter end time"), endTime); @@ -49,7 +46,6 @@ public EnterTimeAndTask(ScheduleCTController scheduleCTController) { main.add(title); main.add(taskInfo); - main.add(userInfo); main.add(startInfo); main.add(endInfo); main.add(buttons); @@ -62,7 +58,7 @@ public EnterTimeAndTask(ScheduleCTController scheduleCTController) { // React to button click that results in evt public void actionPerformed(ActionEvent evt) { // System.out.println("Click" + evt.getActionCommand()); - scheduleCTController.isConflict(taskTitle.getText(), username.getText(), startTime.getText(), endTime.getText()); + scheduleCTController.isConflict(taskTitle.getText(), startTime.getText(), endTime.getText()); } diff --git a/src/main/java/scheduling_ct_screens/ScheduleCTController.java b/src/main/java/scheduling_ct_screens/ScheduleCTController.java index 22c6fb0..d0f576a 100644 --- a/src/main/java/scheduling_ct_screens/ScheduleCTController.java +++ b/src/main/java/scheduling_ct_screens/ScheduleCTController.java @@ -1,4 +1,5 @@ package scheduling_ct_screens; +import entities.StudentUser; import entities.Task; import scheduling_ct_use_case.*; @@ -15,17 +16,24 @@ public class ScheduleCTController { private final HashMap hashMap; - public ScheduleCTController(ScheduleCTInputBoundary scheduleInput, HashMap hashMap) { + private final StudentUser studentUser; + + public ScheduleCTController(ScheduleCTInputBoundary scheduleInput, HashMap hashMap, StudentUser studentUser) { this.scheduleInput = scheduleInput; this.hashMap = hashMap; + this.studentUser = studentUser; } public HashMap getTaskMap() { return hashMap; } - public ScheduleCTResponseModel isConflict(String taskName, String username, String startTime, String endTime) { - ScheduleCTRequestModel inputData = new ScheduleCTRequestModel(taskName, username, startTime, endTime); + public StudentUser getStudentUser() { + return studentUser; + } + + public ScheduleCTResponseModel isConflict(String taskName, String startTime, String endTime) { + ScheduleCTRequestModel inputData = new ScheduleCTRequestModel(taskName, startTime, endTime, studentUser); return scheduleInput.schedule(inputData, this.hashMap); } diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java index b155080..b959a12 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTInteractor.java @@ -28,7 +28,14 @@ public ScheduleCTResponseModel schedule(ScheduleCTRequestModel requestModel, Has // returns that this has conflict // otherwise will automatically schedule and return a success view + CollaborativeTask task = getTaskObjectFromName(requestModel.getTaskName(), hashMap); + + if (requestModel.getStudentUser() != task.getLeader()) { + return scheduleCTOutputBoundary.prepareFailView("User is not the leader. " + + "You don't have scheduling access"); + } + ArrayList users = task.getTeammates(); users.add(task.getLeader()); diff --git a/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java index 1d35931..7a09f6a 100644 --- a/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java +++ b/src/main/java/scheduling_ct_use_case/ScheduleCTRequestModel.java @@ -1,5 +1,7 @@ package scheduling_ct_use_case; +import entities.StudentUser; + /** * Request Model for the Scheduling Collaborative Tasks Use Case * Acts as the input data object in the use case layer @@ -9,23 +11,22 @@ public class ScheduleCTRequestModel { private final String taskName; - private final String username; - private final String startTime; private final String endTime; - public ScheduleCTRequestModel(String taskName, String username, String startTime, String endTime) { + private final StudentUser studentUser; + + public ScheduleCTRequestModel(String taskName, String startTime, String endTime, StudentUser studentUser) { this.taskName = taskName; - this.username = username; this.startTime = startTime; this.endTime = endTime; + this.studentUser = studentUser; } public String getTaskName() { return taskName; } - public String getUsername() { return username; } public String getStartTime() { return startTime; } @@ -33,5 +34,9 @@ public String getEndTime() { return endTime; } + public StudentUser getStudentUser() { + return studentUser; + } + } From 18278b2841319c46e2626cbb4b4a509da36414bf Mon Sep 17 00:00:00 2001 From: alyson647 Date: Mon, 21 Nov 2022 23:30:45 -0500 Subject: [PATCH 6/6] Attempt to resolve merge conflict --- src/main/java/entities/CollaborativeTask.java | 71 +++++++------------ 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/src/main/java/entities/CollaborativeTask.java b/src/main/java/entities/CollaborativeTask.java index a84fe1c..d94c4bb 100644 --- a/src/main/java/entities/CollaborativeTask.java +++ b/src/main/java/entities/CollaborativeTask.java @@ -22,6 +22,7 @@ public class CollaborativeTask extends Task implements Timeblockable { * * @param title - the title of the Collaborative Task * @param id - the unique ID of the Collaborative Task + * @param priority - the priority value of the Collaborative Task * @param recurring - whether the Collaborative Task is recurring * @param frequency - the frequency at which the Collaborative Task occurs (if recurring) * @param startTime = the start time and date of the first occurrence of the Collaborative Task @@ -123,19 +124,22 @@ public void setDeadline(LocalDateTime deadline) { // The following four methods (getTimeBlock, setTimeBlock, scheduleTimeBlock, and removeTimeBlock) are here because this class implements Timeblockable/ // Based on the way Collaborative Tasks are scheduled (Feature 5), not sure if they remain necessary. + /** * Set the time block of a Collaborative Task + * * @return - the time block of the Collaborative Task - * - in array form: {startTime, endTime} + * - in array form: {startTime, endTime} */ public LocalDateTime[] getTimeBlock() { - return new LocalDateTime[] {this.startTime, this.endTime}; + return new LocalDateTime[]{this.startTime, this.endTime}; } /** * Set a new time block and then schedule it + * * @param startTime - the start of the time block - * @param endTime - the end of the time block + * @param endTime - the end of the time block */ public void setTimeBlock(LocalDateTime startTime, LocalDateTime endTime) { this.startTime = startTime; @@ -145,6 +149,7 @@ public void setTimeBlock(LocalDateTime startTime, LocalDateTime endTime) { /** * Schedule a time block for the user + * * @return - whether the time block has been successfully scheduled */ public boolean scheduleTimeBlock() { @@ -153,6 +158,7 @@ public boolean scheduleTimeBlock() { /** * Remove a time block from the user's schedule + * * @return - whether the time block has been successfully removed */ public boolean removeTimeBlock() { @@ -202,24 +208,13 @@ public ArrayList getTeammates() { } /** - * To be used when invitations to join a Collaborative Task are accepted. - * - * @param newTeammates - an Array List of Student Users who are to be added as teammates. - */ - public void addTeammates(ArrayList newTeammates) { - this.teammates.addAll(newTeammates); - } - - /** - * When this method is used by the leader of the Collaborative Task, - * the oldTeammates parameter can contain any Student User in the Collaborative Task's teammates list. - * When this method is used by any other teammate of the Collaborative Task, - * the oldTeammates parameter can only contain themselves. + * Set a new Array List of Student User teammates. + * To be used when invitations are accepted, teammates are removed by leader, or teammates remove themselves. * - * @param oldTeammates - an Array List of Student Users who are to be removed as teammates. + * @param teammates - an Array List of Student Users who are to be added as teammates. */ - public void removeTeammates(ArrayList oldTeammates) { - this.teammates.removeAll(oldTeammates); + public void setTeammates(ArrayList teammates) { + this.teammates = teammates; } /** @@ -231,23 +226,15 @@ public ArrayList getPendingTeammates() { } /** - * To be used when invitations to join a Collaborative Task are sent. + * Set a new Array List of Student User pending teammates. + * To be used when invitations to join a Collaborative Task are sent, canceled, or responded to. * - * @param newTeammates - an Array List of Student Users who are being invited to join the Collaborative Task. + * @param pendingTeammates - an Array List of Student Users who are being invited to join the Collaborative Task. */ - public void addPendingTeammates(ArrayList newTeammates) { - this.pendingTeammates.addAll(newTeammates); + public void setPendingTeammates(ArrayList pendingTeammates) { + this.pendingTeammates = pendingTeammates; } - /** - * To be used when invitations to join a Collaborative Task are canceled or responded to. - * - * @param oldTeammates - an Array List of Student Users who are no longer undergoing the process of being - * invited to join the Collaborative Task. - */ - public void removePendingTeammates(ArrayList oldTeammates) { - this.pendingTeammates.removeAll(oldTeammates); - } /** * @return an Array List of all Student Users who have declined invitations to join the Collaborative Task. @@ -257,22 +244,14 @@ public ArrayList getDeclinedTeammates() { } /** - * To be used when invitations to join a Collaborative Task are declined. + * Set a new Array List of Student User declined teammates. + * To be used when invitations to join a Collaborative Task are declined or when a Student User who has previously + * declined an invitation to join the Collaborative Task has accepted a reinvitation to join. * - * @param newTeammates - an Array List of Student Users who have declined invitations to join the Collaborative Task. + * @param declinedTeammates - an Array List of Student Users who have declined invitations to join the Collaborative Task. */ - public void addDeclinedTeammates(ArrayList newTeammates) { - this.declinedTeammates.addAll(newTeammates); + public void setDeclinedTeammates(ArrayList declinedTeammates) { + this.declinedTeammates = declinedTeammates; } - /** - * To be used when a Student User who has previously declined an invitation to join the Collaborative Task has - * accepted a reinvitation to join. - * - * @param oldTeammates - an Array List of Student Users who have accepted an invitation to join the Collaborative - * Task after previously declining such an invitation. - */ - public void removeDeclinedTeammates(ArrayList oldTeammates) { - this.declinedTeammates.removeAll(oldTeammates); - } } \ No newline at end of file