Skip to content

Commit

Permalink
WriteNotification class created - write to text file
Browse files Browse the repository at this point in the history
  • Loading branch information
ongweekeong committed Sep 27, 2018
1 parent ee1b4b6 commit 37e96eb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 13 deletions.
13 changes: 3 additions & 10 deletions src/seedu/addressbook/inbox/Inbox.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package seedu.addressbook.inbox;

import seedu.addressbook.inbox.Msg;

import seedu.addressbook.data.exception.IllegalValueException;
import seedu.addressbook.data.person.*;
import seedu.addressbook.data.tag.Tag;

import java.security.Timestamp;
import java.util.HashSet;
import java.util.Set;

public class Inbox {
// all messages will be stored here, notifications will appear based on severity and timestamp.
public static final String MESSAGE_STORAGE_FILEPATH = "notifications.txt";
public static final String COMMAND_WORD = "inbox";
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" + "Opens up list of unread notifications. \n\t"
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_PROMPT = "Press 'Enter' to take action for Message 1";
public static int unreadMsgs = 0;
private Msg message;
WriteNotification myMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH);

public enum Priority{
HIGH, // For messages that require HPQ intervention
MED, // For messages that only require PO back-up
Expand Down
18 changes: 16 additions & 2 deletions src/seedu/addressbook/inbox/Msg.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package seedu.addressbook.inbox;

import java.util.Date;
import java.security.Timestamp;

/** Msg has the following attributes:
* @params Priority, timestamp, message, location (x,y coordinates) and ETA.
* Priority, timestamp and message are compulsory fields. Location and ETA are optional.
*/


public class Msg {
private String newMsg;
private Priority priority;
private double x, y;
private int eta;
private int eta = -1;
private String comment;
public boolean isRead = false;
public boolean isLocationAvailable = false;
private Timestamp time;
private enum Priority {
HIGH, // For messages that require HPQ intervention
Expand Down Expand Up @@ -39,6 +45,7 @@ public String getMsg(){
public void setLocation(double x, double y, double min){
this.x = x;
this.y = y;
isLocationAvailable = true;
}

public double getLongitude(){
Expand All @@ -55,6 +62,13 @@ public int getEta(){
return this.eta;
}

public boolean hasEta(){
if(eta == -1)
return false;
else
return true;
}

public void setTime(Timestamp time){
this.time = time;
}
Expand Down
4 changes: 4 additions & 0 deletions src/seedu/addressbook/inbox/NotificationManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.addressbook.inbox;

public class NotificationManager {
}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/inbox/ReadNotification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seedu.addressbook.inbox;

public class ReadNotification {
}
47 changes: 47 additions & 0 deletions src/seedu/addressbook/inbox/WriteNotification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.addressbook.inbox;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class WriteNotification {
private String path;
private boolean isAppend = false;

public WriteNotification(String filePath){
path = filePath;
}

public WriteNotification(String filePath, boolean appendValue){
path = filePath;
isAppend = appendValue;
}


/** Message format should look like this
* Read/Unread (1 or 0) --> for writeToFile function, messages are entered as unread.
* Priority of Message
* Timestamp of message
* Message
* ETA, if applicable
* Location, if available
*/

public void writeToFile(Msg message) throws IOException{
FileWriter write = new FileWriter (path, isAppend);
PrintWriter myPrinter = new PrintWriter(write);
myPrinter.println(message.isRead);
myPrinter.println(message.getPriority());
myPrinter.println(message.getTime());
myPrinter.println(message.getMsg());
if(message.hasEta())
myPrinter.println(message.getEta());
if(message.isLocationAvailable) {
myPrinter.println(message.getLatitude());
myPrinter.println(message.getLongitude());
}
myPrinter.println("---"); // Notate the end of 1 message entry with "---"
myPrinter.close();
}

}
1 change: 0 additions & 1 deletion src/seedu/addressbook/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class StorageFile {

/** Default file path used if the user doesn't provide the file name. */
public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt";
public static final String MESSAGE_STORAGE_FILEPATH = "notifications.txt";
/* Note: Note the use of nested classes below.
* More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html
*/
Expand Down

0 comments on commit 37e96eb

Please sign in to comment.