diff --git a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java index c3c9ae0a34f5..d971c5ab8abd 100644 --- a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java @@ -1,9 +1,5 @@ package seedu.address.logic.commands; -import static java.util.Objects.requireNonNull; - -import java.util.List; - import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.logic.CommandHistory; @@ -11,10 +7,12 @@ import seedu.address.model.Model; import seedu.address.model.transaction.Transaction; -/** - * Uploads the photo of the transaction in a transaction for record keeping purposes. - */ -public class UploadPhotoCommand extends Command { +import java.util.List; + +import static java.util.Objects.requireNonNull; + + +public class UploadPhotoCommand extends Command{ public static final String COMMAND_WORD = "uploadphoto"; public static final String COMMAND_ALIAS = "uploadp"; @@ -22,7 +20,7 @@ public class UploadPhotoCommand extends Command { + ": upload image to that transaction contact"; private String filePath; - private Index imageindex; + private Index photoIndex; public UploadPhotoCommand(Index index, String path) { @@ -31,7 +29,7 @@ public UploadPhotoCommand(Index index, String path) { requireNonNull(index); requireNonNull(path); - imageindex = index; + photoIndex = index; filePath = path; } @@ -43,13 +41,16 @@ public CommandResult execute(Model model, CommandHistory history) throws Command int lastPersonListIndex = lastTransactionList.size(); - int thatPerson = imageindex.getZeroBased(); + int thatPersonIndex = photoIndex.getZeroBased(); - if (thatPerson >= lastPersonListIndex) { + if (thatPersonIndex >= lastPersonListIndex ) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } +// = lastPersonList.get(thatPersonIndex); + +// model.updateFilteredPersonList(); return null; } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index dfbb838cf41c..85e4786539a1 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -1,13 +1,13 @@ package seedu.address.model.person; -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import seedu.address.model.tag.Tag; import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; -import seedu.address.model.tag.Tag; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; /** * Represents a Person in the address book. @@ -16,13 +16,14 @@ public class Person { // Identity fields + private final Email email; private final Name name; private final Phone phone; - private final Email email; // Data fields private final Address address; private final Set tags = new HashSet<>(); + private Photo photo; /** * Parameterized constructor that takes in a UniqueId argument diff --git a/src/main/java/seedu/address/model/person/Photo.java b/src/main/java/seedu/address/model/person/Photo.java index cce5af7d1002..7df8fe12f347 100644 --- a/src/main/java/seedu/address/model/person/Photo.java +++ b/src/main/java/seedu/address/model/person/Photo.java @@ -9,31 +9,32 @@ import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import static java.util.Objects.requireNonNull; +/** + * Each Person should have a photo + */ public class Photo { public static final String DEFAULT_MESSAGE_PHOTO = "Filepath be less than 10MB and FilePath must be valid "; public static final String DEFAULT_PHOTO = "images/default_person.png"; + + private static final int tenMB = 1048576; private static final String FOLDER = getOperatingPath(); - //cannot be blank space - //double space equals to one in java private static final String PHOTO_INTITAL_REGEX_ = "[^\\s].*"; - private static final int tenMB = 1048576; private String photoPath; - - public Photo(){ + public Photo() { this.photoPath = DEFAULT_PHOTO; } - public Photo(String path){ + public Photo(String path) { requireNonNull(path); - if(checkPath(path)){ + if (checkPath(path)) { this.photoPath = path; - } else{ + } else { this.photoPath = DEFAULT_PHOTO; } @@ -48,10 +49,13 @@ public Photo(String filePath, String newPhoto) throws IllegalValueException { } //link to the path this.photoPath = FOLDER + "//" + newPhoto; - - makePhoto( filePath, newPhoto); + makePhoto(filePath, newPhoto); } + /** + * Make a photo + */ + private void makePhoto(String filePath, String newPhoto) { makePhotoFolder(); @@ -62,13 +66,10 @@ private void makePhoto(String filePath, String newPhoto) { //create file object File pictureFinal = new File(FOLDER + "//" + newPhoto); + + //if cannot get file object create an empty object - - //if cannot get file object create an empty object - - - if (!pictureFinal.exists() ) { - + if (!pictureFinal.exists()) { try { pictureFinal.createNewFile(); } catch (IOException e) { @@ -80,89 +81,106 @@ private void makePhoto(String filePath, String newPhoto) { try { Files.copy(getImage.toPath(), pictureFinal.toPath(), REPLACE_EXISTING); - this.photoPath =pictureFinal.toPath().toString(); - } catch (IOException e){ + this.photoPath = pictureFinal.toPath().toString(); + } catch (IOException e) { e.printStackTrace(); - } } + /** + * Make a photoFolder + */ - public void makePhotoFolder(){ + public void makePhotoFolder() { File locationFolder = new File(FOLDER); - if ( !locationFolder.exists()) { + if (!locationFolder.exists()) { locationFolder.mkdir(); } } + /** + * Check Operating System of User + */ - - - private static String getOperatingPath(){ - String oSystem = System.getProperty("os.name"); + private static String getOperatingPath() { + String oSystem = System.getProperty("os.name"); //mac - if (oSystem.contains("mac")){ - return System.getProperty("user.home") +"/Documents/cs2103/debt-tracker/PhotoFolder"; - } - //windows - else{ - return System.getenv("APPDATA")+"/PhotoFolder"; + if (oSystem.contains("mac")) { + return System.getProperty("user.home") + "/Documents/cs2103/debt-tracker/PhotoFolder"; + } else { + return System.getenv("APPDATA") + "/PhotoFolder"; } } - private static String getOsName(){ + /** + * Get Operating System of User + */ + + private static String getOsName() { return System.getProperty("os.name"); } + /** + * Get Photo Path + */ - public String getPicturePath(){ + public String getPhoto() { return this.photoPath; } - public static boolean checkPath(String path){ + /** + * Check Photo Path of User + */ - if(path.equals(DEFAULT_PHOTO)){ + public static boolean checkPath(String path) { + + if (path.equals(DEFAULT_PHOTO)) { return true; } - if( path.matches(PHOTO_INTITAL_REGEX_) ){ - return checkPicture(path); + if (path.matches(PHOTO_INTITAL_REGEX_)) { + return checkPicture(path); + } return false; } - public static boolean checkPicture(String path){ + /** + * Photo Validation + */ + public static boolean checkPicture(String path) { File pictureNew = new File(path); - try{ - if (ImageIO.read(pictureNew) == null) + try { + if (ImageIO.read(pictureNew) == null) { return false; + } - } catch (IOException error){ + } catch (IOException error) { return false; } - if (pictureNew.length() > tenMB){ + if (pictureNew.length() > tenMB) { return false; } - + return true; - - } - - - - + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Photo // instanceof handles nulls + && this.photoPath.equals(((Photo) other).photoPath)); + } }