Skip to content

Commit

Permalink
Merge pull request #254 from tanjiajiajun/branch-RegexBugFix
Browse files Browse the repository at this point in the history
Regex bugfix for link. email, and telegram
  • Loading branch information
darryl-chan authored Apr 14, 2024
2 parents f186fa3 + 9ed2f2c commit 25a1db3
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 57 deletions.
30 changes: 15 additions & 15 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ This section describes some noteworthy details on how certain features are imple
* Each `Timetable` contains <u>1 to 7</u> `Day` objects, by default, 5 days of the week (Monday - Friday) is used.
* Each `Day` object can contain <u>0 to 24</u> 1-hour `Period` objects, or less if each `Period` has intervals longer
than 1 hour.
* Each `Period` is defined by the start time and end time, indicated by integers on a 24-hour clock,
* Each `Period` is defined by the start time and end time, indicated by integers on a 24-hour clock,
i.e. 0-23, which refers to 12 AM till 11 PM.
* Each `Day` cannot contain any overlapping `Period`.
* An overlap occurs when the start time of the previous `Period` is before the end time of the next `Period`.
* An overlap occurs when the start time of the previous `Period` is before the end time of the next `Period`.
* E.g. for the case of `Period` of 12-14, `Period` of 14-16 is allowed, but `Period` of 13-15 is not.
* If not specified in the `add` command, or subsequently modified using the `edit` command, the `Timetable` is assumed
to be empty, indicating no occupied period.
Expand All @@ -189,7 +189,7 @@ This section describes some noteworthy details on how certain features are imple

* The `Timetable` of the `Student` can be specified during the `add` command, indicated with a `c/` prefix.
* Similarly, the `Timetable` of a `Student` can be modified during the `edit` command, with the same prefix.
* The `c/` prefix is optional, and if not specified,
* The `c/` prefix is optional, and if not specified,
an empty `Timetable` object will be created as the attribute of the `Student`.
* The arguments for the `Timetable` object can be broken down into its respective day and periods that day contains.
* The day is indicated by its respective prefix as well, the format is `{DAY_3_LETTERS}:`, e.g. `"mon:"` or `"fri:"`.
Expand All @@ -201,7 +201,7 @@ This section describes some noteworthy details on how certain features are imple

#### Finding Common Slots from list of Students (can be filtered)

The finding a common slot feature will have a portion implemented similarly to the `find` command.
The finding a common slot feature will have a portion implemented similarly to the `find` command.
The command consists of a mandatory specified duration, and optional arguments for higher specificity,
and a common empty slot across all students that fulfils the duration requirement will be outputted to the user.

Expand All @@ -213,22 +213,22 @@ and a common empty slot across all students that fulfils the duration requiremen
* if not specified, defaults to 8 AM to 10 PM.
* `o/` is an optional argument for on which days specifically to look for slots.
* if not specified, defaults to Monday to Friday.

* Examples:
* `slot d/1` - EduConnect will look through the current list of students, i.e. can be the full list, or a filtered
list if ran after the `find` command, then returns all the 1-hour slot(s) available for the week.
* `slot d/2 t/tutorial-1` - EduConnect will first filter and get the list of students with the tag `tutorial-1`,
* `slot d/2 t/tutorial-1` - EduConnect will first filter and get the list of students with the tag `tutorial-1`,
then return all the 2-hour slot(s) available for the week.
* `slot d/3 p/12-18 o/tue, wed, thu t/tutorial-2` - EduConnect will first filter and get the list of students
with the tag `tutorial-2`, then returns all the 3-hour slot(s) available,
between 12 PM to 6 PM, on Tuesdays, Wednesdays, and Thursdays only.

* The command's execution will iterate through the selected list of students, accessing each `Timetable` object's
list of `Day` objects.
* Each `Day` object will look for valid `Period` that does not overlap with its own list of `Period` objects.
* The series of valid `Period` and `Day` will be collected from each `Timetable` of each `Student`,
and returned as an `AvailableSlots` objects, which is collected in a `List`.
* Common slots across all `AvailableSlots` will then be filtered out
* The series of valid `Period` and `Day` will be collected from each `Timetable` of each `Student`,
and returned as an `AvailableSlots` objects, which is collected in a `List`.
* Common slots across all `AvailableSlots` will then be filtered out
and returned as a singular `AvailableSlots` object.

* The diagram below shows the sequence diagram for an example execution of finding common slots.
Expand All @@ -248,7 +248,7 @@ The inclusion of the `Link` attribute enhances the versatility of EduConnect, en

#### UI implementation

* A student's weblink will be displayed using the JavaFX `Hyperlink` class at `StudentCard.java`.
* A student's weblink will be displayed using the JavaFX `Hyperlink` class at `StudentCard.java`.
* Due to potential UI issues arising from excessively long URLs, a clickable embedded text labeled "Project Link" will be displayed instead of the actual URL.
* If the student has a valid Link, the Hyperlink will be visible and clickable, allowing users to access the weblink directly.
* If the student does not have a Link attribute or if the Link is not specified, the Hyperlink will be toggled to be invisible, ensuring a clean and uncluttered user interface.
Expand Down Expand Up @@ -599,7 +599,7 @@ testers are expected to do more *exploratory* testing.
## **Appendix C: Effort**

#### Overview
- Our team aims at creating an application that is easy to use and helpful for TAs to manage courses. We mainly focused on features that are optimized for CLI users.
- Our team aims at creating an application that is easy to use and helpful for TAs to manage courses. We mainly focused on features that are optimized for CLI users.
- In addition to the existing basic features of AB3 (Address Book 3), we implement additional features including finding students, copying emails, and finding common slots for our target users - TAs.

#### Difficulty Level and Challenges Faced
Expand All @@ -609,12 +609,12 @@ testers are expected to do more *exploratory* testing.

#### Effort Required

- Efforts were allocated across various project phases, including requirement analysis, design, development, testing, deployment, and debugging.
- Efforts were allocated across various project phases, including requirement analysis, design, development, testing, deployment, and debugging.

- We also emphasized considerable efforct on team collaboration to make the development process smooth.

#### Achievements
- Successful implementation of core functionalities, including
- Successful implementation of core functionalities, including
finding common slots and copying student emails, which showcases our goal of creating an application with user-centric features.

- Implementation of GUI(Graphic User Interface) which aligns with the UI design as outlined in the project planning phase.
Expand All @@ -627,4 +627,4 @@ Team Size: 6
1. **Use a better font:** User experience is greatly influenced by font, and choosing the right font can significantly enhance readability, Especially for EduConnect with numeric details of students displayed, the current font causes confusion sometimes. TWe plan to adapt a new font which not only improve the overall appearance of the platform but also contribute to a smoother reading experience for users.
2. **Hover over ‘Project Link’ shows the full link:** Currently, when hovering over the project link, nothing is showing. We plan to provide users with the convenience of viewing the full link by simply hovering over it. We aim to allow users to quickly verify or copy the complete URL without having to click on it.
3. **Better timetable display:** The current timetable of each student is displayed in text with little formatting. We plan to enhance the timetable display by incorporating a standardized graphical format, such as calendar or grid layout. This would allow users to quickly grasp their schedules at a glance and navigate through different time slots more efficiently.
4. **View student details:** The ability to view comprehensive details of each student in text, including their project link and timetable, is essential for effective management and communication within EduConnect. We plan to introduce a new "View Student" function, allowing users to access all student information conveniently.
4. **View student details:** The ability to view comprehensive details of each student in text, including their project link and timetable, is essential for effective management and communication within EduConnect. We plan to introduce a new "View Student" function, allowing users to access all student information conveniently.
16 changes: 10 additions & 6 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ EduConnect is a **desktop app for managing student contacts, optimized for use v

* `list` : Lists all students.

* `add n/John Doe s/A1234567X h/@john.doe e/[email protected] t/tutorial-1 t/high-ability` : Adds a contact named `John Doe` to the Address Book.
* `add n/John Doe s/A1234567X h/@john_doe e/[email protected] t/tutorial-1 t/high-ability` : Adds a contact named `John Doe` to the Address Book.

* `delete s/A0001234A` : Deletes the person with the `s/STUDENT_ID` unique identifier

Expand Down Expand Up @@ -188,7 +188,10 @@ Format: `add n/NAME s/STUDENT_ID e/EMAIL h/TELEGRAM_HANDLE [l/WEBLINK] [c/TIMETA
</box>

Examples:
* `add n/John Doe s/A1234567X h/@john.doe e/[email protected] l/https://github.com/johndoe/tp t/tutorial-1 t/high-ability c/mon: 8-10, 10-12 tue: 11-13 thu: 12-15, 15-17`

* `add n/John Doe s/A1234567X h/@john_doe e/[email protected] t/tutorial-1 t/high-ability c/mon: 8-10, 10-12 tue:
11-13 thu: 12-15, 15-17`

* `add n/Anne-Marie Rose Nicholson t/singer t/songwriter e/[email protected] h/@AnneMarieofficial s/A7041991U`
![result for 'add n/Anne-Marie Rose Nicholson t/singer t/songwriter e/[email protected] h/@AnneMarieofficial s/A7041991U'](images/add.png)

Expand All @@ -206,8 +209,9 @@ Format: `list [timetable]`

Examples:
* `list`
* `list timetable`
* `list timetable`
![result for 'list timetable'](images/listTimetable.png)

### Editing a student: `edit`

Edits an existing student.
Expand Down Expand Up @@ -241,7 +245,7 @@ Finds students whose criteria match all the given keywords.
Format: `find <choose 1 or more> [n/NAME] [s/STUDENT_ID] [h/TELEGRAM_HANDLE] [t/TAG]…`

* The search is case-insensitive. e.g. `find n/hans` will match Hans.
* The order of the keywords do not matter. e.g. `find n/hans t/tutorial-1` will return the same result as `find
* The order of the keywords do not matter. e.g. `find n/hans t/tutorial-1` will return the same result as `find
t/tutorial-1 n/hans`.
* Name and other criteria are searched using fuzzy matching.
* Students with any part of the names matching the keyword will be returned.
Expand All @@ -266,7 +270,7 @@ Copy student emails to the clipboard.
Format: `copy [t/TAG]…`

* When no tags are supplied, copies all student emails.
* When multiple tags are used, copies emails of all students that has **ALL** the tags specified.
* When multiple tags are used, copies emails of all students that has **ALL** the tags specified.
* Tag is searched as complete tag names. e.g. `copy t/tutorial-1` will only return those with a tag 'tutorial-1'
(tag 'tutorial-10', 'tutorial-11', etc. will NOT be copied)
* Copied emails are in the form of `[email protected], [email protected], [email protected]` and adheres to the format specified in [section 3.4 of RFC5322](https://tools.ietf.org/html/rfc5322#section-3.4).
Expand All @@ -277,7 +281,7 @@ Format: `copy [t/TAG]…`
Examples:
* `copy` copies all emails
* `copy t/tutorial-2` copies 3 emails (`[email protected], [email protected], [email protected]` all with `tutorial-2` tag)
* `copy t/tutorial-2 t/strong-student` copies 1 email (`[email protected]` with both `tutorial-2` and `strong-student` tag)
* `copy t/tutorial-2 t/strong-student` copies 1 email (`[email protected]` with both `tutorial-2` and `strong-student` tag)

### Deleting a student: `delete`

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/educonnect/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AddCommand extends Command {
+ "Example1: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_STUDENT_ID + "A1234567X "
+ PREFIX_TELEGRAM_HANDLE + "@john.doe "
+ PREFIX_TELEGRAM_HANDLE + "@john_doe "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_LINK + "https://github.com/johndoe/tp "
+ PREFIX_TAG + "tutorial-1 "
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/educonnect/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ public class EditCommand extends Command {
+ "[" + PREFIX_LINK + "WEBLINK] "
+ "[" + PREFIX_TIMETABLE + "TIMETABLE] "
+ "[" + PREFIX_TAG + "TAG]...\n\n"

+ "Example 1: " + COMMAND_WORD + " " + EDIT_ID_PREFIX_INDEX + "1 "
+ PREFIX_TELEGRAM_HANDLE + "@john.doe "
+ "Example 1: " + COMMAND_WORD + " 1 "
+ PREFIX_TELEGRAM_HANDLE + "@john_doe "
+ PREFIX_STUDENT_ID + "A1234567X "
+ PREFIX_EMAIL + "[email protected] \n\nEdits the student id and email address "
+ "of the 1st student to be A1234567X and [email protected] respectively.\n\n"
Expand Down
35 changes: 25 additions & 10 deletions src/main/java/educonnect/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static educonnect.commons.util.CollectionUtil.requireAllNonNull;
import static educonnect.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static educonnect.model.student.Link.VALIDATION_REGEX;
import static java.util.Objects.requireNonNull;

import java.time.DayOfWeek;
Expand All @@ -10,7 +11,12 @@
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import educonnect.MainApp;
import educonnect.commons.core.LogsCenter;
import educonnect.commons.core.index.Index;
import educonnect.commons.util.StringUtil;
import educonnect.logic.commands.SlotsCommand;
Expand Down Expand Up @@ -40,7 +46,7 @@ public class ParserUtil {
"Invalid day specified! "
+ "Each day is indicated by their 3-letter identifier, e.g. 'mon', or 'fri'.\n"
+ "(Hint: by default Saturdays and Sundays are not included.)";

private static final Logger logger = LogsCenter.getLogger(MainApp.class);
/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it. Leading and trailing whitespaces will be
* trimmed.
Expand Down Expand Up @@ -134,7 +140,8 @@ public static String createCapitalStudentId(String trimmedId) {
*/
public static TelegramHandle parseTelegramHandle(String telegramHandle) throws ParseException {
requireNonNull(telegramHandle);
String trimmedHandle = telegramHandle.trim();
String lowerHandle = telegramHandle.toLowerCase();
String trimmedHandle = lowerHandle.trim();
if (!TelegramHandle.isValidTelegramHandle(trimmedHandle)) {
throw new ParseException(TelegramHandle.MESSAGE_CONSTRAINTS);
}
Expand All @@ -149,7 +156,8 @@ public static TelegramHandle parseTelegramHandle(String telegramHandle) throws P
*/
public static Email parseEmail(String email) throws ParseException {
requireNonNull(email);
String trimmedEmail = email.trim();
String lowerEmail = email.toLowerCase();
String trimmedEmail = lowerEmail.trim();
if (!Email.isValidEmail(trimmedEmail)) {
throw new ParseException(Email.MESSAGE_CONSTRAINTS);
}
Expand Down Expand Up @@ -317,14 +325,21 @@ public static HashSet<DayOfWeek> parseDaysSpecified(String days) throws ParseExc
*
* @throws ParseException if the given {@code link} is invalid.
*/
public static Link parseLink(String s) throws ParseException {
requireNonNull(s);
String trimmedLink = s.trim();
if (!Link.isValidLink(trimmedLink)) {
System.out.println("Invalid link");
public static Link parseLink(String url) throws ParseException {
requireNonNull(url);
url = url.trim();
Pattern p = Pattern.compile(VALIDATION_REGEX);
Matcher m = p.matcher(url); //url is https://example.com
if (!m.matches()) {
throw new ParseException(Link.MESSAGE_CONSTRAINTS);
}
System.out.println("Valid link");
return new Link(trimmedLink);

if (m.group("scheme") == null) {
logger.info("No scheme found!"); //if url does not contain ftp/http/https
url = "https://" + url;
}


return new Link(url);
}
}
28 changes: 21 additions & 7 deletions src/main/java/educonnect/model/student/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@
public class Link {

public static final String MESSAGE_CONSTRAINTS = "Please provide a valid website.";
// @@author tanjiajiajun-reused
// Reused from https://stackoverflow.com/questions/42618872/regex-for-website-or-url-validation,
// under Mustofa Rizwan's response
public static final String VALIDATION_REGEX =
"^((ftp|http|https):\\/\\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_-]+(\\.[a-zA-Z]+)+((\\/)[\\w#]+)"
+ "*(\\/\\w+\\?[a-zA-Z0-9_]+=\\w+(&[a-zA-Z0-9_]+=\\w+)*)?\\/?$";
//@@author
// @@author jeremiahlzz
// Solution below inspired by https://stackoverflow.com/questions/42618872/regex-for-website-or-url-validation
// Regex groups match plan:
// 1) scheme ftp/http/https
// 2) ssh username
// 3) ssh password
// 4) sub-domain(s) including www.
// 5) domain name
// 6) gTLD (generic top-level domain) e.g. .com
// 7) ccTLD (country-code top-level domain) e.g. .sg
// 8) port number e.g. 8080
// 9) path e.g. /file/file
// 10) query string e.g. ?something
// 11) fragment e.g. #something
public static final String VALIDATION_REGEX = "^(?<scheme>(?:ftp|https?):\\/\\/)?+(?:(?<username>[a-zA-Z][\\w-.]"
+ "{0,31})(?::(?<password>[!-~&&[^@$\\n\\r]]{6,255}))?@)?(?<subdomain>(?:[a-zA-Z0-9][a-zA-Z0-9-]{0,61}"
+ "[a-zA-Z0-9]?\\.){0,127})(?<domain>[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9])(?<tld>\\."
+ "[a-zA-Z]{3,63})(?<cctld>\\.[a-zA-Z]{2})?(?<portnumber>:\\d{1,5})?(?<path>(?:\\/{1,2}[\\w-@.~()%]"
+ "*)*)(?<querystring>\\?(?:[\\w-%]+=[\\w-?/:@.~!$&'()*+,;=%]+(?:&[\\w-%]+=[\\w-?/:@.~!$&'()*+,;=%]+)*)"
+ "?)?(?<fragment>#[\\w-?/:@.~!$&'()*+,;=%]+)?$";
public final String url;

/**
Expand All @@ -26,6 +39,7 @@ public class Link {
public Link(String url) {
requireNonNull(url);
this.url = url;

}

public static boolean isValidLink(String test) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/educonnect/model/student/TelegramHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
public class TelegramHandle {

public static final String MESSAGE_CONSTRAINTS =
"Telegram handles should start with @";
public static final String VALIDATION_REGEX = "^@.*";
"Telegram handles should \n"
+ "1. Start with @, \n"
+ "2. Consist of only alphanumeric characters and underscores (_) \n"
+ "3. Have a minimum of 5 characters\n"
+ "4. Have a minimum of 3 alphanumeric characters\n";
public static final String VALIDATION_REGEX = "^@(?=(?:[0-9_]*[a-z]){3})[a-z0-9_]{5,}$";
public final String value;

/**
* Constructs a {@code TelegramHandle}.
* @param handle a valid {@code String} representing the telegram handle.
*/
public TelegramHandle(String handle) {
String lowerHandle = handle.toLowerCase();
requireNonNull(handle);
checkArgument(isValidTelegramHandle(handle), MESSAGE_CONSTRAINTS);
value = handle;
checkArgument(isValidTelegramHandle(lowerHandle), MESSAGE_CONSTRAINTS);
value = lowerHandle;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Valid Student",
"studentId": "A1234567P",
"email": "[email protected]",
"telegramHandle": "@hans",
"telegramHandle": "@hansis",
"link": "https://github.com/tanjiajiajun/tp"
}, {
"name": "Student With Invalid student Id Field",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Student with invalid name field: Ha!ns Mu@ster",
"studentId": "A1234567L",
"email": "[email protected]",
"telegramHandle": "@hans",
"telegramHandle": "@hansis",
"link": "https://github.com/tanjiajiajun/tp"
} ]
}
Loading

0 comments on commit 25a1db3

Please sign in to comment.