Skip to content

Commit fa1e735

Browse files
authored
Merge pull request #53 from Maurice2n97/branch-add-Profile-Picture
Branch add profile picture
2 parents 90f132f + 48d54ae commit fa1e735

64 files changed

Lines changed: 611 additions & 387 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ dependencies {
6262
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
6363
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'
6464

65+
6566
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
6667

6768
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
69+
70+
6871
}
6972

7073
shadowJar {

config/checkstyle/checkstyle.xml

Lines changed: 130 additions & 130 deletions
Large diffs are not rendered by default.

src/main/java/seedu/address/MainApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import seedu.address.logic.LogicManager;
1818
import seedu.address.model.Model;
1919
import seedu.address.model.ModelManager;
20-
import seedu.address.model.person.AddressBook;
21-
import seedu.address.model.person.ReadOnlyAddressBook;
2220
import seedu.address.model.ReadOnlyUserPrefs;
2321
import seedu.address.model.UserPrefs;
22+
import seedu.address.model.person.AddressBook;
23+
import seedu.address.model.person.ReadOnlyAddressBook;
2424
import seedu.address.model.util.SampleDataUtil;
2525
import seedu.address.storage.AddressBookStorage;
2626
import seedu.address.storage.JsonAddressBookStorage;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package seedu.address.commons.util;
2+
3+
4+
5+
6+
import javafx.scene.image.Image;
7+
8+
9+
public class ImageRequestUtil {
10+
11+
public static final String BASIC_IMAGE_REQUEST_URL = "https://www.gravatar.com/avatar/%s";
12+
public static final String SIZE_REQUEST = "?s=104";
13+
public static final String DEFAULT_IMAGE_REQUEST = "d=robohash";
14+
public static final String FILE_EXTENSION = ".jpg";
15+
16+
17+
/**
18+
* generates the image request URL from an email. The image request URL
19+
* will be used to get the image from Gravatar account associated to the email.
20+
*
21+
* @param email the email of the gravatar account.
22+
* @return the URL string of image request
23+
* @throws Exception when it is unable to get the hash correctly.
24+
*/
25+
26+
public static String generateImageRequest(String email) throws Exception {
27+
String hash = MD5Util.md5Hex(email.toLowerCase());
28+
String urlString = String.format(BASIC_IMAGE_REQUEST_URL
29+
+ FILE_EXTENSION
30+
+ SIZE_REQUEST
31+
+ "&"
32+
+ DEFAULT_IMAGE_REQUEST, hash
33+
);
34+
return urlString;
35+
}
36+
37+
38+
/**
39+
* Fetches Gravatar Image from Gravatar server given an email of the Gravatar avatar.
40+
*
41+
* @param email email of the Gravatar avatar
42+
* @return the javafx Image of the avatar
43+
* @throws Exception when unable to fetch image.
44+
*/
45+
46+
public static Image getGravatarImage(String email) throws Exception {
47+
String urlString = generateImageRequest(email);
48+
Image image = new Image(urlString);
49+
if (image.isError()) {
50+
throw new IllegalArgumentException("failed to load image");
51+
}
52+
return image;
53+
}
54+
55+
}
56+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package seedu.address.commons.util;
2+
3+
import java.security.MessageDigest;
4+
5+
/**
6+
* A Utility class for returning the MD5 hash of some input string.
7+
* This class is used by {@link ImageRequestUtil}
8+
*/
9+
10+
public class MD5Util {
11+
/**
12+
* Encodes a byte[] array into hexadecimal string.
13+
*
14+
* @param array of bytes
15+
* @return the hexadecimal string
16+
*/
17+
public static String hex(byte[] array) {
18+
StringBuffer sb = new StringBuffer();
19+
for (int i = 0; i < array.length; ++i) {
20+
sb.append(Integer.toHexString((array[i]
21+
& 0xFF) | 0x100).substring(1, 3));
22+
}
23+
return sb.toString();
24+
}
25+
26+
/**
27+
* Hashes a string using MD5 algorithm and returns it in hexadecimal format.
28+
*
29+
* @param message the input string to be hashed.
30+
* @return hexed md5-hash of input string
31+
* @throws Exception if messageDigest library fails to hash.
32+
*/
33+
34+
public static String md5Hex(String message) throws Exception {
35+
MessageDigest md = MessageDigest.getInstance("MD5");
36+
return hex(md.digest(message.getBytes("CP1252")));
37+
}
38+
}
39+
//code from http://en.gravatar.com/site/implement/images/java/

src/main/java/seedu/address/logic/Logic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import seedu.address.model.Model;
1111
import seedu.address.model.meeting.Meeting;
1212
import seedu.address.model.meeting.ReadOnlyMeetingBook;
13-
import seedu.address.model.person.ReadOnlyAddressBook;
1413
import seedu.address.model.person.Person;
14+
import seedu.address.model.person.ReadOnlyAddressBook;
1515

1616
/**
1717
* API of the Logic component

src/main/java/seedu/address/logic/LogicManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import seedu.address.model.Model;
1616
import seedu.address.model.meeting.Meeting;
1717
import seedu.address.model.meeting.ReadOnlyMeetingBook;
18-
import seedu.address.model.person.ReadOnlyAddressBook;
1918
import seedu.address.model.person.Person;
19+
import seedu.address.model.person.ReadOnlyAddressBook;
2020
import seedu.address.storage.Storage;
2121

2222
/**

src/main/java/seedu/address/logic/commands/meetings/AddMeetingCommand.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package seedu.address.logic.commands.meetings;
22

3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
7+
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
8+
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
9+
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME;
10+
311
import seedu.address.logic.commands.Command;
412
import seedu.address.logic.commands.CommandResult;
513
import seedu.address.logic.commands.exceptions.CommandException;
614
import seedu.address.model.Model;
715
import seedu.address.model.meeting.Meeting;
816

9-
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME;
10-
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME;
11-
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
12-
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY;
13-
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
14-
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION;
15-
16-
import static java.util.Objects.requireNonNull;
1717

1818
public class AddMeetingCommand extends Command {
1919
public static final String COMMAND_WORD = "addm";
@@ -49,14 +49,14 @@ public AddMeetingCommand(Meeting meeting) {
4949
}
5050

5151
@Override
52-
public CommandResult execute(Model Model) throws CommandException {
53-
requireNonNull(Model);
52+
public CommandResult execute(Model model) throws CommandException {
53+
requireNonNull(model);
5454

55-
if (Model.hasMeeting(toAdd)) {
55+
if (model.hasMeeting(toAdd)) {
5656
throw new CommandException(MESSAGE_DUPLICATE_MEETING);
5757
}
5858

59-
Model.addMeeting(toAdd);
59+
model.addMeeting(toAdd);
6060
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
6161
}
6262

src/main/java/seedu/address/logic/commands/persons/AddPersonCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import static java.util.Objects.requireNonNull;
44
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
55
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
67
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
78
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
8-
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
99

1010
import seedu.address.logic.commands.Command;
1111
import seedu.address.logic.commands.CommandResult;

src/main/java/seedu/address/logic/commands/persons/ClearPersonCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import seedu.address.logic.commands.Command;
66
import seedu.address.logic.commands.CommandResult;
7-
import seedu.address.model.person.AddressBook;
87
import seedu.address.model.Model;
8+
import seedu.address.model.person.AddressBook;
99

1010
/**
1111
* Clears the address book.

0 commit comments

Comments
 (0)