/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2020 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
import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jjobs.beans.BaseJobsBean;
import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
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;
*/
@Named ("phoneController")
@RequestScoped
-public class JobsPhoneWebRequestBean extends BaseJobsController implements JobsPhoneWebRequestController {
+public class JobsPhoneWebRequestBean extends BaseJobsBean implements JobsPhoneWebRequestController {
/**
* Serial number
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?
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?
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?
// Init list
final List<DialableFaxNumber> list = new LinkedList<>();
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableFaxNumber>> iterator = this.faxNumberCache.iterator();
-
// Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableFaxNumber> next = iterator.next();
-
+ for (final Cache.Entry<Long, DialableFaxNumber> currentEntry : this.faxNumberCache) {
// Add value to list
- list.add(next.getValue());
+ list.add(currentEntry.getValue());
}
// Return it
// Init list
final List<DialableLandLineNumber> list = new LinkedList<>();
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableLandLineNumber>> iterator = this.landLineNumberCache.iterator();
-
// Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableLandLineNumber> next = iterator.next();
-
+ for (final Cache.Entry<Long, DialableLandLineNumber> currentEntry : this.landLineNumberCache) {
// Add value to list
- list.add(next.getValue());
+ list.add(currentEntry.getValue());
}
// Return it
// Init list
final List<DialableMobileNumber> list = new LinkedList<>();
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableMobileNumber>> iterator = this.mobileNumberCache.iterator();
-
// Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableMobileNumber> next = iterator.next();
-
+ for (final Cache.Entry<Long, DialableMobileNumber> currentEntry : this.mobileNumberCache) {
// Add value to list
- list.add(next.getValue());
+ list.add(currentEntry.getValue());
}
// Return it
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
*/
public void init () {
// Is cache there?
if (!this.faxNumberCache.iterator().hasNext()) {
- // Get whole list
- final List<DialableFaxNumber> list = this.phoneBean.allFaxNumbers();
+ // Get whole list from EJB
+ 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();
+ // Get whole list from EJB
+ 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();
+ // Get whole list from EJB
+ 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);
}
}
}
// 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
// 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
// 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
// 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
}