diff --git a/src/main/java/Model_Classes/Meeting.java b/src/main/java/Model_Classes/Meeting.java index e8938a5907..aa8841fb62 100644 --- a/src/main/java/Model_Classes/Meeting.java +++ b/src/main/java/Model_Classes/Meeting.java @@ -22,8 +22,8 @@ public Meeting(String description, Date at) { this.isFixedDuration = false; } - public Meeting (String description, int duration, TimeUnit unit) { - super(description, null); + public Meeting (String description, Date date, int duration, TimeUnit unit) { + super(description, date); this.duration = duration; this.timeUnit = unit; this.isFixedDuration = true; @@ -36,7 +36,7 @@ public Meeting (String description, int duration, TimeUnit unit) { @Override public String toString() { if (isFixedDuration){ - return "[M]" + super.toString() + " (in: " + duration + " " + timeUnit.toString() + ")"; + return "[M]" + super.toString() + " (on: " + super.getDate() + ") (duration: " + duration + " " + timeUnit.toString() + ")"; } else { return "[M]" + super.toString() + " (on: " + super.getDate() + ")"; } diff --git a/src/main/java/Model_Classes/Task.java b/src/main/java/Model_Classes/Task.java index ac0fc96204..d464196e31 100644 --- a/src/main/java/Model_Classes/Task.java +++ b/src/main/java/Model_Classes/Task.java @@ -47,7 +47,7 @@ public String getUser() { * @return time the task was created */ - public void setUser(String user) { + public void setAssignee(String user) { this.user = user; } diff --git a/src/main/java/Operations/RecurHandler.java b/src/main/java/Operations/RecurHandler.java index 9117a62fd8..0ec6f2fc2f 100644 --- a/src/main/java/Operations/RecurHandler.java +++ b/src/main/java/Operations/RecurHandler.java @@ -51,14 +51,14 @@ public boolean checkRecurrence() { Assignment recurringAssignment= new Assignment(description, getNewDate(check)); recurringAssignment.setRecurrenceSchedule(type); recurringAssignment.setPriority(check.getPriority()); - recurringAssignment.setUser(check.getUser()); + recurringAssignment.setAssignee(check.getUser()); taskList.replace(index, recurringAssignment); isEdited = true; } else { Meeting recurringMeeting= new Meeting(description, getNewDate(check)); recurringMeeting.setRecurrenceSchedule(type); recurringMeeting.setPriority(check.getPriority()); - recurringMeeting.setUser(check.getUser()); + recurringMeeting.setAssignee(check.getUser()); taskList.replace(index, recurringMeeting); isEdited = true; } diff --git a/src/main/java/Operations/Storage.java b/src/main/java/Operations/Storage.java index a70c1347ba..a1555ae5fb 100644 --- a/src/main/java/Operations/Storage.java +++ b/src/main/java/Operations/Storage.java @@ -96,7 +96,7 @@ public ArrayList loadFile(String fileName) throws RoomShareException { // Assignment type Assignment assignment = new Assignment(description, date); assignment.setPriority(priority); - assignment.setUser(user); + assignment.setAssignee(user); assignment.setRecurrenceSchedule(recurrence); assignment.setDone(done); if (scanSubTask.length() != 0) assignment.setSubTasks(scanSubTask); @@ -104,9 +104,9 @@ public ArrayList loadFile(String fileName) throws RoomShareException { } else { //Meeting type if (isFixedDuration) { - Meeting meeting = new Meeting(description, duration, unit); + Meeting meeting = new Meeting(description, date, duration, unit); meeting.setPriority(priority); - meeting.setUser(user); + meeting.setAssignee(user); meeting.setRecurrenceSchedule(recurrence); meeting.setDone(done); taskArrayList.add(meeting); @@ -114,7 +114,7 @@ public ArrayList loadFile(String fileName) throws RoomShareException { Meeting meeting = new Meeting(description, date); meeting.setRecurrenceSchedule(recurrence); meeting.setPriority(priority); - meeting.setUser(user); + meeting.setAssignee(user); meeting.setDone(done); taskArrayList.add(meeting); } @@ -224,8 +224,7 @@ String convertForStorage(Task task) throws RoomShareException { String month = dateFormat.format(date); String[] timeArray = tempString[4].split(":", 3); String day = tempString[3]; - String recurrence = task.getRecurrenceSchedule().toString(); - time = day + "/" + month + "/" + year + " " + timeArray[0] + ":" + timeArray[1] + '#' + recurrence +"#"; + time = day + "/" + month + "/" + year + " " + timeArray[0] + ":" + timeArray[1]; // if (task instanceof FixedDuration) { // String[] durationArray = prelimSplit[3].split(":"); // String temp = durationArray[1].trim(); diff --git a/src/main/java/Operations/TaskCreator.java b/src/main/java/Operations/TaskCreator.java index 112b35c5e8..e1d7252577 100644 --- a/src/main/java/Operations/TaskCreator.java +++ b/src/main/java/Operations/TaskCreator.java @@ -1,7 +1,6 @@ package Operations; import CustomExceptions.RoomShareException; -import Enums.ExceptionType; import Enums.Priority; import Enums.RecurrenceScheduleType; import Enums.TimeUnit; @@ -9,7 +8,6 @@ import Model_Classes.Meeting; import Model_Classes.Task; import java.util.Timer; -import java.util.TimerTask; import java.util.Date; @@ -21,30 +19,45 @@ public TaskCreator() { } public Task create(String input) throws RoomShareException { - Priority priorityType; - RecurrenceScheduleType recurrenceScheduleType; - String assignee; - // extract the description - String[] descriptionArray = input.split("\\("); - String[] descriptionArray2 = descriptionArray[1].trim().split("\\)"); - String description = descriptionArray2[0].trim(); + // extract the Task Type + String[] typeArray = input.split("#"); + String type = typeArray[1]; + // extract the priority String[] priorityArray = input.split("\\*"); + Priority priority; if (priorityArray.length != 1) { - String priority = priorityArray[1].trim(); + String inputPriority = priorityArray[1].trim(); try { - priorityType = Priority.valueOf(priority); + priority = Priority.valueOf(inputPriority); } catch (IllegalArgumentException e) { System.out.println("There seems to some mistake in your priority entry, will be setting priority as low"); - priorityType = Priority.low; + priority = Priority.low; } } else { - priorityType = Priority.low; + priority = Priority.low; + } + + // extract the description + String[] descriptionArray = input.split("\\("); + String[] descriptionArray2 = descriptionArray[1].trim().split("\\)"); + String description = descriptionArray2[0].trim(); + + // extract date + String dateArray[] = input.split("&"); + String dateInput = dateArray[1].trim(); + Date date; + try { + date = new Parser().formatDate(dateInput); + } catch (RoomShareException e) { + System.out.println("Wrong date format"); + date = new Date(); } // extract the assignee String[] assigneeArray = input.split("@"); + String assignee; if (assigneeArray.length != 1) { assignee = assigneeArray[1].trim(); } else { @@ -53,97 +66,59 @@ public Task create(String input) throws RoomShareException { // extract recurrence schedule String[] recurrenceArray = input.split("%"); + RecurrenceScheduleType recurrence; if (recurrenceArray.length != 1) { - String recurrence = recurrenceArray[1].trim(); + String inputRecurrence = recurrenceArray[1].trim(); try { - recurrenceScheduleType = RecurrenceScheduleType.valueOf(recurrence); + recurrence = RecurrenceScheduleType.valueOf(inputRecurrence); } catch (IllegalArgumentException e) { System.out.println("There seems to some mistake in your recurrence entry, will be setting recurrence as none"); - recurrenceScheduleType = RecurrenceScheduleType.none; + recurrence = RecurrenceScheduleType.none; } } else { - recurrenceScheduleType = RecurrenceScheduleType.none; + recurrence = RecurrenceScheduleType.none; } - // extract the Task Type - String[] type = input.split("#"); - // extract the time - String[] timeArray = input.split("&"); - String[] durationArray = timeArray[1].split(" "); - String[] durationLength = durationArray[1].split("-"); - TimeUnit unit = TimeUnit.minutes; - int duration =0; - if (timeArray.length != 1 && durationLength.length < 1) { - // not a fixed duration task - String time = timeArray[1].trim(); - // create the time - Date by; - try { - by = parser.formatDate(time); - } catch (RoomShareException e) { - by = new Date(); - } - if (type[1].contains("assignment")) { - Assignment createdTask = new Assignment(description, by); - createdTask.setPriority(priorityType); - createdTask.setUser(assignee); - createdTask.setRecurrenceSchedule(recurrenceScheduleType); - return createdTask; - } else { - //checks for time clashes before creating Meeting - if( !CheckAnomaly.checkTime(by) ) { - Meeting createdTask = new Meeting(description, by); - createdTask.setPriority(priorityType); - createdTask.setUser(assignee); - createdTask.setRecurrenceSchedule(recurrenceScheduleType); - return createdTask; - } else { - throw new RoomShareException(ExceptionType.timeClash); - } - } - } else if (durationLength.length > 1){ - duration = Integer.parseInt(durationLength[1]) - Integer.parseInt(durationLength[0]); - //need to change this section - if(durationArray[1].contains("r")) { - TaskReminder taskReminder = new TaskReminder(description, duration); - taskReminder.start(); - } - if((duration % 100) == 0) { - duration = duration % 9; - unit = TimeUnit.valueOf("hours"); - Meeting meeting = new Meeting(description, duration, unit); - meeting.setPriority(priorityType); - meeting.setUser(assignee); - meeting.setRecurrenceSchedule(recurrenceScheduleType); + + //extract duration + String[] durationArray = input.split("\\^"); + String[] inputDuration = durationArray[1].split(" "); + int duration; + TimeUnit unit; + try { + duration = Integer.parseInt(inputDuration[0].trim()); + unit = TimeUnit.valueOf(inputDuration[1].trim()); + } + catch (IllegalArgumentException e) { + duration = 0; + unit = TimeUnit.unDefined; + } + + if (type.contains("assignment")) { + Assignment assignment = new Assignment(description,date); + assignment.setPriority(priority); + assignment.setAssignee(assignee); + assignment.setRecurrenceSchedule(recurrence); + return assignment; + } + + if (type.contains("meeting")) { + if (unit.equals(TimeUnit.unDefined)) { + // duration was not specified or not correctly input + Meeting meeting = new Meeting(description,date); + meeting.setPriority(priority); + meeting.setAssignee(assignee); + meeting.setRecurrenceSchedule(recurrence); return meeting; - } else { - if( !CheckAnomaly.checkTime(duration, unit) ) { - Meeting meeting = new Meeting(description, duration, unit); - meeting.setPriority(priorityType); - meeting.setUser(assignee); - meeting.setRecurrenceSchedule(recurrenceScheduleType); - return meeting; - } else { - throw new RoomShareException(ExceptionType.timeClash); - } } - } else { - // fixed duration task - // extract the fixed duration timing - String[] fixedDurationArray = input.split("\\^"); - String[] tempArray = fixedDurationArray[1].split("\\s+"); - duration = Integer.parseInt(tempArray[0].trim()); - unit = TimeUnit.valueOf(tempArray[1].toLowerCase().trim()); - - //reminder function - if(durationArray[1].contains("r")) { - TaskReminder taskReminder = new TaskReminder(description, duration); - taskReminder.start(); + else { + Meeting meeting = new Meeting(description, date, duration, unit); + meeting.setPriority(priority); + meeting.setAssignee(assignee); + meeting.setRecurrenceSchedule(recurrence); + return meeting; } - Meeting meeting = new Meeting(description, duration, unit); - meeting.setPriority(priorityType); - meeting.setUser(assignee); - meeting.setRecurrenceSchedule(recurrenceScheduleType); - return meeting; } + + return null; } } \ No newline at end of file