/** * This method allows the user to mark task as completed * * @param taskID the taskID is used to search for the task in the storage * @return it will return successful when a task is marked as completed, else otherwise. */ public Notification doTask(ArrayList<Integer> taskIds) { Notification n = new Notification(); ArrayList<Integer> validIds = new ArrayList<Integer>(); for (int id : taskIds) { // fliters out non-existent ids if (Storage.getTask(id) != null) { validIds.add(id); } } // check if the validIds is empty if (validIds.isEmpty()) { n.setTitle(Keywords.MESSAGE_ERROR); } else if (validIds.size() > 1) { // shows that there will be definitely // more than 1 task been completed n.setTitle(Keywords.MESSAGE_COMPLETED_SUCCESS); n.setMessage(validIds.toString()); } else { // there is only 1 task to be completed n.setTitle(Keywords.MESSAGE_COMPLETED_SUCCESS); n.setMessage(Storage.getTask(validIds.get(Keywords.FIRST_ELEMENT)).getUserFormat() + "done!"); } for (int taskID : validIds) { doTask(taskID); } // Add to history the action to be done super.addToHistory("do"); super.synchronization(); return n; }
private Notification makeNotification(Properties p) { Notification notification = new Notification(); String id = p.getProperty("notificationID"); String description = p.getProperty("description"); notification.setId(Integer.parseInt(id)); notification.setMessage(description); notification.setRecipient(queryNotificationTo(Integer.parseInt(id))); Event event = queryNotificationEvent(Integer.parseInt(id)); notification.setEvent(event); return notification; }