diff --git a/.gradle/9.3.1/executionHistory/executionHistory.bin b/.gradle/9.3.1/executionHistory/executionHistory.bin index 2828a91..855f95c 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.bin and b/.gradle/9.3.1/executionHistory/executionHistory.bin differ diff --git a/.gradle/9.3.1/executionHistory/executionHistory.lock b/.gradle/9.3.1/executionHistory/executionHistory.lock index acffcc0..169f2c3 100755 Binary files a/.gradle/9.3.1/executionHistory/executionHistory.lock and b/.gradle/9.3.1/executionHistory/executionHistory.lock differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.bin b/.gradle/9.3.1/fileHashes/fileHashes.bin index bbb97af..3db4444 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.bin and b/.gradle/9.3.1/fileHashes/fileHashes.bin differ diff --git a/.gradle/9.3.1/fileHashes/fileHashes.lock b/.gradle/9.3.1/fileHashes/fileHashes.lock index 61d6fee..d737ca8 100755 Binary files a/.gradle/9.3.1/fileHashes/fileHashes.lock and b/.gradle/9.3.1/fileHashes/fileHashes.lock differ diff --git a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin index 96cd4c2..6926026 100755 Binary files a/.gradle/9.3.1/fileHashes/resourceHashesCache.bin and b/.gradle/9.3.1/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 902cb81..28e5aea 100755 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 00232f6..796d40a 100755 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs index e479558..8e50e0f 100644 --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,13 +1,13 @@ -arguments= -auto.sync=false +arguments=--init-script /home/sherwinp/.config/VSCodium/User/globalStorage/redhat.java/1.50.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/init/init.gradle --init-script /home/sherwinp/.config/VSCodium/User/globalStorage/redhat.java/1.50.0/config_linux/org.eclipse.osgi/58/0/.cp/gradle/protobuf/init.gradle +auto.sync=true build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= -java.home= +java.home=/usr/lib/jvm/java-25-openjdk jvm.arguments= offline.mode=false -override.workspace.settings=false -show.console.view=false -show.executions.view=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/.vscode/launch.json b/.vscode/launch.json index 8c2a506..5918bb0 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,7 +23,7 @@ "name": "Linux Current File", "request": "launch", "mainClass": "edu.bookocontacts.AppSceneView", - "vmArgs": " --module-path '/home/sherwinp/workspace/javafx-sdk/lib/' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics" + "vmArgs": " --class-path .:edu.bookocontacts:edu.bookocontacts.model --module-path '/home/sherwinp/workspace/javafx-sdk/lib/' --add-modules ALL-MODULE-PATH --enable-native-access=javafx.graphics" } ] } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 95429ef..c39434f 100755 --- a/build.gradle +++ b/build.gradle @@ -66,7 +66,7 @@ tasks.named('jar') { 'Implementation-Title': group, 'Implementation-Version': 1.0, 'Main-Class': application.mainClass, - 'Class-Path': 'edu.bookocontacts javafx.base javafx.controls .' ) + 'Class-Path': '. edu.bookocontacts edu.bookocontacts.model javafx.base javafx.controls' ) } } diff --git a/db/sample.db b/db/sample.db index e69de29..d2a9158 100644 Binary files a/db/sample.db and b/db/sample.db differ diff --git a/readme.txt b/readme.txt index 17eab94..ca77a40 100644 --- a/readme.txt +++ b/readme.txt @@ -21,6 +21,27 @@ Tests with ASPECTJ: schema +------- +CREATE TABLE CONTACT( + ID NUMBER PRIMARY KEY, + FIRST_NAME TEXT, + LAST_NAME TEXT, + PHONE_NUMBER TEXT, + EMAIL_ADDRESS TEXT, + MAIL_ADDRESS TEXT +); +------- + +INSERT INTO CONTACT (ID, FIRST_NAME, LAST_NAME, PHONE_NUMBER, EMAIL_ADDRESS, MAIL_ADDRESS) +VALUES + (8,"Ramon", "Razone", "443-310-8764","Raz@home.com",NULL), + (9,"Manny", "Zonie", "443-350-6764","Zonie@home.com","7000 Hause Ln, People City,MN, 34090"), + (10,"Von", "Ray", "443-210-9764","RayVon@home.com",""); + +UPDATE CONTACT SET MAIL_ADDRESS=NULL WHERE ID=8; + + +------- CREATE TABLE contact ( contact_id NUMBER PRIMARY KEY, first_name TEXT, diff --git a/src/main/java/edu/bookocontacts/AppSceneView.java b/src/main/java/edu/bookocontacts/AppSceneView.java index 7b79ba8..3baeb05 100755 --- a/src/main/java/edu/bookocontacts/AppSceneView.java +++ b/src/main/java/edu/bookocontacts/AppSceneView.java @@ -4,6 +4,7 @@ import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; +import edu.bookocontacts.model.DATASET; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.fxml.JavaFXBuilderFactory; diff --git a/src/main/java/edu/bookocontacts/ControlDDXDialog.java b/src/main/java/edu/bookocontacts/ControlDDXDialog.java index aa7262e..b96c351 100644 --- a/src/main/java/edu/bookocontacts/ControlDDXDialog.java +++ b/src/main/java/edu/bookocontacts/ControlDDXDialog.java @@ -11,11 +11,15 @@ import javafx.scene.control.Dialog; import javafx.scene.control.TextField; import javafx.util.Callback; -import edu.bookocontacts.model.Address; +import edu.bookocontacts.model.MailAddress; import edu.bookocontacts.model.Contact; import edu.bookocontacts.model.EmailAddress; import edu.bookocontacts.model.PhoneNumber; +/** + * FXML Controller class + * + */ public class ControlDDXDialog extends Dialog { @FXML @@ -60,55 +64,51 @@ public class ControlDDXDialog extends Dialog { } private void setResultConverter() { - Logger.getLogger(getClass().getName()).log(Level.INFO, "setResultConverter called."); Callback aRC = (buttonType) -> { if (buttonType == ButtonType.OK) { if (getFirstName().isBlank() && (getEmail().isBlank() || getPhoneNo().isBlank())) { return null; } - if (getFirstName().isBlank() || getStreet().isEmpty() || getCity().isEmpty() || getState().isEmpty() - || getZip().isEmpty()) { - return null; - } return new Contact(getFirstName(), getLastName(), new EmailAddress(getEmail()), - new PhoneNumber(getPhoneNo()), new Address(getStreet(), getCity(), getState(), getZip())); + new PhoneNumber(getPhoneNo()), new MailAddress(getStreet(), getCity(), getState(), getZip())); } return null; }; setResultConverter(aRC); + Logger.getLogger(getClass().getName()).log(Level.INFO, "setResultConverter called."); } private String getFirstName() { - return ""; + return String.format( "%s", tfFirstName.getText()); } private String getLastName() { - return ""; + return String.format("%s", tfLastName.getText()); } private String getPhoneNo() { - return ""; + return String.format("%s", tfPhoneNo.getText()); } private String getEmail() { - return ""; + return String.format("%s", tfEmail.getText()); } private String getZip() { - return tfZip.getText(); + return String.format("%s", tfZip.getText()); } private String getState() { - return tfState.getText(); + return String.format("%s", tfState.getText()); } private String getCity() { - return tfCity.getText(); + return String.format("%s", tfCity.getText()); } private String getStreet() { - return tfStreet.getText(); + return String.format("%s", tfStreet.getText()); } } diff --git a/src/main/java/edu/bookocontacts/DATASET.java b/src/main/java/edu/bookocontacts/DATASET.java deleted file mode 100644 index 4d27d93..0000000 --- a/src/main/java/edu/bookocontacts/DATASET.java +++ /dev/null @@ -1,38 +0,0 @@ -package edu.bookocontacts; - -import java.io.File; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.util.ListIterator; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.sqlite.SQLiteDataSource; - -import edu.bookocontacts.model.Contact; - -public final class DATASET { - public final static ListIterator FINDDATA() { - try { - File rootDir = new File(String.format("%s", DataRepositoryConfig.getPath())); - Files.createDirectories(rootDir.toPath()); - - SQLiteDataSource dataSource = new SQLiteDataSource(); - dataSource.setUrl(String.format("jdbc:sqlite:%ssample.db", DataRepositoryConfig.getPath())); - - dataSource.getConnection(); - } catch (Exception ex) { - Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex); - } - - return null; - } - - public final static class DataRepositoryConfig { - public final static String getPath() { - String home = System.getenv("HOME") != null ? System.getenv("HOME") - : System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH"); - return home.replace('\\', '/') + "/workspace/bookocontacts/db/"; - } - } -} diff --git a/src/main/java/edu/bookocontacts/ViewController.java b/src/main/java/edu/bookocontacts/ViewController.java index 81eb11e..9ebe4ab 100755 --- a/src/main/java/edu/bookocontacts/ViewController.java +++ b/src/main/java/edu/bookocontacts/ViewController.java @@ -4,20 +4,17 @@ */ package edu.bookocontacts; -import java.util.logging.Level; -import java.util.logging.Logger; - -import edu.bookocontacts.model.Factory; -import edu.bookocontacts.model.Person; -import edu.bookocontacts.model.Address; -import edu.bookocontacts.model.PhoneNumber; -import edu.bookocontacts.model.Contact; - import java.net.URL; import java.util.Collections; import java.util.Comparator; import java.util.Optional; import java.util.ResourceBundle; +import java.util.logging.Level; +import java.util.logging.Logger; + +import edu.bookocontacts.model.Contact; +import edu.bookocontacts.model.Factory; +import edu.bookocontacts.model.PhoneNumber; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -27,12 +24,9 @@ import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.Pagination; import javafx.scene.control.TableColumn; -import javafx.scene.control.TableColumn.SortType; import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.control.cell.PropertyValueFactory; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; /** * FXML Controller class @@ -43,29 +37,29 @@ public class ViewController implements Initializable { Logger logger = Logger.getLogger(getClass().getName()); @FXML - private TableView personView = new TableView<>(); + private TableView contactView = new TableView<>(); @FXML - private TableColumn personViewIdCol; + private TableColumn contactViewIdCol; @FXML - private TableColumn personViewNameCol; + private TableColumn contactViewNameCol; @FXML - private TableColumn personViewPhoneNoCol; + private TableColumn contactViewPhoneNoCol; @FXML Pagination pagination; @FXML - private Button save; - - private Button id = new Button("ID"); - - private ImageView upImg = new ImageView(new Image("/media/up.png")); - private ImageView downImg = new ImageView(new Image("/media/down.png")); + private Button btnAdd; + @FXML + private Button btnDel; + @FXML + private Button btnSrch; + @FXML + private TextField txtSrch; private ObservableList contacts = null; private int pageCount = 5; private int itemsPerPage = 4; private int currentPageIndex = 0; - private boolean order = true; private void log(String message) { logger.log(Level.INFO, message); @@ -76,8 +70,11 @@ public class ViewController implements Initializable { */ public void initialize(URL location, ResourceBundle resources) { log("initialize"); + btnSrch.setDisable(true); + txtSrch.setDisable(true); + contacts = FXCollections.observableArrayList(Factory.getAll(new Contact())); - log(String.format("Person size: %d", contacts.size())); + log(String.format("Contact List size: %d", contacts.size())); sort(); initializeTable(); @@ -89,13 +86,17 @@ public class ViewController implements Initializable { pagination.currentPageIndexProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Number oldValue, Number newValue) { - log("Pagination Changed from " + oldValue + " , to " + newValue); + log(String.format("Pagination Changed from %d to %d", oldValue, newValue)); currentPageIndex = newValue.intValue(); - updatePersonView(); + try { + updatecontactView(); + } catch (IllegalArgumentException ex) { + log(ex.getMessage()); + } } }); - save.setOnAction(new javafx.event.EventHandler() { + btnAdd.setOnAction(new javafx.event.EventHandler() { @Override public void handle(javafx.event.ActionEvent t) { @@ -106,33 +107,53 @@ public class ViewController implements Initializable { if (result.isPresent()) { log("result is present."); // add to storage - // contacts.add((Address) result.get()); - // bind to model - // tvInventory.refresh(); - // - // sort(); - // updatePersonView(); - + Contact ct = (Contact) result.get(); + ct.setId(contacts.size()); + contacts.add(ct); + try { + ct.save(); + } catch (Exception ex) { + log(ex.getMessage()); + } + updatecontactView(); } } }); - id.setOnAction(new javafx.event.EventHandler() { + btnDel.setOnAction(new javafx.event.EventHandler() { @Override public void handle(javafx.event.ActionEvent t) { - sort(); - if (order) { - Collections.reverse(contacts); + Contact ct = contactView.getSelectionModel().getSelectedItem(); + log(String.format("%s", ct)); + contacts.remove(ct); + pagination.setPageCount(getPageCount(contacts.size(), itemsPerPage)); + try { + // delete from storage + ct.markDeleted(); + ct.save(); + } catch (Exception ex) { + log(ex.getMessage()); } - log(" order = " + order + "; data = " + contacts); - order = !order; - id.setGraphic((order) ? upImg : downImg); - updatePersonView(); - log(" comparator called"); + updatecontactView(); } }); } + private void initializeTable() { + + contactViewIdCol.setCellValueFactory(new PropertyValueFactory("Id")); + contactViewNameCol.setCellValueFactory(new PropertyValueFactory("Name")); + + contactViewPhoneNoCol.setCellValueFactory(new PropertyValueFactory("PhoneNo")); + contactViewPhoneNoCol.setSortable(false); + + if (contacts.size() < itemsPerPage) { + contactView.getItems().setAll(contacts.subList(0, contacts.size())); + } else { + contactView.getItems().setAll(contacts.subList(0, itemsPerPage)); + } + } + private void sort() { Collections.sort(contacts, new Comparator() { @Override @@ -143,35 +164,15 @@ public class ViewController implements Initializable { }); } - public void updatePersonView() { + public void updatecontactView() throws IllegalArgumentException { log("update View"); - personView.getItems() + contactView.getItems() .setAll(contacts.subList(currentPageIndex * itemsPerPage, ((currentPageIndex * itemsPerPage + itemsPerPage <= contacts.size()) ? currentPageIndex * itemsPerPage + itemsPerPage : contacts.size()))); } - private void initializeTable() { - personViewIdCol.setCellValueFactory(new PropertyValueFactory("Id")); - id.setGraphic(upImg); - personViewIdCol.setGraphic(id); - personViewIdCol.setSortable(false); - personViewNameCol.setCellValueFactory(new PropertyValueFactory("Name")); - personViewNameCol.sortTypeProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue paramObservableValue, SortType paramT1, - SortType paramT2) { - log("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); - id.setGraphic(null); - } - }); - personViewPhoneNoCol.setCellValueFactory(new PropertyValueFactory("PhoneNo")); - personViewPhoneNoCol.setText("PhoneNo"); - personViewPhoneNoCol.setSortable(false); - personView.getItems().setAll(contacts.subList(0, itemsPerPage)); - } - public int getItemsPerPage() { return itemsPerPage; } diff --git a/src/main/java/edu/bookocontacts/model/Contact.java b/src/main/java/edu/bookocontacts/model/Contact.java index 2d858d8..f8e015f 100644 --- a/src/main/java/edu/bookocontacts/model/Contact.java +++ b/src/main/java/edu/bookocontacts/model/Contact.java @@ -12,7 +12,8 @@ public class Contact { private String last_name = null; private PhoneNumber phone_number; private EmailAddress email_address; - private Address mailing_address; + private MailAddress mailing_address; + EnumStatus status = EnumStatus.STORED; public Contact() { this("", ""); @@ -24,7 +25,7 @@ public class Contact { } public Contact(String first_name, String last_name, EmailAddress email_address, PhoneNumber phone_number, - Address mailing_address) + MailAddress mailing_address) throws IllegalArgumentException { this.phone_number = phone_number; this.mailing_address = mailing_address; @@ -33,8 +34,9 @@ public class Contact { this.first_name = first_name; this.last_name = last_name; - if (this.first_name==null && (email_address.isBlank() || phone_number.isBlank())){ - throw new IllegalArgumentException(String.format("%s %s", "Contact: requires Phone Number or Email Address")); + if (this.first_name == null && (email_address.isBlank() || phone_number.isBlank())) { + throw new IllegalArgumentException( + String.format("%s %s", "Contact: requires Phone Number or Email Address")); } this.phone_number = phone_number; @@ -42,7 +44,7 @@ public class Contact { this.email_address = email_address; } - public Contact(PhoneNumber phone_number, Address mailing_address, EmailAddress email_address) + public Contact(PhoneNumber phone_number, MailAddress mailing_address, EmailAddress email_address) throws IllegalArgumentException { this.phone_number = phone_number; this.mailing_address = mailing_address; @@ -76,16 +78,20 @@ public class Contact { public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("{ \"Account\":{"); - sb.append("\"account_number\": \"").append(id).append("\","); + sb.append("{\"id\": \"").append(id).append("\","); sb.append("\"phone_number\": \"").append(phone_number).append("\","); - sb.append("\"mailing_address\": ").append(mailing_address).append(","); sb.append("\"email_address\": ").append(email_address).append(","); - sb.append("}}"); + sb.append("}"); return sb.toString(); } - public static void Write(Contact acct) throws IOException { + public void save() throws IOException { + Factory.save(this); + this.status = EnumStatus.STORED; + } + + public void markDeleted() { + this.status = EnumStatus.DELETED; } public Integer getId() { @@ -124,11 +130,11 @@ public class Contact { this.phone_number = phone_number; } - public Address getMailing_address() { + public MailAddress getMailing_address() { return mailing_address; } - public void setMailing_address(Address mailing_address) { + public void setMailing_address(MailAddress mailing_address) { this.mailing_address = mailing_address; } diff --git a/src/main/java/edu/bookocontacts/model/DATASET.java b/src/main/java/edu/bookocontacts/model/DATASET.java new file mode 100644 index 0000000..50eb400 --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/DATASET.java @@ -0,0 +1,105 @@ +package edu.bookocontacts.model; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.sqlite.SQLiteDataSource; + +public interface DATASET { + public static PreparedStatement getPreparedStatement(String sql) throws SQLException, IOException { + File rootDir = new File(String.format("%s", DataRepositoryConfig.getPath())); + Files.createDirectories(rootDir.toPath()); + + SQLiteDataSource dataSource = new SQLiteDataSource(); + dataSource.setUrl(String.format("jdbc:sqlite:%ssample.db", DataRepositoryConfig.getPath())); + return dataSource.getConnection().prepareStatement(sql); + } + + public static List FINDDATA() { + ArrayList list = new ArrayList(); + try { + PreparedStatement stmt = getPreparedStatement(String.format( + "SELECT ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS FROM CONTACT;")); + ResultSet rs = stmt.executeQuery(); + + while (rs.next()) { + Contact ct = Factory.createContact(rs.getInt("ID"), + rs.getString("FIRST_NAME"), + rs.getString("LAST_NAME"), + new EmailAddress(rs.getString("EMAIL_ADDRESS")), + new PhoneNumber(rs.getString("PHONE_NUMBER"))); + ct.status = EnumStatus.STORED; + list.add(ct); + } + + } catch (Exception ex) { + Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex); + } + return list; + } + + public interface DataRepositoryConfig { + public static String getPath() { + String home = System.getenv("HOME") != null ? System.getenv("HOME") + : System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH"); + return home.replace('\\', '/') + "/workspace/bookocontacts/db/"; + } + } + + public static void UPDATESERT(Contact ct) { + try { + PreparedStatement stmt = getPreparedStatement(String.format( + "SELECT ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS FROM CONTACT WHERE ID=?;")); + stmt.setInt(1, ct.getId()); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + stmt.close(); + stmt = getPreparedStatement(String.format( + "UPDATE CONTACT SET FIRST_NAME=?, LAST_NAME=?, EMAIL_ADDRESS=?, PHONE_NUMBER=?, MAIL_ADDRESS=? WHERE ID=?;")); + stmt.setString(1, ct.getFirst_name()); + stmt.setString(2, ct.getLast_name()); + stmt.setString(3, ct.getEmail().getEmail_address()); + stmt.setString(4, ct.getPhoneNo().getphone_number()); + stmt.setString(5, ct.getMailing_address().getMailingAddress()); + stmt.setInt(6, ct.getId()); + stmt.execute(); + stmt.close(); + } else { + stmt.close(); + stmt = getPreparedStatement(String.format( + "INSERT INTO CONTACT(ID, FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, PHONE_NUMBER, MAIL_ADDRESS) " + + "VALUES(?,?,?,?,?,?);")); + stmt.setInt(1, ct.getId()); + stmt.setString(2, ct.getFirst_name()); + stmt.setString(3, ct.getLast_name()); + stmt.setString(4, ct.getEmail().getEmail_address()); + stmt.setString(5, ct.getPhoneNo().getphone_number()); + stmt.setString(6, ct.getMailing_address().getMailingAddress()); + stmt.execute(); + stmt.close(); + } + } catch (Exception ex) { + Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex); + } + } + + static void DELETE(Contact ct){ + try { + PreparedStatement stmt = getPreparedStatement(String.format( + "DELETE FROM CONTACT WHERE ID=?;")); + stmt.setInt(1, ct.getId()); + stmt.execute(); + stmt.close(); + } catch (Exception ex) { + Logger.getLogger(DATASET.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/src/main/java/edu/bookocontacts/model/EmailAddress.java b/src/main/java/edu/bookocontacts/model/EmailAddress.java index 95705ac..d022dc7 100644 --- a/src/main/java/edu/bookocontacts/model/EmailAddress.java +++ b/src/main/java/edu/bookocontacts/model/EmailAddress.java @@ -2,8 +2,15 @@ package edu.bookocontacts.model; public class EmailAddress{ String email_address; - + public EmailAddress(){ + this(""); + } + public EmailAddress(String email_address) { + if (email_address == null) { + email_address = ""; + return; + } this.email_address = email_address; } @@ -43,15 +50,14 @@ public class EmailAddress{ @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("{ \"EmailAddress\":{"); - sb.append("\"email\": \"" + email_address + "\""); - sb.append("}}"); + + sb.append("{\"email\": \"" + email_address + "\""); + sb.append("}"); return sb.toString(); } public boolean isBlank() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'isBlank'"); + return this.email_address == null || this.email_address.isBlank(); } } diff --git a/src/main/java/edu/bookocontacts/model/EnumStatus.java b/src/main/java/edu/bookocontacts/model/EnumStatus.java new file mode 100644 index 0000000..cf0f340 --- /dev/null +++ b/src/main/java/edu/bookocontacts/model/EnumStatus.java @@ -0,0 +1,5 @@ +package edu.bookocontacts.model; + +public enum EnumStatus { + STORED,NEW,DELETED; +} diff --git a/src/main/java/edu/bookocontacts/model/Factory.java b/src/main/java/edu/bookocontacts/model/Factory.java index 2d35951..f76550e 100755 --- a/src/main/java/edu/bookocontacts/model/Factory.java +++ b/src/main/java/edu/bookocontacts/model/Factory.java @@ -4,62 +4,32 @@ */ package edu.bookocontacts.model; -import java.util.ArrayList; +import java.io.IOException; import java.util.List; /** * */ -public class Factory { - static int id=0; - - public static List getAll(Person clazz){ - return getAllPersons(); +public interface Factory { + public static List getAll(Contact clazz) { + return DATASET.FINDDATA(); } - public static List getAll(Contact clazz){ - return getAllContacts(); - } - - public static List getAllPersons() { - ArrayList list = new ArrayList<>(); - list.add(createPerson("John", 40)); - list.add(createPerson("Daisy", 21)); - list.add(createPerson("Martha", 34)); - list.add(createPerson("Frodo", 16)); - list.add(createPerson("Mickey", 22)); - list.add(createPerson("Minnie", 19)); - list.add(createPerson("Donald", 30)); - list.add(createPerson("Goofy", 32)); - list.add(createPerson("Pokoyo", 12)); - list.add(createPerson("Dora", 16)); - list.add(createPerson("Tintin", 25)); - list.add(createPerson("John", 52)); - list.add(createPerson("Daisy", 29)); - list.add(createPerson("Martha Has a very Long Name", 18)); - return list; - } - - static Person createPerson(String _name, int _age) { - return new Person(Integer.toString(id++),_name, _age); - } - - public static List getAllContacts() { - ArrayList list = new ArrayList<>(); - list.add(createContact(1, "Jose", "Cezone", "cezon50@yahoo.com", "410-456-9876")); - list.add(createContact(2,"Jack", "Bolt", "jbolt100@hotmail.com", "443-266-9776")); - list.add(createContact(3,"David", "Rossi", null, "210-356-9876")); - list.add(createContact(4, "Sheila", "Philster", null, "410-356-5876")); - list.add(createContact(5, "Adam", "Zhaine", null, "410-456-1876")); - list.add(createContact(6, "Amanda", "Kelstone", null, "410-456-2876")); - - return list; - } - - static Contact createContact(Integer id, String first_name, String last_name, String email, String phone_number) { - Contact c = new Contact(first_name, last_name, new EmailAddress(email), new PhoneNumber(phone_number), (Address)null); + static Contact createContact(Integer id, String first_name, String last_name, EmailAddress email, + PhoneNumber phone_number) { + Contact c = new Contact(first_name, last_name, email, phone_number, new MailAddress()); c.setId(id); + return c; } + public static Contact save(final Contact ct) throws IOException { + if(ct.status==EnumStatus.DELETED){ + DATASET.DELETE(ct); + }else{ + DATASET.UPDATESERT(ct); + } + return ct; + } + } diff --git a/src/main/java/edu/bookocontacts/model/Address.java b/src/main/java/edu/bookocontacts/model/MailAddress.java similarity index 67% rename from src/main/java/edu/bookocontacts/model/Address.java rename to src/main/java/edu/bookocontacts/model/MailAddress.java index 8d7e86c..a23da52 100644 --- a/src/main/java/edu/bookocontacts/model/Address.java +++ b/src/main/java/edu/bookocontacts/model/MailAddress.java @@ -1,16 +1,17 @@ package edu.bookocontacts.model; -public final class Address{ +public final class MailAddress{ String street; String city; String state; String zip; - public Address() { + public MailAddress() { + this("", "", "", ""); } - public Address(String street, String city, String state, String zip) { + public MailAddress(String street, String city, String state, String zip) { this.street = street; this.city = city; this.state = state; @@ -49,14 +50,22 @@ public final class Address{ this.zip = zip; } + public String getMailingAddress(){ + return String.format( "%s %s %s %s", formatField(this.street), formatField(this.city), this.state, this.zip ); + } + + private String formatField(String field){ + return field == null || field.isBlank()? "": field.trim() + ","; + } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((street == null) ? 0 : street.hashCode()); - result = prime * result + ((city == null) ? 0 : city.hashCode()); - result = prime * result + ((state == null) ? 0 : state.hashCode()); - result = prime * result + ((zip == null) ? 0 : zip.hashCode()); + result = prime * result + ((street.isBlank()) ? 0 : street.hashCode()); + result = prime * result + ((city.isBlank()) ? 0 : city.hashCode()); + result = prime * result + ((state.isBlank()) ? 0 : state.hashCode()); + result = prime * result + ((zip.isBlank()) ? 0 : zip.hashCode()); return result; } @@ -68,7 +77,7 @@ public final class Address{ return false; if (getClass() != obj.getClass()) return false; - Address other = (Address) obj; + MailAddress other = (MailAddress) obj; if (street == null) { if (other.street != null) return false; @@ -95,7 +104,7 @@ public final class Address{ @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("{ \"Address\":{"); + sb.append("{ \"MailAddress\":{"); sb.append("\"street\": \"" + street + "\","); sb.append("\"city\": \"" + city + "\","); sb.append("\"state\": \"" + state + "\","); @@ -103,4 +112,15 @@ public final class Address{ sb.append("}}"); return sb.toString(); } + + public Boolean isBlank() { + + if(street.isBlank() && city.isBlank() && state.isBlank()) { + return true; + } + if( zip == null || zip.isBlank() ) { + return true; + } + return false; + } } \ No newline at end of file diff --git a/src/main/java/edu/bookocontacts/model/Person.java b/src/main/java/edu/bookocontacts/model/Person.java deleted file mode 100755 index 930c91c..0000000 --- a/src/main/java/edu/bookocontacts/model/Person.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package edu.bookocontacts.model; - -/** - * - */ -public class Person { - String Id; String Name; int Age; - - public Person(final String Id, final String Name, final int Age) { - this.Id=Id; - this.Name = Name; - this.Age = Age; - } - - public Person() { - this("", "", 0); - } - - public String getId() { - return Id; - } - - public void setId(final String id) { - Id = id; - } - - public String getName() { - return Name; - } - - public void setName(final String name) { - Name = name; - } - - public int getAge() { - return Age; - } - - public void setAge(final int age) { - Age = age; - } - -} \ No newline at end of file diff --git a/src/main/resources/media/ControlAddressDDXDialog.fxml b/src/main/resources/media/ControlAddressDDXDialog.fxml index 97fec28..bc5f94f 100644 --- a/src/main/resources/media/ControlAddressDDXDialog.fxml +++ b/src/main/resources/media/ControlAddressDDXDialog.fxml @@ -29,30 +29,30 @@ diff --git a/src/main/resources/media/TableView.fxml b/src/main/resources/media/TableView.fxml index 7185c3a..7bce109 100755 --- a/src/main/resources/media/TableView.fxml +++ b/src/main/resources/media/TableView.fxml @@ -12,25 +12,25 @@ - + - - - + + + - + - + -