]> git.mxchange.org Git - addressbook-swing.git/blobdiff - src/org/mxchange/addressbook/facade/contact/AddressbookContactFacade.java
using gender for Mr./Mrs. is plain wrong, now "personal title" and "academic
[addressbook-swing.git] / src / org / mxchange / addressbook / facade / contact / AddressbookContactFacade.java
index b6635e613a36ca68e394b7529fee46872b4d7a0b..74d3653cc1d83676246004085a41a78e0cec8eb0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Roland Haeder
+ * Copyright (C) 2016, 2017 Roland Häder
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,26 +23,24 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
 import org.mxchange.addressbook.client.AddressbookClient;
 import org.mxchange.jcontacts.contact.Contact;
-import org.mxchange.jcontacts.contact.gender.Gender;
-import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcontacts.contact.title.PersonalTitle;
+import org.mxchange.jcontactsbusiness.exceptions.BusinessContactAlreadyAddedException;
 import org.mxchange.jcore.client.Client;
 import org.mxchange.jcore.exceptions.UnhandledUserChoiceException;
 import org.mxchange.jcore.facade.BaseFacade;
 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 import org.mxchange.jcountry.data.Country;
-import org.mxchange.jphone.phonenumbers.cellphone.DialableCellphoneNumber;
 import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
 
 /**
  * A facade for contacts.
  * <p>
- * @author Roland Haeder
+ * @author Roland Häder<roland@mxchange.org>
  * @version 0.0
  */
 public class AddressbookContactFacade extends BaseFacade implements ContactFacade {
@@ -52,17 +50,11 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         */
        private final List<String> columnNames;
 
-       /**
-        * Entity manager
-        */
-       @PersistenceContext
-       private EntityManager entityManager;
-
        /**
         * Logger instance
         */
        @Log
-       private LoggerBeanLocal logger;
+       private LoggerBeanLocal loggerBeanLocal;
 
        /**
         * Translated column name list
@@ -79,7 +71,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         */
        public AddressbookContactFacade (final Client client) throws SQLException {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("client={1} - CALLED!", client)); //NOI18N
 
                // Make sure all parameters are set correctly
                if (null == client) {
@@ -102,9 +94,9 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        }
 
        @Override
-       public void addContact (final Contact contact) throws ContactAlreadyAddedException {
+       public void addContact (final Contact contact) throws BusinessContactAlreadyAddedException {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - CALLED!", contact)); //NOI18N
 
                // Contact instance must not be null
                if (null == contact) {
@@ -116,7 +108,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                this.entityManager.persist(contact);
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -127,7 +119,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public void doChangeAddressData (final Contact contact) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -155,13 +147,13 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doChangeNameData (final Contact contact) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -185,7 +177,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -196,7 +188,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public void doChangeOtherData (final Contact contact) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Contact must not be null
                if (null == contact) {
@@ -220,13 +212,13 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
        public void doChangeOwnData () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                /*
                 * First check if the user has registered own contact, before that
@@ -256,11 +248,11 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                        // Ask user what to change
                        client.userChooseChangeContactData(contact);
                } catch (final UnhandledUserChoiceException ex) {
-                       this.getLogger().logException(ex);
+                       this.getLoggerBeanLocal().logException(ex);
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -269,14 +261,14 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        }
 
        @Override
-       public void doEnterOwnData () throws ContactAlreadyAddedException {
+       public void doEnterOwnData () throws BusinessContactAlreadyAddedException {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Is own contact already added?
                if (this.isOwnContactAdded()) {
                        // Don't continue here
-                       throw new ContactAlreadyAddedException();
+                       throw new BusinessContactAlreadyAddedException();
                }
 
                // Get and cast client instance
@@ -292,7 +284,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -308,19 +300,19 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public void doShutdown () throws SQLException, IOException {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Shut down the database layer
                this.entityManager.close();
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        @Override
-       public DialableCellphoneNumber enterOwnCellNumber () {
+       public DialableMobileNumber enterOwnCellNumber () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -331,7 +323,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnCity () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -342,7 +334,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnComment () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -353,7 +345,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnCompanyName () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -364,7 +356,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public Country enterOwnCountryCode () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -375,7 +367,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnEmailAddress () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -386,7 +378,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnFamilyName () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -397,7 +389,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public DialableFaxNumber enterOwnFaxNumber () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -408,7 +400,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnFirstName () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -417,20 +409,20 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        }
 
        @Override
-       public Gender enterOwnGender () {
+       public PersonalTitle enterOwnPersonalTitle () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
 
-               return client.enterGender("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
+               return client.enterPersonalTitle("Bitte geben Sie die Anrede ein: (M=Herr, F=Frau, C=Firma): ");
        }
 
        @Override
        public DialableLandLineNumber enterOwnPhoneNumber () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -441,7 +433,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public String enterOwnStreet () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -452,7 +444,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public int enterOwnZipCode () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Get and cast client instance
                AddressbookClient client = (AddressbookClient) this.getClient();
@@ -486,19 +478,19 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("rowIndex={0},columnIndex={1} CALLED!", rowIndex, columnIndex)); //NOI18N
 
                // Convert column index -> name
                String columnName = this.getColumnName(columnIndex);
 
                // Debug message
-               this.getLogger().logDebug(MessageFormat.format("columnName={0}", columnName)); //NOI18N
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("columnName={0}", columnName)); //NOI18N
 
                // Init value
                Object value = null;
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("value={0} - EXIT!", value)); //NOI18N
 
                // Return it
                return value;
@@ -507,13 +499,13 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public boolean isOwnContactAdded () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Init variable
                boolean isAdded = false;
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
 
                // Return result
                return isAdded;
@@ -522,7 +514,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
        @Override
        public void registerContact (final Contact contact) {
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} CALLED!", contact)); //NOI18N
 
                // Sanity check
                if (null == contact) {
@@ -541,13 +533,13 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
 
                        // Add contact to internal list
                        this.addContact(contact);
-               } catch (final ContactAlreadyAddedException ex) {
+               } catch (final BusinessContactAlreadyAddedException ex) {
                        // Abort here
                        this.abortProgramWithException(ex);
                }
 
                // Trace message
-               this.getLogger().logTrace("EXIT!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("EXIT!"); //NOI18N
        }
 
        /**
@@ -571,7 +563,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                assert (this.translatedColumnNames instanceof List) : "this.translatedColumnNames is not initialized"; //NOI18N
 
                // Debug message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // First get an iterator from key set to iterate over
                Iterator<String> iterator = this.getBundle().keySet().iterator();
@@ -584,7 +576,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                        // Does the key start with AddressbookContactFacade.columnName ?
                        if (key.startsWith("ContactManager.columnName")) { //NOI18N
                                // This is the wanted entry.
-                               this.getLogger().logDebug(MessageFormat.format("key={0}", key)); //NOI18N
+                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("key={0}", key)); //NOI18N
 
                                // Convert string to array based on delimiter '.'
                                String[] tokens = this.getArrayFromString(key, "."); //NOI18N
@@ -596,7 +588,7 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                                String columnName = tokens[tokens.length - 2];
 
                                // Debug message
-                               this.getLogger().logDebug(MessageFormat.format("columnName={0} - adding ...", columnName)); //NOI18N
+                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("columnName={0} - adding ...", columnName)); //NOI18N
 
                                // So add it
                                this.columnNames.add(columnName);
@@ -605,16 +597,16 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
                }
 
                // Debug message
-               this.getLogger().logTrace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getColumnCount()={0}: EXIT!", this.getColumnCount())); //NOI18N
        }
 
        /**
-        * Getter for logger instance
+        * Getter for loggerBeanLocal instance
         * <p>
         * @return Logger instance
         */
-       private LoggerBeanLocal getLogger () {
-               return this.logger;
+       private LoggerBeanLocal getLoggerBeanLocal () {
+               return this.loggerBeanLocal;
        }
 
        /**
@@ -624,14 +616,14 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         */
        private Contact getOwnContact () {
                // Trace message
-               this.getLogger().logTrace("CALLED!"); //NOI18N
+               this.getLoggerBeanLocal().logTrace("CALLED!"); //NOI18N
 
                // Deligate this call to database frontend
                Contact contact = null;
                //Contact contact = ((AddressbookContactFrontend) this.getFrontend()).getOwnContact();
 
                // Trace message
-               this.getLogger().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("contact={0} - EXIT!", contact)); //NOI18N
 
                // Return instance or null
                return contact;
@@ -643,6 +635,6 @@ public class AddressbookContactFacade extends BaseFacade implements ContactFacad
         * @param exception Throwable
         */
        protected void logException (final Throwable exception) {
-               this.getLogger().logException(exception);
+               this.getLoggerBeanLocal().logException(exception);
        }
 }