diff --git a/db/contacts.json b/db/contacts.json index b86be73263e4a6c1246934e50b8a00d44466efcf..963156b3878de107a01e1f7a871a07a7d5260762 100644 --- a/db/contacts.json +++ b/db/contacts.json @@ -1 +1 @@ -[{"name":"acima","lastname":["BBBB"],"address":"sude ksdjf ldsaflksa flkds fldsa fdsaf","telelphoneNumbers":["+4234234234234234"],"emailAddresses":["@.com.sdfd"],"socialAcounts":["https://"],"profession":"student","familyRelation":"brother","type":"Family"},{"name":"agnon","lastname":["burteshi"],"address":"rue du valais 21","telelphoneNumbers":["+9294324234234"],"emailAddresses":["burteshi@gmail.com"],"socialAcounts":["https://hello.com"],"profession":"developeeur","type":"Professional","professionalRelation":"Collegue"},{"name":"agnon","lastname":["kurteshi"],"address":"rue du rhone 4, 1203 Genève","telelphoneNumbers":["+41 78 741 22 11"],"emailAddresses":["agnon@gmail.com"],"socialAcounts":["https://hello.com/?=name"],"profession":"student","type":"Friend","friendsSince":"2002.12.12"}] \ No newline at end of file +[{"name":"Albion","lastname":["kurteshi"],"type":"Friend","address":"rue du rhone 4, 1203 Genève","telelphoneNumbers":["+41 78 741 22 11"],"emailAddresses":["agnon@gmail.com"],"socialAcounts":["https://hello.com/?=name"],"profession":"student","relation":"best friend"},{"name":"agnon","lastname":["kurteshi"],"type":"Friend","address":"rue du rhone 4, 1203 Genève","telelphoneNumbers":["+41 78 741 22 11"],"emailAddresses":["agnon@gmail.com"],"socialAcounts":["https://hello.com/?=name"],"profession":"student","relation":"normal friend"},{"name":"alex","lastname":["berneaux"],"type":"Professional","address":"rue la martine 23, 1203 Genève","telelphoneNumbers":["+41 78 751 68 41"],"emailAddresses":["alexberneaux@gmail.com"],"socialAcounts":["https://instagram.com"],"profession":"student","relation":"employee"},{"name":"dawid","lastname":["dymm"],"type":"Professional","address":"rue la martine 23, 1203 Genève","telelphoneNumbers":["+41 78 751 68 41"],"emailAddresses":["zabio@gmail.com"],"socialAcounts":["https://instagram.com"],"profession":"student","relation":"collegue"},{"name":"zabiullah3","lastname":["ahmadi"," bx"],"type":"Professional","address":"rue la martine 23, 1203 Genève","telelphoneNumbers":["+41 78 751 68 41"],"emailAddresses":["zabio@gmail.com"],"socialAcounts":["https://instagram.com"],"profession":"student","relation":"employee"},{"name":"zabiullah34","lastname":["ahmadi"," bx"],"type":"Professional","address":"rue la martine 23, 1203 Genève","telelphoneNumbers":["+41 78 751 68 41"],"emailAddresses":["zabio@gmail.com"],"socialAcounts":["https://instagram.com"],"profession":"student","relation":"employee"},{"name":"zabiullah6666","lastname":["ahmadi"," bx"],"type":"Professional","address":"rue la martine 23, 1203 Genève","telelphoneNumbers":["+41 78 751 68 41"],"emailAddresses":["zabio@gmail.com"],"socialAcounts":["https://instagram.com"],"profession":"student","relation":"employee"}] \ No newline at end of file diff --git a/pom.xml b/pom.xml index aeb0ce6fafb9962f9aa023fcffa970c69dc191d9..311d33ad6c5f30d47f10fdb4a796a9d72e9e1a0e 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,31 @@ </properties> <dependencies> + + <dependency> + <groupId>com.google.zxing</groupId> + <artifactId>core</artifactId> + <version>3.4.0</version> + </dependency> + + + + + <!-- JAVA FX --> + <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-controls</artifactId> + <version>18.0.2</version> + </dependency> + + + <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-fxml</artifactId> + <version>18.0.2</version> + </dependency> + <!-- JAVA FX --> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> @@ -22,6 +47,7 @@ <scope>test</scope> </dependency> + <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> @@ -33,12 +59,36 @@ <artifactId>json-simple</artifactId> <version>1.1.1</version> </dependency> + + </dependencies> <build> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> - <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> + <plugin> + <groupId>org.openjfx</groupId> + <artifactId>javafx-maven-plugin</artifactId> + <version>0.0.8</version> + <executions> + <execution> + <!-- Default configuration for running with: mvn clean javafx:run --> + <id>default-cli</id> + <configuration> + <mainClass>Main</mainClass> + <launcher>app</launcher> + <jlinkZipName>app</jlinkZipName> + <jlinkImageName>app</jlinkImageName> + <noManPages>true</noManPages> + <stripDebug>true</stripDebug> + <noHeaderFiles>true</noHeaderFiles> + </configuration> + </execution> + </executions> + </plugin> + + + <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> diff --git a/src/Application/Application.java b/src/Application/Application.java deleted file mode 100644 index 55d8b2b6e5edd43b2d738d21865b25b0b9546758..0000000000000000000000000000000000000000 --- a/src/Application/Application.java +++ /dev/null @@ -1,412 +0,0 @@ -package Application; - -import Contacts.Contacts; -import Family.Family; -import Friends.Friends; -import Helper.Helper; -import Professional.Professional; - -import java.util.Objects; -import java.util.Scanner; - -public class Application extends Helper { - Contacts[] contact_list; - - public void addToContactList(Contacts newContact) { - - // if null - if (contact_list == null) { - contact_list = new Contacts[1]; - contact_list[0] = newContact; - } else { - Contacts[] temp = new Contacts[contact_list.length + 1]; - - for (int i = 0; i < contact_list.length; i++) { - temp[i] = contact_list[i]; - } - temp[contact_list.length] = newContact; - - contact_list = temp; - // bubble sort - bubbleSort(); - } - } - - public Contacts createContact() { - - System.out.println("Enter the type of contact: []"); - System.out.println("[1] for friend "); - System.out.println("[2] for family "); - System.out.println("[3] for professional"); - System.out.println("Enter your choice [] :"); - - Scanner scanner = new Scanner(System.in); - int type = scanner.nextInt(); - while (type < 1 || type > 3) { - - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT TYPE", RED); - System.out.format("%s", RESET); - System.out.println("Enter your choice [] :"); - type = scanner.nextInt(); - } - - Contacts new_contact = null; - if (type == 1) { - new_contact = new Friends() - .askContact(); - } - - else if (type == 2) { - new_contact = new Family().askContact(); - } - - else if (type == 3) { - new_contact = new Professional() - .askContact(); - } else { - PrintErrorAndReturn(); - } - // scanner.close(); - return new_contact; - - } - - public boolean update(int id) { - - int elementId = id - 1; - if (elementId >= 0 && elementId < contact_list.length) { - contact_list[elementId].updateContact(); - return true; - } - return false; - } - - public Contacts[] search() { - - Contacts[] result = new Contacts[0]; - Scanner scanner = new Scanner(System.in); - System.out.println("CHOOSE BY WHICH FIELD YOU WANT TO SEARCH"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] BY TYPE:"); - - System.out.println(String.format("%s %s %s : []", BLUE, "YOUR FIELD ", BLUE)); - System.out.print(String.format("%s", RESET)); - int option = scanner.nextInt(); - while (option < 1 || option > 4) { - System.out.println(String.format("%s %s %s", RED, "ERREUR: PLEASE CHOOSE THE CORRECT FIELD", RED)); - System.out.println(String.format("%s %s %s : [] ", BLUE, "YOUR FIELD ", BLUE)); - System.out.print(String.format("%s", RESET)); - option = scanner.nextInt(); - } - - if (option == 1) { - - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A NAME TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - Scanner sc = new Scanner(System.in); - String nameToSearch = sc.nextLine(); - while (nameToSearch.length() < 3) { - System.out.println( - String.format("%s %s %s", RED, "NAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A NAME TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - nameToSearch = sc.nextLine(); - } - - int j = 0; - for (int i = 0; i < contact_list.length; i++) { - if (contact_list[i].getName().equals(nameToSearch)) { - result = new Contacts[result.length + 1]; - result[j++] = contact_list[i]; - } - } - } - - // } - if (option == 2) - - { - int j = 0; - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - Scanner sc = new Scanner(System.in); - String lastNameToSerach = sc.nextLine(); - while (lastNameToSerach.length() < 3) { - System.out.println( - String.format("%s %s %s", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - lastNameToSerach = sc.nextLine(); - } - - for (int i = 0; i < contact_list.length; i++) { - if (contact_list[i].getLastname().equals(lastNameToSerach)) { - result = new Contacts[result.length + 1]; - result[j++] = contact_list[i]; - } - } - } else if (option == 3) { - int j = 0; - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A EMAIL TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - Scanner sc = new Scanner(System.in); - String emailToSearch = sc.nextLine(); - while (emailToSearch.length() < 3) { - System.out.println( - String.format("%s %s %s\n", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED)); - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A EMAIL TO SEARCH", BLUE)); - System.out.print(String.format("%s", RESET)); - emailToSearch = sc.nextLine(); - } - - for (int i = 0; i < contact_list.length; i++) { - if (contact_list[i].getEmailAddresses().equals(emailToSearch)) { - result = new Contacts[result.length + 1]; - result[j++] = contact_list[i]; - } - } - } else if (option == 4) { - int j = 0; - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A TYPE TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - Scanner sc = new Scanner(System.in); - String typeToSearch = sc.nextLine(); - while (typeToSearch.length() < 5) { - System.out.println( - String.format("%s %s %s\n", RED, "TYPE SHOULD CONTAINS AT LEAST 5 CHARACTER LENGTH", RED)); - System.out.println(String.format("%s %s %s : [] ", BLUE, "ENTER A TYPE TO SEARCH ", BLUE)); - System.out.print(String.format("%s", RESET)); - typeToSearch = sc.nextLine(); - } - - for (int i = 0; i < contact_list.length; i++) { - if (contact_list[i].getType().equals(typeToSearch)) { - result = new Contacts[result.length + 1]; - result[j++] = contact_list[i]; - } - } - } - - return result; - } - - public boolean delete(int id) { - - int elementId = id - 1; - if (elementId >= 0 && elementId < contact_list.length) { - // delete - Contacts[] temp = new Contacts[contact_list.length - 1]; - - int j = 0; - for (int i = 0; i < contact_list.length; i++) { - if (i != elementId) { - temp[j] = contact_list[i]; - j++; - } - } - contact_list = temp; - return true; - - } else { - return false; - } - } - - public int getCharNumericValue(String value) { - return (int) (value.charAt(0)); - } - - public void shift(int index) { - Contacts tempContact = contact_list[index]; - contact_list[index] = contact_list[index - 1]; - contact_list[index - 1] = tempContact; - } - - public void bubbleSort() { - for (int i = 0; i < contact_list.length; i++) { - - for (int j = contact_list.length - 1; j >= 1; j--) { - - int firstPersonNameValue = getCharNumericValue(contact_list[j].getName().toUpperCase()); - int firstPersonLastNameValue = getCharNumericValue(contact_list[j].getLastname()[0].toUpperCase()); - - int secondPersonNameValue = getCharNumericValue(contact_list[j - 1].getName().toUpperCase()); - int secondPersonLastNameValue = getCharNumericValue(contact_list[j - 1].getLastname()[0].toUpperCase()); - - // sort by last name if first names are equals - if (firstPersonNameValue == secondPersonNameValue) { - - if (firstPersonLastNameValue < secondPersonLastNameValue) { - shift(j); - } - // sort by first name - } else if (firstPersonNameValue < secondPersonNameValue) { - shift(j); - } - - } - } - } - - public void showContacts() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", YELLOW); - PrintInColor(String.format("SHOW CONTACTS \t\t\t\t\t\t\tTOTAL [%s %d %s]\n", WHITE, - (contact_list != null) ? contact_list.length : 0, CYAN), CYAN); - PrintInColor("==================================================================================\n\n", YELLOW); - - if (contact_list == null) { - System.out.println(" No contacts yet !\n"); - } - - if (contact_list != null) { - for (int i = 0; i < contact_list.length; i++) { - - contact_list[i].showContact(); - } - } - } - - public void run() { - int option = ASK_USER_INPUT; - - while (true) { - Scanner scanner = new Scanner(System.in); - if (option == ASK_USER_INPUT) { - - PrintHeader(); - PrintInColor("Enter your option : ", WHITE); - - option = scanner.nextInt(); - - if (option == EXIT_CONSOLE) { - System.exit(0); - } - - if (option == ADD_CONTACTS) { - - addToContactList(createContact()); - option = ASK_USER_INPUT; - continue; - } - - if (option == SHOW_CONTACTS) { - showContacts(); - printFooter(); - - PrintInColor("Enter your option : ", WHITE); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - continue; - - } - - if (option == SEARCH_CONTACT) { - - if (contact_list != null) { - Contacts[] result = search(); - if (result.length != 0) { - for (int i = 0; i < result.length; i++) { - - result[i].showContact(); - } - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - - } else { - System.out.println("---------------------------------------------------"); - System.out.println(String.format("no contact found")); - System.out.println("---------------------------------------------------"); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - } else { - showContacts(); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - - } - continue; - } - - // update contact - if (option == UPDATE_CONTACTS) { - - showContacts(); - if (contact_list != null) { - - System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); - int id = scanner.nextInt(); - - while (id < 1 || id > contact_list.length + 1) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT ID", RED); - System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); - id = scanner.nextInt(); - } - - Boolean updated = update(id); - if (updated) { - option = ASK_USER_INPUT; - } else { - System.out.println(String.format( - " Contact with id %d doesn't exists", id)); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - - } else { - showContacts(); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - continue; - } - // delete contact - if (option == DELETE_CONTACT) { - showContacts(); - - if (contact_list != null) { - deleteOption(); - System.out.print("Enter contact id to delete: "); - int id = scanner.nextInt(); - - boolean deleted = delete(id); - - if (deleted) { - option = ASK_USER_INPUT; - } else { - System.out.println(String.format( - " Contact with id %d doesn't exists", id)); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - - } else { - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - continue; - } - - } - - if (option < 1 || option > 4) { - - clearConsoleScreen(); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - scanner.close();// close scanner - } - } -} diff --git a/src/Contacts/Contacts.java b/src/Contacts/Contacts.java deleted file mode 100644 index 81c7cf7eabccdf0828590bda082c42ce881b8d95..0000000000000000000000000000000000000000 --- a/src/Contacts/Contacts.java +++ /dev/null @@ -1,253 +0,0 @@ -package Contacts; - -import Helper.Helper; - -import java.util.Scanner; - -public abstract class Contacts extends Helper { - - protected String name; - protected String[] lastname; - protected String address; - protected String[] telelphoneNumbers; - protected String[] emailAddresses; - protected String[] socialAcounts; - protected String profession; - - public Contacts() { - } - - public Contacts(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, - String[] socialAcounts, String profession) { - this.name = name; - this.lastname = lastname; - this.address = address; - this.telelphoneNumbers = telelphoneNumbers; - this.emailAddresses = emailAddresses; - this.socialAcounts = socialAcounts; - this.profession = profession; - } - - public String getName() { - return name; - } - - protected void setName(String name) { - this.name = name; - } - - public String[] getLastname() { - return lastname; - } - - public void setLastname(String[] lastname) { - this.lastname = lastname; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String[] getTelelphoneNumbers() { - return telelphoneNumbers; - } - - public void setTelelphoneNumbers(String[] telelphoneNumbers) { - this.telelphoneNumbers = telelphoneNumbers; - } - - public String[] getEmailAddresses() { - return emailAddresses; - } - - public void setEmailAddresses(String[] emailAddresses) { - this.emailAddresses = emailAddresses; - } - - public String[] getSocialAcounts() { - return socialAcounts; - } - - public void setSocialAcounts(String[] socialAcounts) { - this.socialAcounts = socialAcounts; - } - - public String getProfession() { - return profession; - } - - public void setProfession(String profession) { - this.profession = profession; - } - - public void askName() { - - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter a name [] : "); - String name = sc.nextLine(); - while (name.length() < 3) { - System.out - .println( - String.format("\n %sName should contain at least 3 character %s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter a name [] : "); - name = sc.nextLine(); - } - setName(name); - // sc.close(); - } - - public void askLastName() { - - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter one or more last name separated by , [] : "); - String lastName = sc.nextLine(); - - while (lastName.length() < 3) { - System.out - .println( - String.format("\n %slast name should contain at least 3 character %s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more last name separated by , [] : "); - name = sc.nextLine(); - } - setLastname(lastName.split(",")); - - // sc.close(); - } - - public void askAdress() { - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter Address [] : "); - String address = sc.nextLine(); - while (address.length() < 15) { - System.out - .println( - String.format("\n %sAddress should at least contain 15 character length%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Address [] : "); - address = sc.nextLine(); - } - setAddress(address); - - // sc.close(); - } - - public void askEmail() { - Scanner sc = new Scanner(System.in); - System.out.print(" Enter one or more email separated by , [] : "); - String email = sc.nextLine(); - - while (email.length() < 10 || !email.contains("@") || !email.contains(".")) { - System.out - .println( - String.format("\n %sPlease Insert a correct Email !%s%s", RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more email separated by , [] : "); - - email = sc.nextLine(); - } - setEmailAddresses(email.split(",")); - // sc.close(); - } - - public void askTelephoneNumber() { - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter one or more telephone number separated by , [] : "); - String telephonNumber = sc.nextLine(); - - while (telephonNumber.length() < 12 || !telephonNumber.contains("+") - || telephonNumber.replaceAll(" ", telephonNumber).length() < 12) { // +4178 223 22 44 - System.out.println( - String.format("\n %sPLEASE INSERT A CORRECT TELEPHONE NUMBER !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more telephone number separated by , [] : "); - telephonNumber = sc.nextLine(); - - } - setTelelphoneNumbers(telephonNumber.split(",")); - - // sc.close(); - } - - public void askSocialAcount() { - Scanner sc = new Scanner(System.in); - System.out.print(" Enter one or more social acount URL separated by , [] :"); - String socialAcount = sc.nextLine(); - - while (!socialAcount.contains("https://")) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT URL PREFIXED BY HTTPS:// !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more social acount URL separated by , [] :"); - socialAcount = sc.nextLine(); - } - setSocialAcounts(socialAcount.split(",")); - // sc.close(); - } - - public void askProfession() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your Contact Profession [] : "); - String profession = sc.nextLine(); - - while (profession.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT PROFESSION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Your Contact Profession [] : "); - profession = sc.nextLine(); - } - setProfession(profession); - // sc.close(); - } - - public void displayRequestHeader() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - } - - public abstract String getType(); - - public abstract void setType(String type); - - public abstract void showContact(); - - public abstract void updateContact(); - -} diff --git a/src/Family/Family.java b/src/Family/Family.java deleted file mode 100644 index 1bd19ef33d21da2a68f128f77ca9da5d89eb19db..0000000000000000000000000000000000000000 --- a/src/Family/Family.java +++ /dev/null @@ -1,195 +0,0 @@ -package Family; - -import java.util.Scanner; - -import Contacts.Contacts; -import Helper.Helper; - -public class Family extends Contacts { - private String Type; - private String familyRelation; - - public Family() { - super(); - this.Type = "Family"; - } - - public Family(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, - String[] socialAcounts, String profession, String familyRelation) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - Type = "Family"; - setFamilyRelation(familyRelation); - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setFamilyRelation(String familyRelation) { - this.familyRelation = familyRelation; - } - - public String getFamilyRelation() { - return this.familyRelation; - } - - public void askFamilyRelation() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); - String famRelation = sc.nextLine(); - - while (famRelation.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT FAMILY RELATION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); - famRelation = sc.nextLine(); - } - setFamilyRelation(famRelation); - - } - - public Family askContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Family]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askFamilyRelation(); - askTelephoneNumber(); - askAdress(); - - askSocialAcount(); - askProfession(); - return this; - - } - - public void updateContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [Family]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] FAMILY RELATION:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while (option < 1 || option > 8) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option) { - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askFamilyRelation(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sFamily Relation : %s", BLUE, - BLUE) - + String.format("\t\t%s" + getFamilyRelation(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } - - @Override - public String toString() { - return this.getName(); - } - -} diff --git a/src/Friends/Friends.java b/src/Friends/Friends.java deleted file mode 100644 index 8472a02c04f25bf6665c01bf2746ac62f498520a..0000000000000000000000000000000000000000 --- a/src/Friends/Friends.java +++ /dev/null @@ -1,197 +0,0 @@ -package Friends; - -import Contacts.Contacts; -import Family.Family; -import Professional.Professional; - -import java.util.Scanner; - -public class Friends extends Contacts { - - private String Type; - - private String firendsSince; - - public Friends() { - super(); - Type = "Friend"; - } - - public Friends(String name, String[] lastname, String address, String[] telelphoneNumbers, String[] emailAddresses, - String[] socialAcounts, String profession, String firendsSince) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - Type = "Friend"; - setFriendsSince(firendsSince); - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setFriendsSince(String str) { - this.firendsSince = str; - - } - - public String getFriendsSince() { - return this.firendsSince; - } - - public void askFriendShipDate() { - - Scanner sc = new Scanner(System.in); - System.out.print(this.name + " is Your friend since : "); - String friendshipeDate = sc.nextLine(); - - while (friendshipeDate.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT FRIENDSHIP DATE !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(this.name + " is Your friend since : "); - friendshipeDate = sc.nextLine(); - } - setFriendsSince(friendshipeDate); - } - - public Contacts askContact() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Friends]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askFriendShipDate(); - askTelephoneNumber(); - askAdress(); - askSocialAcount(); - askProfession(); - return this; - - } - - public void updateContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [FRIENDS]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] FRIENDSHIP DATE:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while (option < 1 || option > 8) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option) { - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askFriendShipDate(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sFriendship since : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getFriendsSince(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("\t\t%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } - - @Override - public String toString() { - return this.getName(); - } -} diff --git a/src/Helper/Helper.java b/src/Helper/Helper.java deleted file mode 100644 index 762e26ccb36137ef5ce216719efbd7a6ceed98bd..0000000000000000000000000000000000000000 --- a/src/Helper/Helper.java +++ /dev/null @@ -1,115 +0,0 @@ -package Helper; - - - -public abstract class Helper { - - // text color - protected final String RED = "\u001B[31m"; - protected final String BLACK = "\u001B[30m"; - protected final String GREEN = "\u001B[32m"; - protected final String BLUE = "\u001B[34m"; - protected final String RESET = "\u001B[0m"; - protected final String PURPLE = "\u001B[35m"; - protected final String CYAN = "\u001B[36m"; - protected final String YELLOW = "\u001B[33m"; - protected final String WHITE = "\u001B[37m"; - - protected final String YELLOW_BACKGROUND = "\u001B[43m"; - protected final String BLUE_BACKGROUND = "\u001B[44m"; - protected final String BLACK_BACKGROUND = "\u001B[40m"; - protected final String PURPLE_BACKGROUND = "\u001B[45m"; - protected final String CYAN_BACKGROUND = "\u001B[46m"; - protected final String GREEN_BACKGROUND = "\u001B[42m"; - protected final String WHITE_BACKGROUND = "\u001B[47m"; - - protected final int ASK_USER_INPUT = 110; - protected final int SHOW_CONTACTS = 1; - protected final int ADD_CONTACTS = 2; - protected final int SEARCH_CONTACT = 3; - protected final int UPDATE_CONTACTS = 4; - protected final int DELETE_CONTACT = 5; - protected final int EXIT_CONSOLE = 6; - - // clear console screen - protected void clearConsoleScreen() { - System.out.print("\033[H\033[2J"); - System.out.flush(); - } - - // print in color a given text or change background color - protected void PrintInColor(String text, String color) { - - System.out.format("%s %s %s", color, text, color); - System.out.format("%s", RESET); - } - - // Print header of our console application - protected void PrintHeader() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", - YELLOW); - PrintInColor("WELLCOME TO CONTACT MANAGEMENT SYSTEM \n", GREEN); - PrintInColor("==================================================================================\n", - YELLOW); - - PrintInColor("[1]: \tshow contacts\t\t\t\t\n", CYAN); - PrintInColor("[2]: \tadd contact\t\t\t\t\n", CYAN); - PrintInColor("[3]: \tsearch contact\t\t\t\t\n", CYAN); - PrintInColor("[4]: \tupdate a contact\t\t\t\t\n", CYAN); - PrintInColor("[5]: \tdelete a contact\t\t\t\t\n", CYAN); - PrintInColor("[6]: \texit\t\t\t\t\n", CYAN); - PrintInColor("==================================================================================\n", - YELLOW); - } - - // print OPTION ERROR - protected void PrintErrorAndReturn() { - - PrintInColor(" ----------------------------------------------------------------------------------\n", - YELLOW); - PrintInColor("ERROR: WRONG OPTION ID \n", RED); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); - PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - } - - protected void printFooter() { - - PrintInColor(" ----------------------------------------------------------------------------------\n", - YELLOW); - PrintInColor("RETURN TO HOME \n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); - PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - } - - protected void deleteOption() { - PrintInColor(" ==================================================================================\n", - YELLOW); - PrintInColor("DELETE A CONCTACT\n", CYAN); - PrintInColor("==================================================================================\n", - YELLOW); - } - - protected int populateErrorOrReturnHome(int option) { - if (option == 1) { - return ASK_USER_INPUT; - } - if (option == 2) { - System.exit(0); - } - return 0; - } - -} diff --git a/src/Main.java b/src/Main.java deleted file mode 100644 index 76fcf5efd30d4a36b5489669eb16a026f3e16c39..0000000000000000000000000000000000000000 --- a/src/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -import Application.Application; - -public class Main { - public static void main(String[] args) { - new Application().run(); - } -} \ No newline at end of file diff --git a/src/Professional/Professional.java b/src/Professional/Professional.java deleted file mode 100644 index dd9d6da20ff3dbd1ce34cfa19c03ad8d8af68bb3..0000000000000000000000000000000000000000 --- a/src/Professional/Professional.java +++ /dev/null @@ -1,196 +0,0 @@ -package Professional; - -import java.util.Scanner; - -import Contacts.Contacts; -import Family.Family; - -public class Professional extends Contacts { - private String Type; - - private String ProfessionRelation; - - public Professional() { - super(); - Type = "Professional"; - } - - public Professional(String name, String[] lastname, String address, String[] telelphoneNumbers, - String[] emailAddresses, String[] socialAcounts, String profession, String professionRelation) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - setProfessionRelation(professionRelation); - Type = "Professional"; - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setProfessionRelation(String professionRelation) { - ProfessionRelation = professionRelation; - } - - public String getProfessionalRelation() { - return this.ProfessionRelation; - } - - public void askProfessionalRelation() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); - String proRelation = sc.nextLine(); - - while (proRelation.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT PROFESSIONAL RELATION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out - .print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); - proRelation = sc.nextLine(); - } - setProfessionRelation(proRelation); - - } - - public Professional askContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Professional]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askProfessionalRelation(); - askTelephoneNumber(); - askAdress(); - askSocialAcount(); - askProfession(); - - return this; - - } - - public void updateContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [PROFESSIONAL]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] PROFESSIONAL RELATION:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while (option < 1 || option > 8) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option) { - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askProfessionalRelation(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfessional Relation : %s", BLUE, - BLUE) - + String.format("\t\t%s" + getProfessionalRelation(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("\t\t%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } - - @Override - public String toString() { - return this.getName(); - } -} diff --git a/src/main/java/Application/Application.java b/src/main/java/Application/Application.java index 15333075e373330b5de9914df5da58268d77156c..2984582bbfe9057219eaa9037cee642b13eac744 100644 --- a/src/main/java/Application/Application.java +++ b/src/main/java/Application/Application.java @@ -5,21 +5,27 @@ import java.io.FileReader; import java.io.IOException; import java.util.*; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import com.fasterxml.jackson.databind.ObjectMapper; import Contacts.Contacts; -import Family.Family; -import Friends.Friends; -import Helper.Helper; -import Professional.Professional; +import Contacts.Family; +import Contacts.Friend; +import Contacts.Professional; -public class Application extends Helper { - List<Contacts> contactsList = new ArrayList<>(); +public class Application { + public ObservableList<Contacts> contactsList = FXCollections.observableArrayList(); - public void saveContactList(List<Contacts> contactsList) { + public Application() { + this.loadDatabase(); + this.sortContactList(); + } + + public void saveContactList(ObservableList<Contacts> contactsList) { ObjectMapper objectMapper = new ObjectMapper(); try { @@ -61,30 +67,28 @@ public class Application extends Helper { .trim() .split(",")); String profession = info.get("profession").toString().trim(); - Contacts new_contact = null; String type = info.get("type").toString(); + + String relation = (info.get("relation") != null) + ? info.get("relation").toString().trim() + : ""; + Contacts new_contact = null; + switch (type) { case "Family": - String familyRelation = (info.get("familyRelation") != null) - ? info.get("familyRelation").toString().trim() - : ""; - new_contact = new Family(name, lastname, address, telelphoneNumbers, emailAddresses, - socialAcounts, profession, familyRelation); + new_contact = new Family(name, lastname, type, relation, address, telelphoneNumbers, + emailAddresses, socialAcounts, profession); break; case "Friend": - String friendsSince = (info.get("friendsSince") != null) ? info.get("friendsSince").toString().trim() - : ""; - new_contact = new Friends(name, lastname, address, telelphoneNumbers, emailAddresses, - socialAcounts, profession, friendsSince); + new_contact = new Friend(name, lastname, type, relation, address, telelphoneNumbers, + emailAddresses, socialAcounts, profession); break; case "Professional": - String ProfessionRelation = (info.get("ProfessionRelation") != null) - ? info.get("ProfessionRelation").toString().trim() - : ""; - new_contact = new Friends(name, lastname, address, telelphoneNumbers, emailAddresses, - socialAcounts, profession, ProfessionRelation); + new_contact = new Professional(name, lastname, type, relation, address, telelphoneNumbers, + emailAddresses, socialAcounts, profession); + break; default: break; @@ -117,163 +121,19 @@ public class Application extends Helper { } - public Contacts createContact() { - - System.out.println("Enter the type of contact: []"); - System.out.println("[1] for friend "); - System.out.println("[2] for family "); - System.out.println("[3] for professional"); - System.out.println("Enter your choice [] :"); - - Scanner scanner = new Scanner(System.in); - int type = scanner.nextInt(); - while (type < 1 || type > 3) { - - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT TYPE", RED); - System.out.format("%s", RESET); - System.out.println("Enter your choice [] :"); - type = scanner.nextInt(); - } - - Contacts new_contact = null; - if (type == 1) { - new_contact = new Friends() - .askContact(); - } - - else if (type == 2) { - new_contact = new Family().askContact(); - } - - else if (type == 3) { - new_contact = new Professional() - .askContact(); - } else { - PrintErrorAndReturn(); - } - // scanner.close(); - return new_contact; - - } - - public boolean update(int id) { - - int elementId = id - 1; - if (!contactsList.isEmpty() && contactsList.get(elementId) != null) { - contactsList.get(elementId).updateContact(); - sortContactList(); + public boolean delete(String searchKey) { + Optional<Contacts> contact = contactsList + .stream() + .filter(e -> e.getName().equals(searchKey)) + .findFirst(); + if (contact.isPresent()) { + int index = contactsList.indexOf(contact.get()); + contactsList.remove(index); return true; } return false; } - public List<Contacts> search() { - - List<Contacts> result = new ArrayList<Contacts>(); - - Scanner scanner = new Scanner(System.in); - System.out.println("CHOOSE BY WHICH FIELD YOU WANT TO SEARCH"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] BY TYPE:"); - - System.out.printf("%s %s %s : []%n", BLUE, "YOUR OPTION ", BLUE); - System.out.printf("%s", RESET); - int option = scanner.nextInt(); - while (option < 1 || option > 4) { - System.out.printf("%s %s %s%n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.printf("%s %s %s : [] %n", BLUE, "YOUR OPTION ", BLUE); - System.out.printf("%s", RESET); - option = scanner.nextInt(); - } - - if (option == 1) { - - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A NAME TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - Scanner sc = new Scanner(System.in); - String nameToSearch = sc.nextLine(); - while (nameToSearch.length() < 3) { - System.out.printf("%s %s %s%n", RED, "NAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED); - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A NAME TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - nameToSearch = sc.nextLine(); - } - - final String searchKey = nameToSearch; - result = contactsList.stream().filter(e -> e.getName().contains(searchKey)).toList(); - } - if (option == 2) - - { - int j = 0; - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - Scanner sc = new Scanner(System.in); - String lastNameToSerach = sc.nextLine(); - while (lastNameToSerach.length() < 3) { - System.out.printf("%s %s %s%n", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED); - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A LASTNAME TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - lastNameToSerach = sc.nextLine(); - } - - final String searchKey = lastNameToSerach; - result = contactsList.stream().filter(e -> e.getLastname().contains(searchKey)).toList(); - - } else if (option == 3) { - int j = 0; - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A EMAIL TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - Scanner sc = new Scanner(System.in); - String emailToSearch = sc.nextLine(); - while (emailToSearch.length() < 3) { - System.out.printf("%s %s %s\n%n", RED, "LASTNAME SHOULD CONTAINS AT LEAST 3 CHARACTER LENGTH", RED); - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A EMAIL TO SEARCH", BLUE); - System.out.printf("%s", RESET); - emailToSearch = sc.nextLine(); - } - - final String searchKey = emailToSearch; - result = contactsList.stream().filter(e -> e.getEmailAddresses().contains(searchKey)).toList(); - - } else if (option == 4) { - int j = 0; - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A TYPE TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - Scanner sc = new Scanner(System.in); - String typeToSearch = sc.nextLine(); - while (typeToSearch.length() < 5) { - System.out.printf("%s %s %s\n%n", RED, "TYPE SHOULD CONTAINS AT LEAST 5 CHARACTER LENGTH", RED); - System.out.printf("%s %s %s : [] %n", BLUE, "ENTER A TYPE TO SEARCH ", BLUE); - System.out.printf("%s", RESET); - typeToSearch = sc.nextLine(); - } - - final String searchKey = typeToSearch; - result = contactsList.stream().filter(e -> e.getType().contains(searchKey)).toList(); - } - - return result; - } - - public boolean delete(int id) { - - int elementId = id - 1; - - if (elementId >= 0 && elementId < contactsList.size()) { - // delete - contactsList.remove(elementId); - // sort - sortContactList(); - return true; - - } else { - return false; - } - } - public void sortContactList() { Comparator<Contacts> compareByName = Comparator .comparing(Contacts::getName) @@ -283,172 +143,11 @@ public class Application extends Helper { } - public void showContacts() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", YELLOW); - PrintInColor(String.format("SHOW CONTACTS \t\t\t\t\t\t\tTOTAL [%s %d %s]\n", WHITE, - (!contactsList.isEmpty()) ? contactsList.size() : 0, CYAN), CYAN); - PrintInColor("==================================================================================\n\n", YELLOW); - - if (contactsList.isEmpty()) { - System.out.println(" No contacts yet !\n"); - } else { - contactsList.forEach(e -> e.showContact()); - } - } - - public void run() { - - loadDatabase(); - sortContactList(); - int option = ASK_USER_INPUT; - - while (true) { - Scanner scanner = new Scanner(System.in); - if (option == ASK_USER_INPUT) { - - PrintHeader(); - PrintInColor("Enter your option : ", WHITE); - - option = scanner.nextInt(); - - if (option == EXIT_CONSOLE) { - - saveContactList(contactsList); // save - System.exit(0); - } - - if (option == ADD_CONTACTS) { - - addToContactList(createContact()); - saveContactList(contactsList); // save - option = ASK_USER_INPUT; - continue; - } - - if (option == SHOW_CONTACTS) { - showContacts(); - printFooter(); - - PrintInColor("Enter your option : ", WHITE); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - continue; - - } - - if (option == SEARCH_CONTACT) { - - if (!contactsList.isEmpty()) { - List<Contacts> result = search(); - if (!result.isEmpty()) { - - result.forEach(res -> res.showContact()); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - - } else { - System.out.println("---------------------------------------------------"); - System.out.println("no contact found"); - System.out.println("---------------------------------------------------"); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - } else { - showContacts(); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - - } - continue; - } - - // update contact - if (option == UPDATE_CONTACTS) { - - showContacts(); - if (!contactsList.isEmpty()) { - - System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); - int id = scanner.nextInt(); - - while (id < 1 || id > contactsList.size() + 1) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT ID", RED); - System.out.format("%s %s %s : [] ", BLUE, "ENTER A CONTACT ID TO UPDATE: ", BLUE); - id = scanner.nextInt(); - } - - Boolean updated = update(id); - if (updated) { - - // save to database - saveContactList(contactsList); - option = ASK_USER_INPUT; - } else { - System.out.printf( - " Contact with id %d doesn't exists%n", id); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - - } else { - showContacts(); - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - continue; - } - // delete contact - if (option == DELETE_CONTACT) { - showContacts(); - - if (!contactsList.isEmpty()) { - deleteOption(); - System.out.print("Enter contact id to delete: "); - int id = scanner.nextInt(); - - boolean deleted = delete(id); - - if (deleted) { - option = ASK_USER_INPUT; - // save to database - saveContactList(contactsList); - } else { - System.out.printf( - " Contact with id %d doesn't exists%n", id); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - - } else { - - printFooter(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - continue; - } - - } - - if (option < 1 || option > 4) { - - clearConsoleScreen(); - PrintErrorAndReturn(); - option = scanner.nextInt(); - option = populateErrorOrReturnHome(option); - } - scanner.close();// close scanner - } + public ObservableList<Contacts> getContactList() { + return contactsList; } - public List<Contacts> getContactList() { - return this.contactsList; + public void setContactList(ObservableList<Contacts> contactsList) { + this.contactsList = contactsList; } } diff --git a/src/main/java/Contacts/Contacts.java b/src/main/java/Contacts/Contacts.java index 93eac5e880d400b93f53df0ad7c91b4b6a0cb9f3..1796f434810f12f5bbf18e03795628e373b05b72 100644 --- a/src/main/java/Contacts/Contacts.java +++ b/src/main/java/Contacts/Contacts.java @@ -1,15 +1,12 @@ package Contacts; -import Helper.Helper; - -import java.util.Arrays; import java.util.List; -import java.util.Scanner; -public abstract class Contacts extends Helper { +public abstract class Contacts { protected String name; protected List<String> lastname; + protected String type; protected String address; protected List<String> telelphoneNumbers; protected List<String> emailAddresses; @@ -19,11 +16,12 @@ public abstract class Contacts extends Helper { public Contacts() { } - public Contacts(String name, List<String> lastname, String address, List<String> telelphoneNumbers, + public Contacts(String name, List<String> lastname, String type, String address, List<String> telelphoneNumbers, List<String> emailAddresses, List<String> socialAcounts, String profession) { this.name = name; this.lastname = lastname; + this.type = type; this.address = address; this.telelphoneNumbers = telelphoneNumbers; this.emailAddresses = emailAddresses; @@ -35,7 +33,7 @@ public abstract class Contacts extends Helper { return name; } - protected void setName(String name) { + public void setName(String name) { this.name = name; } @@ -43,6 +41,14 @@ public abstract class Contacts extends Helper { return lastname; } + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + public void setLastname(List<String> lastname) { this.lastname = lastname; } @@ -87,167 +93,19 @@ public abstract class Contacts extends Helper { this.profession = profession; } - public void askName() { - - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter a name [] : "); - String name = sc.nextLine(); - while (name.length() < 3) { - System.out - .println( - String.format("\n %sName should contain at least 3 character %s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter a name [] : "); - name = sc.nextLine(); - } - setName(name); - // sc.close(); - } - - public void askLastName() { - - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter one or more last name separated by , [] : "); - String lastName = sc.nextLine(); - - // validate - while (lastName.length() < 3) { - System.out - .println( - String.format("\n %slast name should contain at least 3 character %s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more last name separated by , [] : "); - name = sc.nextLine(); - } - setLastname(Arrays.asList(lastName.split(","))); - - // sc.close(); - } - - public void askAdress() { - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter Address [] : "); - String address = sc.nextLine(); - while (address.length() < 15) { - System.out - .println( - String.format("\n %sAddress should at least contain 15 character length%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Address [] : "); - address = sc.nextLine(); - } - setAddress(address); - - // sc.close(); - } - - public void askEmail() { - Scanner sc = new Scanner(System.in); - System.out.print(" Enter one or more email separated by , [] : "); - String email = sc.nextLine(); - - while (email.length() < 10 || !email.contains("@") || !email.contains(".")) { - System.out - .println( - String.format("\n %sPlease Insert a correct Email !%s%s", RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more email separated by , [] : "); - - email = sc.nextLine(); - } - setEmailAddresses(Arrays.asList(email.split(","))); - // sc.close(); - } - - public void askTelephoneNumber() { - Scanner sc = new Scanner(System.in); - - System.out.print(" Enter one or more telephone number separated by , [] : "); - String telephonNumber = sc.nextLine(); - - while (telephonNumber.length() < 12 || !telephonNumber.contains("+") - || telephonNumber.replaceAll(" ", telephonNumber).length() < 12) { // +4178 223 22 44 - System.out.println( - String.format("\n %sPLEASE INSERT A CORRECT TELEPHONE NUMBER !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more telephone number separated by , [] : "); - telephonNumber = sc.nextLine(); - + @Override + public boolean equals(Object o) { + if (o == this) { + return true; } - setTelelphoneNumbers(Arrays.asList(telephonNumber.split(","))); - } - - public void askSocialAcount() { - Scanner sc = new Scanner(System.in); - System.out.print(" Enter one or more social acount URL separated by , [] :"); - String socialAcount = sc.nextLine(); - - while (!socialAcount.contains("https://")) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT URL PREFIXED BY HTTPS:// !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter one or more social acount URL separated by , [] :"); - socialAcount = sc.nextLine(); + if (!(o instanceof Contacts)) { + return false; } - setSocialAcounts(Arrays.asList(socialAcount.split(","))); + Contacts c = (Contacts) o; + return name.equals(c.name) && telelphoneNumbers.get(0).equals(c.telelphoneNumbers.get(0)); } - public void askProfession() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your Contact Profession [] : "); - String profession = sc.nextLine(); - - while (profession.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT PROFESSION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Your Contact Profession [] : "); - profession = sc.nextLine(); - } - setProfession(profession); - } - - public void displayRequestHeader() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - } - - public abstract String getType(); - - public abstract void setType(String type); - - public abstract void showContact(); - - public abstract void updateContact(); + public abstract String getRelation(); + public abstract void setRelation(String relation); } diff --git a/src/main/java/Contacts/Family.java b/src/main/java/Contacts/Family.java new file mode 100644 index 0000000000000000000000000000000000000000..0d9a81e58fcee5320a3062549ec245d03774853b --- /dev/null +++ b/src/main/java/Contacts/Family.java @@ -0,0 +1,34 @@ +package Contacts; + +import java.util.List; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public class Family extends Contacts { + + public static ObservableList<String> contactRelation = FXCollections.observableArrayList("father", "mother", + "brother", + "sister", + "daugther", "sun"); + + private String relation; + + public Family(String name, List<String> lastname, String type, String relation, String address, + List<String> telelphoneNumbers, + List<String> emailAddresses, + List<String> socialAcounts, String profession) { + super(name, lastname, type, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + + this.relation = relation; + } + + public String getRelation() { + return relation; + } + + public void setRelation(String relation) { + this.relation = relation; + } + +} diff --git a/src/main/java/Contacts/Friend.java b/src/main/java/Contacts/Friend.java new file mode 100644 index 0000000000000000000000000000000000000000..bb197daa7eea93cb99b9bb3490a59fd096c59a89 --- /dev/null +++ b/src/main/java/Contacts/Friend.java @@ -0,0 +1,31 @@ +package Contacts; + +import java.util.List; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public class Friend extends Contacts { + + public static ObservableList<String> contactRelation = FXCollections.observableArrayList("normal friend", + "best friend"); + + private String relation; + + public Friend(String name, List<String> lastname, String type, String relation, String address, + List<String> telelphoneNumbers, + List<String> emailAddresses, + List<String> socialAcounts, String profession) { + super(name, lastname, type, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + this.relation = relation; + } + + public String getRelation() { + return relation; + } + + public void setRelation(String relation) { + this.relation = relation; + } + +} diff --git a/src/main/java/Contacts/Professional.java b/src/main/java/Contacts/Professional.java new file mode 100644 index 0000000000000000000000000000000000000000..fa99cbd49966ff1feac71d66da4242e83975abcd --- /dev/null +++ b/src/main/java/Contacts/Professional.java @@ -0,0 +1,32 @@ +package Contacts; + +import java.util.List; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +public class Professional extends Contacts { + + public static ObservableList<String> contactRelation = FXCollections.observableArrayList("Boss", "collegue", + "employee", + "collaborator", "manager"); + + private String relation; + + public Professional(String name, List<String> lastname, String type, String relation, String address, + List<String> telelphoneNumbers, + List<String> emailAddresses, + List<String> socialAcounts, String profession) { + super(name, lastname, type, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); + this.relation = relation; + } + + public String getRelation() { + return relation; + } + + public void setRelation(String relation) { + this.relation = relation; + } + +} diff --git a/src/main/java/Family/Family.java b/src/main/java/Family/Family.java deleted file mode 100644 index 38657771e200b24e7a5827ade1ec7b50d8fe5446..0000000000000000000000000000000000000000 --- a/src/main/java/Family/Family.java +++ /dev/null @@ -1,191 +0,0 @@ -package Family; - -import java.util.List; -import java.util.Scanner; - -import Contacts.Contacts; -import Helper.Helper; - -public class Family extends Contacts { - private String Type; - private String familyRelation; - - public Family() { - super(); - this.Type = "Family"; - } - - public Family(String name, List<String> lastname, String address, List<String> telelphoneNumbers, List<String> emailAddresses, - List<String> socialAcounts, String profession, String familyRelation) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - Type = "Family"; - setFamilyRelation(familyRelation); - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setFamilyRelation(String familyRelation) { - this.familyRelation = familyRelation; - } - - public String getFamilyRelation() { - return this.familyRelation; - } - - public void askFamilyRelation() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); - String famRelation = sc.nextLine(); - - while (famRelation.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT FAMILY RELATION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(" Enter Your relation with contact owner [father, mother, brother, sister, ...] : "); - famRelation = sc.nextLine(); - } - setFamilyRelation(famRelation); - - } - - public Family askContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Family]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askFamilyRelation(); - askTelephoneNumber(); - askAdress(); - - askSocialAcount(); - askProfession(); - return this; - - } - public void updateContact(){ - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [Family]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] FAMILY RELATION:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while(option < 1 || option > 8){ - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option){ - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askFamilyRelation(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sFamily Relation : %s", BLUE, - BLUE) - + String.format("\t\t%s" + getFamilyRelation(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } - -} diff --git a/src/main/java/Friends/Friends.java b/src/main/java/Friends/Friends.java deleted file mode 100644 index feee4306384c4e5c479d1b926836978bbfaa0436..0000000000000000000000000000000000000000 --- a/src/main/java/Friends/Friends.java +++ /dev/null @@ -1,191 +0,0 @@ -package Friends; - -import Contacts.Contacts; -import java.util.List; -import java.util.Scanner; - -public class Friends extends Contacts { - - private String Type; - - private String firendsSince; - - public Friends() { - super(); - Type = "Friend"; - } - - public Friends(String name, List<String> lastname, String address, List<String> telelphoneNumbers, - List<String> emailAddresses, - List<String> socialAcounts, String profession, String firendsSince) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - Type = "Friend"; - setFriendsSince(firendsSince); - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setFriendsSince(String str) { - this.firendsSince = str; - - } - - public String getFriendsSince() { - return this.firendsSince; - } - - public void askFriendShipDate() { - - Scanner sc = new Scanner(System.in); - System.out.print(this.name + " is Your friend since : "); - String friendshipeDate = sc.nextLine(); - - while (friendshipeDate.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT FRIENDSHIP DATE !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out.print(this.name + " is Your friend since : "); - friendshipeDate = sc.nextLine(); - } - setFriendsSince(friendshipeDate); - } - - public Contacts askContact() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Friends]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askFriendShipDate(); - askTelephoneNumber(); - askAdress(); - askSocialAcount(); - askProfession(); - return this; - - } - - public void updateContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [FRIENDS]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] FRIENDSHIP DATE:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while (option < 1 || option > 8) { - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option) { - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askFriendShipDate(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sFriendship since : %s", BLUE, - BLUE) - + String.format("\t\t%s" + getFriendsSince(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("\t\t%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } -} diff --git a/src/main/java/Helper/Helper.java b/src/main/java/Helper/Helper.java deleted file mode 100644 index 762e26ccb36137ef5ce216719efbd7a6ceed98bd..0000000000000000000000000000000000000000 --- a/src/main/java/Helper/Helper.java +++ /dev/null @@ -1,115 +0,0 @@ -package Helper; - - - -public abstract class Helper { - - // text color - protected final String RED = "\u001B[31m"; - protected final String BLACK = "\u001B[30m"; - protected final String GREEN = "\u001B[32m"; - protected final String BLUE = "\u001B[34m"; - protected final String RESET = "\u001B[0m"; - protected final String PURPLE = "\u001B[35m"; - protected final String CYAN = "\u001B[36m"; - protected final String YELLOW = "\u001B[33m"; - protected final String WHITE = "\u001B[37m"; - - protected final String YELLOW_BACKGROUND = "\u001B[43m"; - protected final String BLUE_BACKGROUND = "\u001B[44m"; - protected final String BLACK_BACKGROUND = "\u001B[40m"; - protected final String PURPLE_BACKGROUND = "\u001B[45m"; - protected final String CYAN_BACKGROUND = "\u001B[46m"; - protected final String GREEN_BACKGROUND = "\u001B[42m"; - protected final String WHITE_BACKGROUND = "\u001B[47m"; - - protected final int ASK_USER_INPUT = 110; - protected final int SHOW_CONTACTS = 1; - protected final int ADD_CONTACTS = 2; - protected final int SEARCH_CONTACT = 3; - protected final int UPDATE_CONTACTS = 4; - protected final int DELETE_CONTACT = 5; - protected final int EXIT_CONSOLE = 6; - - // clear console screen - protected void clearConsoleScreen() { - System.out.print("\033[H\033[2J"); - System.out.flush(); - } - - // print in color a given text or change background color - protected void PrintInColor(String text, String color) { - - System.out.format("%s %s %s", color, text, color); - System.out.format("%s", RESET); - } - - // Print header of our console application - protected void PrintHeader() { - - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", - YELLOW); - PrintInColor("WELLCOME TO CONTACT MANAGEMENT SYSTEM \n", GREEN); - PrintInColor("==================================================================================\n", - YELLOW); - - PrintInColor("[1]: \tshow contacts\t\t\t\t\n", CYAN); - PrintInColor("[2]: \tadd contact\t\t\t\t\n", CYAN); - PrintInColor("[3]: \tsearch contact\t\t\t\t\n", CYAN); - PrintInColor("[4]: \tupdate a contact\t\t\t\t\n", CYAN); - PrintInColor("[5]: \tdelete a contact\t\t\t\t\n", CYAN); - PrintInColor("[6]: \texit\t\t\t\t\n", CYAN); - PrintInColor("==================================================================================\n", - YELLOW); - } - - // print OPTION ERROR - protected void PrintErrorAndReturn() { - - PrintInColor(" ----------------------------------------------------------------------------------\n", - YELLOW); - PrintInColor("ERROR: WRONG OPTION ID \n", RED); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); - PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - } - - protected void printFooter() { - - PrintInColor(" ----------------------------------------------------------------------------------\n", - YELLOW); - PrintInColor("RETURN TO HOME \n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - - PrintInColor("[1]: \treturn to main menu\t\t\t\t\n", CYAN); - PrintInColor("[2]: \texit\t\t\t\t\n", CYAN); - PrintInColor("----------------------------------------------------------------------------------\n", - YELLOW); - } - - protected void deleteOption() { - PrintInColor(" ==================================================================================\n", - YELLOW); - PrintInColor("DELETE A CONCTACT\n", CYAN); - PrintInColor("==================================================================================\n", - YELLOW); - } - - protected int populateErrorOrReturnHome(int option) { - if (option == 1) { - return ASK_USER_INPUT; - } - if (option == 2) { - System.exit(0); - } - return 0; - } - -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 501e67e6a008694a78430da000ef3a71d3fe062e..74e46a98e9c7709dc71af22b474d971296f41630 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,37 @@ -import Application.Application; +//import Application.Application; -public class Main { +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.paint.Color; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + + + +import java.io.IOException; + +public class Main extends Application { + + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("main.fxml")); + + Scene scene = new Scene(fxmlLoader.load()); + scene.getStylesheets().add(Main.class.getResource("main.css").toExternalForm()); + stage.setTitle("Application!"); + stage.setScene(scene); + + stage.initStyle(StageStyle.UNDECORATED); + stage.initStyle(StageStyle.TRANSPARENT); + scene.setFill(Color.TRANSPARENT); + stage.setResizable(false); + stage.show(); + } public static void main(String[] args) { - new Application().run(); + // new Application().run(); + + launch(args); } } \ No newline at end of file diff --git a/src/main/java/MainController.java b/src/main/java/MainController.java new file mode 100644 index 0000000000000000000000000000000000000000..0959e9e31ccfb92a0213c2b4af11a1e56084a750 --- /dev/null +++ b/src/main/java/MainController.java @@ -0,0 +1,479 @@ + +import Application.Application; +import Contacts.Contacts; +import Contacts.Family; +import Contacts.Friend; +import Contacts.Professional; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.control.cell.PropertyValueFactory; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.input.MouseEvent; +import javafx.scene.text.Text; + +import java.awt.image.BufferedImage; +import java.net.URL; +import java.util.List; +import java.util.Optional; +import java.util.ResourceBundle; +import java.util.function.Predicate; +import java.util.Arrays; +import java.util.stream.Collectors; + +import javax.management.relation.Relation; + +public class MainController implements Initializable { + + Application app = new Application(); + + String searchKey = ""; // // for update base search element 1 + List<String> searchKey2 = List.of(""); // for update base search element 2 + @FXML + private TableView<Contacts> contactTable; + + @FXML + private TableColumn<Contacts, String> colName; + @FXML + private TableColumn<Contacts, List<String>> colLastName; + @FXML + private TableColumn<Contacts, String> colType; + + @FXML + private TableColumn<Contacts, String> colRelation; + + @FXML + private TableColumn<Contacts, String> colAddress; + @FXML + private TableColumn<Contacts, List<String>> colTelephone; + + @FXML + private TableColumn<Contacts, List<String>> colEmail; + + @FXML + private TableColumn<Contacts, List<String>> colSocialAcount; + @FXML + private TableColumn<Contacts, String> colProfession; + + @FXML + private TextField name; + @FXML + private TextField lastName; + @FXML + private ComboBox<String> comboType; + @FXML + private ComboBox<String> comboRelation; + + @FXML + private ImageView profilImage; + + @FXML + private Text profilName; + + ObservableList<String> contactType = FXCollections.observableArrayList("", "Family", "Friend", "Professional"); + ObservableList<String> contactRelation = FXCollections.observableArrayList(""); + + @FXML + void changeComboType(ActionEvent event) { + + switch (comboType.getValue()) { + case "Family": + comboRelation.setItems(Family.contactRelation); + break; + case "Friend": + comboRelation.setItems(Friend.contactRelation); + break; + case "Professional": + comboRelation.setItems(Professional.contactRelation); + default: + + } + } + + @FXML + private TextField address; + @FXML + private TextField telephone; + @FXML + private TextField email; + @FXML + private TextField socialAcount; + @FXML + private TextField profession; + + @FXML + private Button allcontacts; + @FXML + private Button familyContacts; + @FXML + private Button friendsContacts; + @FXML + private Button professionalContacts; + + @FXML + private Button add; + @FXML + private Button update; + @FXML + private Button search; + @FXML + private Button delete; + + @FXML + private Button clearFormBtn; + + @FXML + void clearForm(ActionEvent event) { + + name.clear(); + lastName.clear(); + address.clear(); + telephone.clear(); + email.clear(); + socialAcount.clear(); + profession.clear(); + comboType.setValue(contactType.get(0)); + comboRelation.setValue(null); + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + showContacts(); + + comboType.setItems(contactType); + comboRelation.setItems(contactRelation); + + } + + public void showContacts() { + + colName.setCellValueFactory(new PropertyValueFactory<Contacts, String>("name")); + + colLastName.setCellValueFactory(new PropertyValueFactory<Contacts, List<String>>("lastname")); + + colLastName.setCellFactory(col -> { + return new TableCell<Contacts, List<String>>() { + @Override + protected void updateItem(List<String> item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setText(null); + } else { + setText(String.join(", ", item)); + } + } + }; + }); + + colType.setCellValueFactory(new PropertyValueFactory<Contacts, String>("type")); + + colRelation.setCellValueFactory(new PropertyValueFactory<Contacts, String>("relation")); + + colAddress.setCellValueFactory(new PropertyValueFactory<Contacts, String>("address")); + + colTelephone.setCellValueFactory(new PropertyValueFactory<Contacts, List<String>>("telelphoneNumbers")); + colTelephone.setCellFactory(col -> { + return new TableCell<Contacts, List<String>>() { + + @Override + protected void updateItem(List<String> item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setText(null); + } else { + setText(String.join(", ", item)); + } + } + }; + }); + + colEmail.setCellValueFactory(new PropertyValueFactory<Contacts, List<String>>("emailAddresses")); + colEmail.setCellFactory(col -> { + return new TableCell<Contacts, List<String>>() { + @Override + protected void updateItem(List<String> item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setText(null); + } else { + setText(String.join(", ", item)); + } + } + }; + }); + + colSocialAcount.setCellValueFactory(new PropertyValueFactory<Contacts, List<String>>("socialAcounts")); + colSocialAcount.setCellFactory(col -> + + { + return new TableCell<Contacts, List<String>>() { + @Override + protected void updateItem(List<String> item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setText(null); + } else { + setText(String.join(", ", item)); + } + } + }; + }); + + colProfession.setCellValueFactory(new PropertyValueFactory<Contacts, String>("profession")); + + contactTable.setItems(app.getContactList()); + } + + // checks all inputs + public boolean allInputInvalid() { + Predicate<String> isZero = (str) -> str.length() == 0; + + var combo1 = comboType.getSelectionModel().getSelectedItem(); + var combo2 = comboRelation.getSelectionModel().getSelectedItem(); + + boolean comboInvalid = combo1 == null || combo2 == null; + + boolean inputInvalid = List + .of(name.getText(), lastName.getText(), address.getText(), telephone.getText(), email.getText(), + socialAcount.getText()) + .stream() + .allMatch(isZero); + + return (inputInvalid || comboInvalid); + } + + // checks input for search : at lease one shouldn't be empty or null + public boolean searchInputvalid() { + + Predicate<String> isOk = (str) -> str.length() != 0; + + var combo1 = comboType.getSelectionModel().getSelectedItem(); + var combo2 = comboRelation.getSelectionModel().getSelectedItem(); + + boolean comboInvalid = combo1 != null || combo2 != null; + + boolean inputInvalid = List + .of(name.getText(), lastName.getText(), address.getText(), telephone.getText(), email.getText(), + socialAcount.getText()) + .stream() + .anyMatch(isOk); + + return (inputInvalid || comboInvalid); + } + + @FXML + void addNewConact(ActionEvent event) { + + if (allInputInvalid()) { + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("add error"); + alert.setContentText("All filed are required !"); + + alert.showAndWait(); + + } else { + String contactName = name.getText(); + List<String> contactLastName = Arrays.asList(lastName.getText().split(",")); + String contactType = comboType.getValue(); + String contactRelation = comboRelation.getValue(); + String contactAddress = address.getText(); + List<String> contactTelephone = Arrays.asList(telephone.getText().split(",")); + List<String> contactEmail = Arrays.asList(email.getText().split(",")); + List<String> contactSocialAcount = Arrays.asList(socialAcount.getText().split(",")); + String contactProfession = profession.getText(); + + switch (comboType.getValue()) { + case "Family": + Family familyContact = new Family(contactName, contactLastName, contactType, contactRelation, + contactAddress, contactTelephone, + contactEmail, contactSocialAcount, contactProfession); + + app.addToContactList(familyContact); + break; + case "Friend": + Friend friendContact = new Friend(contactName, contactLastName, contactType, contactRelation, + contactAddress, contactTelephone, + contactEmail, contactSocialAcount, contactProfession); + app.addToContactList(friendContact); + break; + case "Professional": + Professional professionalContact = new Professional(contactName, contactLastName, contactType, + contactRelation, + contactAddress, contactTelephone, + contactEmail, contactSocialAcount, contactProfession); + app.addToContactList(professionalContact); + default: + } + + // save the data to json file + app.saveContactList(app.getContactList()); + // showContacts(); + } + + } + + @FXML + void displayForUpdate(MouseEvent event) { + + Contacts temp_contact = contactTable.getSelectionModel().getSelectedItem(); + if (temp_contact != null) { + + Image image = null; + try { + image = new Image( + "https://randomuser.me/api/portraits/men/" + app.getContactList().indexOf(temp_contact) + ".jpg"); + } catch (Exception e) { + e.printStackTrace(); + } + + profilImage.setImage(image); + + profilName.setText(temp_contact.getName() + " (" + temp_contact.getLastname().get(0) + ")"); + + name.setText(temp_contact.getName()); + lastName.setText(String.join(",", temp_contact.getLastname())); + comboType.setValue(temp_contact.getType()); + comboRelation.setValue(temp_contact.getRelation()); + + address.setText(String.join(",", temp_contact.getAddress())); + telephone.setText(String.join(",", temp_contact.getTelelphoneNumbers())); + email.setText(String.join(",", temp_contact.getEmailAddresses())); + socialAcount.setText(String.join(",", temp_contact.getSocialAcounts())); + profession.setText(temp_contact.getProfession()); + searchKey = temp_contact.getName(); + searchKey2 = temp_contact.getLastname(); + } + + } + + @FXML + void updateConact(ActionEvent event) { + + if (allInputInvalid()) { + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("update error"); + alert.setContentText("choose a contact from table !"); + + alert.showAndWait(); + + } else { + // populate the contactsList with Contacts objects + Optional<Contacts> searchedContact = app.getContactList() + .stream() + .filter( + e -> e.getName().equals(searchKey)) + .filter(e -> e.getLastname().get(0).equals(searchKey2.get(0))) + .findFirst(); + + if (searchedContact.isPresent()) { + int index = app.getContactList().indexOf(searchedContact.get()); + + searchedContact.get().setName(name.getText()); + searchedContact.get().setLastname(Arrays.asList(lastName.getText().split(","))); + searchedContact.get().setType(comboType.getValue()); + searchedContact.get().setRelation(comboRelation.getValue()); + searchedContact.get().setAddress(address.getText()); + searchedContact.get().setEmailAddresses(Arrays.asList(email.getText().split(","))); + searchedContact.get().setTelelphoneNumbers(Arrays.asList(telephone.getText().split(","))); + searchedContact.get().setSocialAcounts(Arrays.asList(socialAcount.getText().split(","))); + searchedContact.get().setProfession(profession.getText()); + + app.getContactList().set(index, searchedContact.get()); + searchKey = ""; + searchKey2 = List.of(""); + app.saveContactList(app.getContactList()); + + } + + } + + } + + @FXML + void deleteContact(ActionEvent event) { + // populate the contactsList with Contacts objects + app.delete(searchKey); + } + + @FXML + void searchContact(ActionEvent event) { + + if (!searchInputvalid()) { + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("update error"); + alert.setContentText("choose a contact from table !"); + + alert.showAndWait(); + + } else { + ObservableList<Contacts> filteredList = app.getContactList().stream() + .filter( + e -> e.getName().equals(name.getText()) + || e.getLastname().get(0).equals(Arrays.asList(lastName.getText().split(",")).get(0)) + || (comboType.getValue() == null) + ? true + : e.getType().toLowerCase().equals(comboType.getValue().toLowerCase()) + + || e.getAddress().equals(address.getText()) + || e.getTelelphoneNumbers().get(0) + .equals(Arrays.asList(Arrays.asList(telephone.getText().split(",")))) + || e.getEmailAddresses().get(0) + .equals(Arrays.asList(Arrays.asList(email.getText().split(",")))) + || e.getSocialAcounts().get(0) + .equals(Arrays.asList(Arrays.asList(socialAcount.getText().split(",")))) + || e.getProfession().equals(profession.getText())) + .collect(Collectors.toCollection(FXCollections::observableArrayList)); + + contactTable.setItems(filteredList); + } + + } + + @FXML + void exitApplication(ActionEvent event) { + app.saveContactList(app.getContactList()); + System.exit(0); + } + + @FXML + void showAllcontacts(ActionEvent event) { + contactTable.setItems(app.getContactList()); + } + + @FXML + void showFamilyContacts(ActionEvent event) { + + ObservableList<Contacts> filteredList = app.getContactList() + .stream() + .filter(e -> e.getType().toLowerCase().equals("Family".toLowerCase())) + .collect(Collectors.toCollection(FXCollections::observableArrayList)); + contactTable.setItems(filteredList); + + } + + @FXML + void showFriendsContacts(ActionEvent event) { + + ObservableList<Contacts> filteredList = app.getContactList() + .stream() + .filter(e -> e.getType().toLowerCase().equals("Friend".toLowerCase())) + .collect(Collectors.toCollection(FXCollections::observableArrayList)); + contactTable.setItems(filteredList); + } + + @FXML + void showProfessionalContacts(ActionEvent event) { + ObservableList<Contacts> filteredList = app.getContactList() + .stream() + .filter(e -> e.getType().toLowerCase().equals("Professional".toLowerCase())) + .collect(Collectors.toCollection(FXCollections::observableArrayList)); + contactTable.setItems(filteredList); + } + +} diff --git a/src/main/java/Professional/Professional.java b/src/main/java/Professional/Professional.java deleted file mode 100644 index 41b9301e519c200266408d1ba4c9cb5a6677c51b..0000000000000000000000000000000000000000 --- a/src/main/java/Professional/Professional.java +++ /dev/null @@ -1,192 +0,0 @@ -package Professional; - -import java.util.List; -import java.util.Scanner; - -import Contacts.Contacts; -import Family.Family; - -public class Professional extends Contacts { - private String Type; - - private String ProfessionRelation; - - public Professional() { - super(); - Type = "Professional"; - } - - public Professional(String name, List<String> lastname, String address, List<String> telelphoneNumbers, - List<String> emailAddresses, List<String> socialAcounts, String profession, String professionRelation) { - super(name, lastname, address, telelphoneNumbers, emailAddresses, socialAcounts, profession); - setProfessionRelation(professionRelation); - Type = "Professional"; - } - - @Override - public String getType() { - return Type; - } - - @Override - public void setType(String type) { - Type = type; - } - - public void setProfessionRelation(String professionRelation) { - ProfessionRelation = professionRelation; - } - - public String getProfessionalRelation() { - return this.ProfessionRelation; - } - - public void askProfessionalRelation() { - - Scanner sc = new Scanner(System.in); - System.out.print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); - String proRelation = sc.nextLine(); - - while (proRelation.length() < 5) { - System.out - .println( - String.format("\n %sPLEASE INSERT A CORRECT PROFESSIONAL RELATION !%s%s", - RED, - RED, - RESET)); - System.out.println(); - System.out - .print(" Enter Your relation with contact owner [Boss, Collegue, Aprentice,collaborator, ...] : "); - proRelation = sc.nextLine(); - } - setProfessionRelation(proRelation); - - } - - public Professional askContact() { - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "CREATE A CONTACT [Professional]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - askName(); - askLastName(); - askEmail(); - // - askProfessionalRelation(); - askTelephoneNumber(); - askAdress(); - askSocialAcount(); - askProfession(); - - return this; - - } - - public void updateContact(){ - clearConsoleScreen(); - PrintInColor(" ==================================================================================\n", GREEN); - PrintInColor(String.format("%s\n", "UPDATE CONTACT [PROFESSIONAL]"), BLUE); - PrintInColor("==================================================================================\n", GREEN); - - System.out.println("CHOOSE WHICH FIELD YOU WANT TO UPDATE"); - System.out.println("[1] NAME "); - System.out.println("[2] LASTNAME "); - System.out.println("[3] EMAIL"); - System.out.println("[4] PROFESSIONAL RELATION:"); - System.out.println("[5] TELEPHONE NUMBER:"); - System.out.println("[6] ADDRESS:"); - System.out.println("[7] SOCIAL ACOUNT:"); - System.out.println("[8] PROFESSION:"); - - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - Scanner sc = new Scanner(System.in); - int option = sc.nextInt(); - while(option < 1 || option > 8){ - System.out.format("%s %s %s\n", RED, "ERREUR: PLEASE CHOOSE THE CORRECT OPTION", RED); - System.out.format("%s", RESET); - System.out.format("%s %s %s : [] ", BLUE, "YOUR OPTION ", BLUE); - option = sc.nextInt(); - } - - switch (option){ - case 1: - askName(); - break; - case 2: - askLastName(); - break; - case 3: - askEmail(); - break; - case 4: - askProfessionalRelation(); - break; - case 5: - askTelephoneNumber(); - break; - case 6: - askAdress(); - break; - case 7: - askSocialAcount(); - break; - case 8: - askProfession(); - break; - } - } - - @Override - public void showContact() { - - System.out.println( - "----------------------------------------------------------------------------------"); - System.out.println(); - - System.out.println(String.format(" %sName : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getName(), RESET)); - - System.out.println(); - String lastnames = String.join(",", getLastname()); - System.out.println(String.format(" %sLast Name : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + lastnames, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfessional Relation : %s", BLUE, - BLUE) - + String.format("\t\t%s" + getProfessionalRelation(), RESET)); - - System.out.println(); - System.out.println(String.format(" %sAddress : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + getAddress(), RESET)); - - System.out.println(); - String emails = String.join(", ", getEmailAddresses()); - System.out.println(String.format(" %sEmail : %s", BLUE, BLUE) - + String.format("\t\t\t%s" + emails, RESET)); - - System.out.println(); - String telephone_numbers = String.join(", ", getTelelphoneNumbers()); - System.out.println(String.format(" %sTelephone Number : %s", BLUE, - BLUE) - + String.format("\t\t%s" + telephone_numbers, RESET)); - - System.out.println(); - String social_acounts = String.join(", ", getSocialAcounts()); - System.out.println(String.format(" %sSocial Acount : %s", BLUE, - BLUE) - + String.format("\t\t%s" + social_acounts, RESET)); - - System.out.println(); - System.out.println(String.format(" %sProfession : %s", BLUE, - BLUE) - + String.format("\t\t\t%s" + getProfession(), RESET)); - - System.out.println(); - System.out.println( - "----------------------------------------------------------------------------------\n"); - - } -} diff --git a/src/main/resources/add.png b/src/main/resources/add.png new file mode 100644 index 0000000000000000000000000000000000000000..8a14ff4f9c9c23c93784d187246d069c289c7438 Binary files /dev/null and b/src/main/resources/add.png differ diff --git a/src/main/resources/bg.png b/src/main/resources/bg.png new file mode 100644 index 0000000000000000000000000000000000000000..59b6f545f75c127c90028869679226f9a6477842 Binary files /dev/null and b/src/main/resources/bg.png differ diff --git a/src/main/resources/close50.png b/src/main/resources/close50.png new file mode 100644 index 0000000000000000000000000000000000000000..b67e064ac48a2664ef898d4e5f31b691e6fea43d Binary files /dev/null and b/src/main/resources/close50.png differ diff --git a/src/main/resources/close_red.png b/src/main/resources/close_red.png new file mode 100644 index 0000000000000000000000000000000000000000..ddd34bf5cb66e30c6795972c26827b2cad79f378 Binary files /dev/null and b/src/main/resources/close_red.png differ diff --git a/src/main/resources/delete.png b/src/main/resources/delete.png new file mode 100644 index 0000000000000000000000000000000000000000..6c2c83939ef3f91153c26678641209ec4ab86a2a Binary files /dev/null and b/src/main/resources/delete.png differ diff --git a/src/main/resources/e.png b/src/main/resources/e.png new file mode 100644 index 0000000000000000000000000000000000000000..185adc25659b5a65f02b70f23de2f947ac9f655a Binary files /dev/null and b/src/main/resources/e.png differ diff --git a/src/main/resources/main.css b/src/main/resources/main.css new file mode 100644 index 0000000000000000000000000000000000000000..c6c89ea0da15c8b11a78d4f444faa574fe0c97bc --- /dev/null +++ b/src/main/resources/main.css @@ -0,0 +1,29 @@ + + + +.btn { + -fx-effect:null; +} +.btn { + /* Remove focus highlighting */ + -fx-focus-traversable: false; +} + + + +.btn:hover { + -fx-text-fill: #44c662; + -fx-border-color: #44c662; + + +} + +.btn:pressed { + -fx-scale-y: 0.9; + -fx-scale-x: 0.9; +} + +.button:pressed { + -fx-scale-y: 0.9; + -fx-scale-x: 0.9; +} \ No newline at end of file diff --git a/src/main/resources/main.fxml b/src/main/resources/main.fxml new file mode 100644 index 0000000000000000000000000000000000000000..47c923ba3d98f7a14e0b3d37fd1e1339ff4cf730 --- /dev/null +++ b/src/main/resources/main.fxml @@ -0,0 +1,343 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Copyright (c) 2015, 2019, Gluon and/or its affiliates. + All rights reserved. Use is subject to license terms. + + This file is available and licensed under the following license: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + - Neither the name of Oracle Corporation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> + +<?import javafx.geometry.Insets?> +<?import javafx.scene.Cursor?> +<?import javafx.scene.control.Button?> +<?import javafx.scene.control.ComboBox?> +<?import javafx.scene.control.TableColumn?> +<?import javafx.scene.control.TableView?> +<?import javafx.scene.control.TextField?> +<?import javafx.scene.image.Image?> +<?import javafx.scene.image.ImageView?> +<?import javafx.scene.layout.BorderPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.Pane?> +<?import javafx.scene.layout.VBox?> +<?import javafx.scene.text.Font?> +<?import javafx.scene.text.Text?> + +<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="784.0" prefWidth="1469.0" style="-fx-border-color: #999;" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MainController"> + <left> + <VBox prefHeight="596.0" prefWidth="204.0" style="-fx-background-color: #2d4059;" BorderPane.alignment="CENTER"> + <children> + <Pane prefHeight="108.0" prefWidth="185.0"> + <children> + <ImageView fitHeight="50.0" fitWidth="178.0" focusTraversable="true" layoutX="1.0" layoutY="16.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@e.png" /> + </image> + </ImageView> + </children> + </Pane> + <Button fx:id="allcontacts" alignment="BASELINE_LEFT" mnemonicParsing="false" onAction="#showAllcontacts" prefHeight="54.0" prefWidth="211.0" style="-fx-background-color: #2d4059;" styleClass="btn" text="ALL CONTACTS" textFill="WHITE"> + <opaqueInsets> + <Insets /> + </opaqueInsets> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <font> + <Font size="12.0" /> + </font> + <padding> + <Insets left="15.0" /> + </padding> + </Button> + <Button fx:id="familyContacts" alignment="BASELINE_LEFT" mnemonicParsing="false" onAction="#showFamilyContacts" prefHeight="54.0" prefWidth="210.0" style="-fx-background-color: #2d4059;" styleClass="btn" text="FAMILY CONTACTS" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <font> + <Font size="12.0" /> + </font> + <padding> + <Insets left="15.0" /> + </padding> + </Button> + <Button fx:id="friendsContacts" alignment="BASELINE_LEFT" mnemonicParsing="false" onAction="#showFriendsContacts" prefHeight="55.0" prefWidth="228.0" style="-fx-background-color: #2d4059;" styleClass="btn" text="FRIENDS CONTACTS" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <font> + <Font size="12.0" /> + </font> + <padding> + <Insets left="15.0" /> + </padding> + </Button> + <Button fx:id="professionalContacts" alignment="BASELINE_LEFT" mnemonicParsing="false" onAction="#showProfessionalContacts" prefHeight="55.0" prefWidth="222.0" style="-fx-background-color: #2d4059;" styleClass="btn" text="PROFESSIONAL CONTACTS" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <font> + <Font size="12.0" /> + </font> + <padding> + <Insets left="15.0" /> + </padding> + </Button> + <Pane prefHeight="124.0" prefWidth="204.0" /> + <Pane prefHeight="335.0" prefWidth="204.0"> + <children> + <Text fill="#f95959" layoutX="40.0" layoutY="311.0" strokeType="OUTSIDE" strokeWidth="0.0" text="HEPIA, POO 2023" /> + </children></Pane> + </children> + <padding> + <Insets left="10.0" right="10.0" /> + </padding> + </VBox> + </left> + <center> + <HBox prefHeight="782.0" prefWidth="1307.0" style="-fx-background-color: #fff;" BorderPane.alignment="CENTER"> + <children> + <VBox prefHeight="782.0" prefWidth="1266.0"> + <children> + <VBox alignment="TOP_CENTER" prefHeight="400.0" prefWidth="1125.0"> + <children> + <Pane prefHeight="44.0" prefWidth="1118.0"> + <children> + <Button layoutX="1213.0" layoutY="3.0" mnemonicParsing="false" onAction="#exitApplication" style="-fx-background-color: transparent;"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <graphic> + <ImageView fitHeight="29.0" fitWidth="37.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@close_red.png" /> + </image> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + </ImageView> + </graphic> + </Button> + </children> + </Pane> + <HBox prefHeight="275.0" prefWidth="1072.0"> + <children> + <VBox prefHeight="275.0" prefWidth="882.0"> + <children> + <HBox alignment="CENTER_LEFT" prefHeight="43.0" prefWidth="300.0" spacing="17.0"> + <children> + <Pane prefHeight="43.0" prefWidth="300.0"> + <children> + <Text layoutX="4.0" layoutY="26.0" strokeType="OUTSIDE" strokeWidth="0.0" text="name" wrappingWidth="58.8671875" /> + <TextField fx:id="name" layoutX="78.0" layoutY="10.0" prefHeight="24.0" prefWidth="227.0" promptText="your name" /> + </children> + </Pane> + <Pane prefHeight="43.0" prefWidth="364.0"> + <children> + <Text layoutX="14.0" layoutY="26.0" strokeType="OUTSIDE" strokeWidth="0.0" text="last name" wrappingWidth="94.8671875" /> + <TextField fx:id="lastName" layoutX="133.0" layoutY="10.0" prefHeight="24.0" prefWidth="217.0" promptText="lastname" /> + </children> + </Pane> + </children> + <padding> + <Insets left="17.0" /> + </padding> + </HBox> + <HBox alignment="CENTER_LEFT" prefHeight="43.0" prefWidth="300.0" spacing="17.0"> + <padding> + <Insets left="17.0" /> + </padding> + <children> + <Pane prefHeight="43.0" prefWidth="312.0"> + <children> + <Text layoutX="4.0" layoutY="26.0" strokeType="OUTSIDE" strokeWidth="0.0" text="address" wrappingWidth="58.8671875" /> + <TextField fx:id="address" layoutX="78.0" layoutY="10.0" prefHeight="24.0" prefWidth="226.0" promptText="your address" /> + </children> + </Pane> + <Pane prefHeight="43.0" prefWidth="346.0"> + <children> + <Text layoutY="27.0" strokeType="OUTSIDE" strokeWidth="0.0" text="telephone" wrappingWidth="94.8671875" /> + <TextField fx:id="telephone" layoutX="120.0" layoutY="10.0" prefHeight="24.0" prefWidth="220.0" promptText="+418888888" /> + </children> + </Pane> + </children> + </HBox> + <HBox alignment="CENTER_LEFT" prefHeight="43.0" prefWidth="300.0" spacing="17.0"> + <padding> + <Insets left="17.0" /> + </padding> + <children> + <Pane prefHeight="43.0" prefWidth="312.0"> + <children> + <Text layoutX="4.0" layoutY="26.0" strokeType="OUTSIDE" strokeWidth="0.0" text="email" wrappingWidth="58.8671875" /> + <TextField fx:id="email" layoutX="78.0" layoutY="10.0" prefHeight="24.0" prefWidth="226.0" promptText="you@demo.com" /> + </children> + </Pane> + <Pane prefHeight="43.0" prefWidth="346.0"> + <children> + <Text layoutY="27.0" strokeType="OUTSIDE" strokeWidth="0.0" text="social acount" wrappingWidth="94.8671875" /> + <TextField fx:id="socialAcount" layoutX="120.0" layoutY="10.0" prefHeight="24.0" prefWidth="220.0" promptText="https://" /> + </children> + </Pane> + </children> + </HBox> + <HBox alignment="CENTER_LEFT" prefHeight="43.0" prefWidth="300.0" spacing="17.0"> + <padding> + <Insets left="17.0" /> + </padding> + <children> + <Pane prefHeight="43.0" prefWidth="322.0"> + <children> + <Text layoutY="25.0" strokeType="OUTSIDE" strokeWidth="0.0" text="profession" wrappingWidth="67.8671875" /> + <TextField fx:id="profession" layoutX="78.0" layoutY="10.0" prefHeight="24.0" prefWidth="226.0" promptText="student" /> + </children> + </Pane> + <Pane prefHeight="40.0" prefWidth="341.0"> + <children> + <Text layoutX="-2.0" layoutY="25.0" strokeType="OUTSIDE" strokeWidth="0.0" text="type" wrappingWidth="67.8671875" /> + <ComboBox fx:id="comboType" layoutX="110.0" layoutY="7.0" onAction="#changeComboType" prefHeight="24.0" prefWidth="220.0" promptText="Type" /> + </children> + </Pane> + </children> + </HBox> + <HBox alignment="CENTER_LEFT" prefHeight="59.0" prefWidth="669.0" spacing="50.0"> + <padding> + <Insets left="17.0" /> + </padding> + <children> + <Pane prefHeight="40.0" prefWidth="341.0"> + <children> + <Text layoutX="-1.0" layoutY="29.0" strokeType="OUTSIDE" strokeWidth="0.0" text="relation" wrappingWidth="67.8671875" /> + <ComboBox fx:id="comboRelation" layoutX="75.0" layoutY="15.0" prefHeight="24.0" prefWidth="226.0" promptText="relation" /> + </children> + </Pane> + <Pane prefHeight="40.0" prefWidth="341.0"> + <children> + <Button fx:id="add" layoutX="67.0" layoutY="15.0" mnemonicParsing="false" onAction="#addNewConact" prefHeight="33.0" prefWidth="220.0" style="-fx-background-color: #88a9f7;" text="ADD new contact" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + </Button> + <ImageView fitHeight="21.0" fitWidth="26.0" layoutX="86.0" layoutY="22.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@add.png" /> + </image> + </ImageView> + </children> + </Pane> + </children> + </HBox> + <Pane prefHeight="60.0" prefWidth="728.0"> + <children> + <Button fx:id="update" layoutX="9.0" layoutY="11.0" mnemonicParsing="false" onAction="#updateConact" prefHeight="33.0" prefWidth="165.0" style="-fx-background-color: #44c662;" text="update contact" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <graphic> + <ImageView fitHeight="21.0" fitWidth="26.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@update1.png" /> + </image> + </ImageView> + </graphic> + </Button> + <Button fx:id="search" layoutX="187.0" layoutY="11.0" mnemonicParsing="false" onAction="#searchContact" prefHeight="33.0" prefWidth="144.0" style="-fx-background-color: #7986c7;" text="search contact" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <graphic> + <ImageView fitHeight="21.0" fitWidth="26.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@search.png" /> + </image> + </ImageView> + </graphic> + </Button> + <Button fx:id="delete" layoutX="537.0" layoutY="10.0" mnemonicParsing="false" onAction="#deleteContact" prefHeight="33.0" prefWidth="149.0" style="-fx-background-color: #f95959;" text="delete contact" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <graphic> + <ImageView fitHeight="21.0" fitWidth="26.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@delete.png" /> + </image> + </ImageView> + </graphic> + </Button> + <Button fx:id="clearFormBtn" layoutX="344.0" layoutY="10.0" mnemonicParsing="false" onAction="#clearForm" prefHeight="33.0" prefWidth="174.0" style="-fx-background-color: #00bbf0;" text="clear Form" textFill="WHITE"> + <cursor> + <Cursor fx:constant="HAND" /> + </cursor> + <graphic> + <ImageView fitHeight="21.0" fitWidth="26.0" pickOnBounds="true" preserveRatio="true"> + <image> + <Image url="@refresh.png" /> + </image> + </ImageView> + </graphic> + </Button> + </children> + </Pane> + </children> + </VBox> + <Pane prefHeight="275.0" prefWidth="689.0"> + <children> + <Pane layoutX="156.0" layoutY="14.0" prefHeight="158.0" prefWidth="151.0" style="-fx-border-color: #999;"> + <children> + <ImageView fx:id="profilImage" fitHeight="158.0" fitWidth="154.0" layoutX="-2.0" pickOnBounds="true" preserveRatio="true" /> + </children> + </Pane> + <Text fx:id="profilName" layoutX="156.0" layoutY="189.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="150.7294921875" /> + </children></Pane> + </children> + </HBox> + </children> + </VBox> + <TableView fx:id="contactTable" fixedCellSize="0.0" onMouseClicked="#displayForUpdate" prefHeight="532.0" prefWidth="1263.0"> + <columns> + <TableColumn fx:id="colName" prefWidth="121.0" text="name" /> + <TableColumn fx:id="colLastName" editable="false" prefWidth="127.0" text="last name" /> + <TableColumn fx:id="colType" editable="false" prefWidth="125.0" text="contactType" /> + <TableColumn fx:id="colRelation" editable="false" prefWidth="157.0" text="relation" /> + <TableColumn fx:id="colAddress" editable="false" prefWidth="160.0" text="address" /> + <TableColumn fx:id="colTelephone" editable="false" prefWidth="138.0" text="telelphone" /> + <TableColumn fx:id="colEmail" editable="false" prefWidth="150.0" text="email" /> + <TableColumn fx:id="colSocialAcount" editable="false" minWidth="0.0" prefWidth="159.0" text="social acount" /> + <TableColumn fx:id="colProfession" editable="false" prefWidth="124.0" text="profession" /> + </columns> + <opaqueInsets> + <Insets /> + </opaqueInsets> + </TableView> + </children> + </VBox> + </children> + </HBox> + </center> +</BorderPane> diff --git a/src/main/resources/refresh.png b/src/main/resources/refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..9156d0f9c45b3bb30522812d63b442862bcaad89 Binary files /dev/null and b/src/main/resources/refresh.png differ diff --git a/src/main/resources/search.png b/src/main/resources/search.png new file mode 100644 index 0000000000000000000000000000000000000000..8212bbbc81088b4813beb428ac3cd10733f25a5e Binary files /dev/null and b/src/main/resources/search.png differ diff --git a/src/main/resources/sidebar.css b/src/main/resources/sidebar.css new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main/resources/update.png b/src/main/resources/update.png new file mode 100644 index 0000000000000000000000000000000000000000..956aafe614975b61df6517955bfb176bb239eabd Binary files /dev/null and b/src/main/resources/update.png differ diff --git a/src/main/resources/update1.png b/src/main/resources/update1.png new file mode 100644 index 0000000000000000000000000000000000000000..f43ae47d7424fd65695878b1cb5b98a3856ed064 Binary files /dev/null and b/src/main/resources/update1.png differ diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 1b3f79c4d3aa74c345709fe9011d94081032f35e..339f53c1cca2f3f5a5efaf83d2c08f7bf543db75 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -1,12 +1,14 @@ import static org.junit.Assert.assertEquals; + import java.util.List; +import java.util.Optional; import org.junit.Test; import Application.Application; import Contacts.Contacts; -import Friends.Friends; +import Contacts.Friend; public class MainTest { @@ -26,16 +28,30 @@ public class MainTest { List<String> email = List.of("alex@gmail.com"); List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; - String friendSince = "2022/02/02"; - Contacts contact = new Friends(name, lastName, address, email, telephoneNumber, socialAcount, profession, - friendSince); + String type = "Friend"; + String relation = "close friend"; + + Contacts contact = new Friend(name, lastName, type, relation, address, telephoneNumber, email, socialAcount, + profession); + + int sizeBeforeAdd = app.getContactList().size(); app.addToContactList(contact); - assertEquals(app.getContactList().size(), 1); - assertEquals(app.getContactList().get(0).getName(), name); - assertEquals(app.getContactList().get(0).getType(), contact.getType()); + // check size + 1 + assertEquals(app.getContactList().size(), 1 + sizeBeforeAdd); + + // check if present + Optional<Contacts> filtered = app.getContactList() + .stream() + .filter(e -> e.getLastname().get(0).equals(lastName.get(0))) + + .findFirst(); + assertEquals(filtered.isPresent(), Boolean.TRUE); + + // check type + assertEquals(filtered.get().getType(), contact.getType()); } @Test @@ -48,17 +64,20 @@ public class MainTest { List<String> email = List.of("alex@gmail.com"); List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; - String friendSince = "2022/02/02"; - Contacts contact = new Friends(name, lastName, address, email, telephoneNumber, socialAcount, profession, - friendSince); + String type = "Friend"; + String relation = Friend.contactRelation.get(0); + Contacts contact = new Friend(name, lastName, type, relation, address, telephoneNumber, email, socialAcount, + profession); + int sizeBeforeAdd = app.getContactList().size(); app.addToContactList(contact); - app.delete(1); + // delete should return true if found + assertEquals(app.delete(name), Boolean.TRUE); + // the size should bee eqauls means delete works + assertEquals(app.getContactList().size(), sizeBeforeAdd); - // after delete size should be 0 - assertEquals(app.getContactList().size(), 0); } @Test @@ -71,16 +90,16 @@ public class MainTest { List<String> email = List.of("alex@gmail.com"); List<String> socialAcount = List.of("https://hello.com/?name=alex"); String profession = "student"; - String friendSince = "2022/02/02"; + String relation = "close freind"; - Contacts contact1 = new Friends(name, lastName, address, email, telephoneNumber, socialAcount, profession, - friendSince); + Contacts contact1 = new Friend(name, lastName, "Friend", relation, address, telephoneNumber, email, socialAcount, + profession); String name2 = "AAAAAA"; - List<String> lastName2 = List.of("BBBBBBBBBBBBBBB", "BOURRRRRIS"); + List<String> lastName2 = List.of("AAAAAA", "BBBBB"); - Contacts contact2 = new Friends(name2, lastName2, address, email, telephoneNumber, socialAcount, profession, - friendSince); + Contacts contact2 = new Friend(name2, lastName2, "Friend", relation, address, email, telephoneNumber, socialAcount, + profession); app.addToContactList(contact1); app.addToContactList(contact2); @@ -89,29 +108,4 @@ public class MainTest { assertEquals(app.getContactList().get(0).getName(), name2); } - - @Test - public void search() { - - String name = "nonexisting"; - List<String> lastName = List.of("kurteshi", "browman"); - String address = "rue du rhone 4, 1203 Genève"; - List<String> telephoneNumber = List.of("+41 77 444 33 22"); - List<String> email = List.of("alex@gmail.com"); - List<String> socialAcount = List.of("https://hello.com/?name=alex"); - String profession = "student"; - String friendSince = "2022/02/02"; - - Contacts contact = new Friends(name, lastName, address, email, telephoneNumber, socialAcount, profession, - friendSince); - - boolean findAlex = app.getContactList().stream().anyMatch(e -> e.getName().equals(name)); - - app.addToContactList(contact); - - boolean findagian = app.getContactList().stream().anyMatch(e -> e.getName().equals(name)); - - assertEquals(!findAlex, findagian); - - } }