From d7584b770695f626ccf7a555f78f851241323878 Mon Sep 17 00:00:00 2001 From: weiqing-nic Date: Tue, 16 Oct 2018 23:13:03 +0800 Subject: [PATCH 1/3] Save work --- .../logic/commands/UploadPhotoCommand.java | 36 ++++++++++--------- .../seedu/address/model/person/Person.java | 14 +++++--- .../seedu/address/model/person/Photo.java | 9 +++-- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java index c011bb772758..da7d5b3a852d 100644 --- a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java @@ -1,13 +1,6 @@ package seedu.address.logic.commands; import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.person.Person; -import static java.util.Objects.requireNonNull; -import seedu.address.logic.commands.exceptions.*; - - -import seedu.address.commons.core.Messages; import seedu.address.logic.CommandHistory; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -18,10 +11,6 @@ import static java.util.Objects.requireNonNull; -import java.util.List; -import seedu.address.model.Model; - - public class UploadPhotoCommand extends Command{ public static final String COMMAND_WORD = "uploadphoto"; @@ -29,7 +18,7 @@ public class UploadPhotoCommand extends Command{ private String path; private String filePath; - private Index imageindex; + private Index photoIndex; public static final String MESSAGE_USAGE = COMMAND_WORD + ": upload image to that person contact"; @@ -40,8 +29,8 @@ public UploadPhotoCommand(Index index, String imagePath){ requireNonNull(index); requireNonNull(imagePath); - imageindex = index; - path = path; + photoIndex = index; + path = imagePath; } @@ -52,12 +41,27 @@ public CommandResult execute(Model model, CommandHistory history) throws Command int lastPersonListIndex = lastPersonList.size(); - int thatPerson = imageindex.getZeroBased(); + int thatPersonIndex = photoIndex.getZeroBased(); + + int editedPerson; - 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 56d03b3f4c06..74c2b146d6cf 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -1,14 +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 seedu.address.model.transaction.Transaction; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; /** * Represents a Person in the address book. @@ -25,6 +24,7 @@ public class Person { // Data fields private final Address address; private final Set tags = new HashSet<>(); + private Photo photo; /** * Every field must be present and not null. @@ -68,7 +68,13 @@ public Address getAddress() { return address; } - public UniqueId getUniqueId() { return uniqueId; } + public UniqueId getUniqueId() { + return uniqueId; + } + + public Photo getPhoto() { + return photo; + } /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} diff --git a/src/main/java/seedu/address/model/person/Photo.java b/src/main/java/seedu/address/model/person/Photo.java index a85eb6294b99..9072976861cc 100644 --- a/src/main/java/seedu/address/model/person/Photo.java +++ b/src/main/java/seedu/address/model/person/Photo.java @@ -120,7 +120,7 @@ private static String getOsName(){ } - public String getPicturePath(){ + public String getPhoto(){ return this.photoPath; } @@ -161,7 +161,12 @@ public static boolean checkPicture(String path){ } - + @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)); + } From 49f2ff1fa438a09b6f2afacd3718c8d391b1c35c Mon Sep 17 00:00:00 2001 From: weiqing-nic Date: Tue, 16 Oct 2018 23:16:31 +0800 Subject: [PATCH 2/3] Merge changes --- .../logic/commands/UploadPhotoCommand.java | 24 ------------------- .../seedu/address/model/person/Person.java | 15 ------------ 2 files changed, 39 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java index dbb2a49f658d..07d795fdda0e 100644 --- a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java @@ -1,12 +1,4 @@ package seedu.address.logic.commands; -<<<<<<< HEAD -======= - -import static java.util.Objects.requireNonNull; - -import java.util.List; - ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.logic.CommandHistory; @@ -14,17 +6,10 @@ import seedu.address.model.Model; import seedu.address.model.transaction.Transaction; -<<<<<<< HEAD import static java.util.Objects.requireNonNull; public class UploadPhotoCommand extends Command{ -======= -/** - * Uploads the photo of the transaction in a transaction for record keeping purposes. - */ -public class UploadPhotoCommand extends Command { ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec public static final String COMMAND_WORD = "uploadphoto"; public static final String COMMAND_ALIAS = "uploadp"; @@ -41,13 +26,8 @@ public UploadPhotoCommand(Index index, String path) { requireNonNull(index); requireNonNull(path); -<<<<<<< HEAD photoIndex = index; path = imagePath; -======= - imageindex = index; - filePath = path; ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec } @@ -62,11 +42,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command int editedPerson; -<<<<<<< HEAD if (thatPersonIndex >= lastPersonListIndex ) { -======= - if (thatPerson >= lastPersonListIndex) { ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 51a32e8b12ba..21d1f87479f0 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -7,11 +7,7 @@ import java.util.Objects; import java.util.Set; -<<<<<<< HEAD -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; -======= import seedu.address.model.tag.Tag; ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec /** * Represents a Person in the address book. @@ -57,17 +53,6 @@ public Address getAddress() { return address; } -<<<<<<< HEAD - public UniqueId getUniqueId() { - return uniqueId; - } - - public Photo getPhoto() { - return photo; - } - -======= ->>>>>>> 62ae91b7be5ee063260e9a6d45587902dc3600ec /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. From ab25e74693b08bd6375d16f36eb08f7597886a84 Mon Sep 17 00:00:00 2001 From: weiqing-nic Date: Tue, 16 Oct 2018 23:45:35 +0800 Subject: [PATCH 3/3] Styling Changes --- .../logic/commands/UploadPhotoCommand.java | 17 +-- .../seedu/address/model/person/Person.java | 4 +- .../seedu/address/model/person/Photo.java | 101 ++++++++++-------- 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java index 07d795fdda0e..d971c5ab8abd 100644 --- a/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UploadPhotoCommand.java @@ -1,4 +1,5 @@ package seedu.address.logic.commands; + import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; import seedu.address.logic.CommandHistory; @@ -6,6 +7,8 @@ import seedu.address.model.Model; import seedu.address.model.transaction.Transaction; +import java.util.List; + import static java.util.Objects.requireNonNull; @@ -27,7 +30,7 @@ public UploadPhotoCommand(Index index, String path) { requireNonNull(path); photoIndex = index; - path = imagePath; + filePath = path; } @@ -40,8 +43,6 @@ public CommandResult execute(Model model, CommandHistory history) throws Command int thatPersonIndex = photoIndex.getZeroBased(); - int editedPerson; - if (thatPersonIndex >= lastPersonListIndex ) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @@ -51,16 +52,6 @@ public CommandResult execute(Model model, CommandHistory history) throws Command // 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 21d1f87479f0..85e4786539a1 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -7,7 +7,7 @@ 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,9 +16,9 @@ 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; diff --git a/src/main/java/seedu/address/model/person/Photo.java b/src/main/java/seedu/address/model/person/Photo.java index 9072976861cc..bd8bb5ae597c 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(); @@ -63,11 +67,9 @@ 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(); @@ -80,85 +82,100 @@ 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 getPhoto(){ + public String getPhoto() { return this.photoPath; } - public static boolean checkPath(String path){ + /** + * Check Photo Path of User + */ + + public static boolean checkPath(String path) { - if(path.equals(DEFAULT_PHOTO)){ + 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 @@ -168,6 +185,4 @@ public boolean equals(Object other) { && this.photoPath.equals(((Photo) other).photoPath)); } - - }