]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/phone/JobsPhoneWebRequestBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / phone / JobsPhoneWebRequestBean.java
index ec3188407074c5b3643c7ef67d710a78a6e5b90e..316f2ae94afbb7b8abd51e3d5ccf6c29ac1cd477 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -42,6 +42,7 @@ import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEve
 import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
 import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
 import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
@@ -254,25 +255,25 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                        throw new NullPointerException("event is null"); //NOI18N
                } else if (event.getContact() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact is null");
+                       throw new NullPointerException("event.contact is null"); //NOI18N
                } else if (event.getContact().getContactId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId is null");
+                       throw new NullPointerException("event.contact.contactId is null"); //NOI18N
                } else if (event.getContact().getContactId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
                } else if (event.getContact().getContactFaxNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactFaxNumber is null");
+                       throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N
                } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null");
+                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N
                } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid"); //NOI18N
                } else if (event.getLinkedFaxNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.linkedFaxNumer is null");
+                       throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N
                }
 
                // Is the id number in linked number not set?
@@ -295,25 +296,25 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                        throw new NullPointerException("event is null"); //NOI18N
                } else if (event.getContact() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact is null");
+                       throw new NullPointerException("event.contact is null"); //NOI18N
                } else if (event.getContact().getContactId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId is null");
+                       throw new NullPointerException("event.contact.contactId is null"); //NOI18N
                } else if (event.getContact().getContactId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
                } else if (event.getContact().getContactLandLineNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactLandLineNumber is null");
+                       throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N
                } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null");
+                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N
                } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid"); //NOI18N
                } else if (event.getLinkedLandLineNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.linkedLandLineNumer is null");
+                       throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N
                }
 
                // Is the id number in linked number not set?
@@ -336,25 +337,25 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                        throw new NullPointerException("event is null"); //NOI18N
                } else if (event.getContact() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact is null");
+                       throw new NullPointerException("event.contact is null"); //NOI18N
                } else if (event.getContact().getContactId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId is null");
+                       throw new NullPointerException("event.contact.contactId is null"); //NOI18N
                } else if (event.getContact().getContactId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid"); //NOI18N
                } else if (event.getContact().getContactMobileNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactMobileNumber is null");
+                       throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N
                } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null");
+                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null"); //NOI18N
                } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
                        // Throw again ...
-                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid");
+                       throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid"); //NOI18N
                } else if (event.getLinkedMobileNumber() == null) {
                        // Throw again ...
-                       throw new NullPointerException("event.linkedMobileNumer is null");
+                       throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N
                }
 
                // Is the id number in linked number not set?
@@ -546,6 +547,69 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                return list;
        }
 
+       @Override
+       public DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException {
+               // Validate paramter
+               if (null == faxNumberId) {
+                       // Throw NPE
+                       throw new NullPointerException("faxNumberId is null"); //NOI18N
+               } else if (faxNumberId < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("faxNumberId=" + faxNumberId + " is invalid."); //NOI18N
+               } else if (!this.faxNumberCache.containsKey(faxNumberId)) {
+                       // Not found
+                       throw new PhoneEntityNotFoundException(faxNumberId);
+               }
+
+               // Get it from cache
+               final DialableFaxNumber faxNumber = this.faxNumberCache.get(faxNumberId);
+
+               // Return it
+               return faxNumber;
+       }
+
+       @Override
+       public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
+               // Validate paramter
+               if (null == landLineNumberId) {
+                       // Throw NPE
+                       throw new NullPointerException("landLineNumberId is null"); //NOI18N
+               } else if (landLineNumberId < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("landLineNumberId=" + landLineNumberId + " is invalid."); //NOI18N
+               } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) {
+                       // Not found
+                       throw new PhoneEntityNotFoundException(landLineNumberId);
+               }
+
+               // Get it from cache
+               final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId);
+
+               // Return it
+               return landLineNumber;
+       }
+
+       @Override
+       public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws PhoneEntityNotFoundException {
+               // Validate paramter
+               if (null == mobileNumberId) {
+                       // Throw NPE
+                       throw new NullPointerException("mobileNumberId is null"); //NOI18N
+               } else if (mobileNumberId < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException("mobileNumberId=" + mobileNumberId + " is invalid."); //NOI18N
+               } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) {
+                       // Not found
+                       throw new PhoneEntityNotFoundException(mobileNumberId);
+               }
+
+               // Get it from cache
+               final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId);
+
+               // Return it
+               return mobileNumber;
+       }
+
        /**
         * Post-construction method
         */
@@ -554,45 +618,36 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                // Is cache there?
                if (!this.faxNumberCache.iterator().hasNext()) {
                        // Get whole list
-                       final List<DialableFaxNumber> list = this.phoneBean.allFaxNumbers();
+                       final List<DialableFaxNumber> faxNumbers = this.phoneBean.allFaxNumbers();
 
                        // Add all
-                       for (final Iterator<DialableFaxNumber> iterator = list.iterator(); iterator.hasNext();) {
-                               // Get next element
-                               final DialableFaxNumber next = iterator.next();
-
+                       for (final DialableFaxNumber faxNumber : faxNumbers) {
                                // Add it to cache
-                               this.faxNumberCache.put(next.getPhoneId(), next);
+                               this.faxNumberCache.put(faxNumber.getPhoneId(), faxNumber);
                        }
                }
 
                // Is cache there?
                if (!this.landLineNumberCache.iterator().hasNext()) {
                        // Get whole list
-                       final List<DialableLandLineNumber> list = this.phoneBean.allLandLineNumbers();
+                       final List<DialableLandLineNumber> lineNumbers = this.phoneBean.allLandLineNumbers();
 
                        // Add all
-                       for (final Iterator<DialableLandLineNumber> iterator = list.iterator(); iterator.hasNext();) {
-                               // Get next element
-                               final DialableLandLineNumber next = iterator.next();
-
+                       for (final DialableLandLineNumber lineNumber : lineNumbers) {
                                // Add it to cache
-                               this.landLineNumberCache.put(next.getPhoneId(), next);
+                               this.landLineNumberCache.put(lineNumber.getPhoneId(), lineNumber);
                        }
                }
 
                // Is cache there?
                if (!this.mobileNumberCache.iterator().hasNext()) {
                        // Get whole list
-                       final List<DialableMobileNumber> list = this.phoneBean.allMobileNumbers();
+                       final List<DialableMobileNumber> mobileNumbers = this.phoneBean.allMobileNumbers();
 
                        // Add all
-                       for (final Iterator<DialableMobileNumber> iterator = list.iterator(); iterator.hasNext();) {
-                               // Get next element
-                               final DialableMobileNumber next = iterator.next();
-
+                       for (final DialableMobileNumber mobileNumber : mobileNumbers) {
                                // Add it to cache
-                               this.mobileNumberCache.put(next.getPhoneId(), next);
+                               this.mobileNumberCache.put(mobileNumber.getPhoneId(), mobileNumber);
                        }
                }
        }
@@ -614,13 +669,13 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                // Make sure the parameter is valid
                if (null == faxNumber) {
                        // Throw NPE
-                       throw new NullPointerException("faxNumber is null");
+                       throw new NullPointerException("faxNumber is null"); //NOI18N
                } else if (faxNumber.getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("faxNumber.phoneId is null");
+                       throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
                } else if (faxNumber.getPhoneId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId()));
+                       throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N
                }
 
                // First remove it
@@ -650,13 +705,13 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                // Make sure the parameter is valid
                if (null == landLineNumber) {
                        // Throw NPE
-                       throw new NullPointerException("landLineNumber is null");
+                       throw new NullPointerException("landLineNumber is null"); //NOI18N
                } else if (landLineNumber.getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("landLineNumber.phoneId is null");
+                       throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
                } else if (landLineNumber.getPhoneId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId()));
+                       throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N
                }
 
                // First remove it
@@ -686,13 +741,13 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                // Make sure the parameter is valid
                if (null == mobileNumber) {
                        // Throw NPE
-                       throw new NullPointerException("mobileNumber is null");
+                       throw new NullPointerException("mobileNumber is null"); //NOI18N
                } else if (mobileNumber.getPhoneId() == null) {
                        // Throw again ...
-                       throw new NullPointerException("mobileNumber.phoneId is null");
+                       throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
                } else if (mobileNumber.getPhoneId() < 1) {
                        // Not valid
-                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId()));
+                       throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId())); //NOI18N
                }
 
                // First remove it by object
@@ -721,10 +776,10 @@ public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWe
                // Parameter must be valid
                if (null == contact) {
                        // Throw NPE
-                       throw new NullPointerException("contact is null");
+                       throw new NullPointerException("contact is null"); //NOI18N
                } else if (contact.getContactId() == null) {
                        // Throw again
-                       throw new NullPointerException("contact.contactId is null");
+                       throw new NullPointerException("contact.contactId is null"); //NOI18N
                } else if (contact.getContactId() < 1) {
                        // Id number is not valid
                }