import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminFaxNumberUnlinkedEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminLandLineNumberUnlinkedEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.mobile.unlinked.AdminMobileNumberUnlinkedEvent;
import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
import org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote;
import org.mxchange.jjobs.beans.BaseJobsController;
import org.mxchange.jjobs.beans.helper.JobsWebRequestController;
+import org.mxchange.jphone.exceptions.FaxNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.LandLineNumberNotLinkedException;
import org.mxchange.jphone.exceptions.MobileNumberNotLinkedException;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
@Inject
private JobsWebRequestController beanHelper;
+ /**
+ * Event being fired when a fax number has been unlinked
+ */
+ @Inject
+ @Any
+ private Event<AdminUnlinkedFaxNumberEvent> faxNumberUnlinkedEvent;
+
+ /**
+ * Event being fired when a land-line number has been unlinked
+ */
+ @Inject
+ @Any
+ private Event<AdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
+
/**
* Event being fired when admin unlinks mobile from contact
*/
@Inject
@Any
- private Event<AdminUnlinkedMobileNumberEvent> mobileDataUnlinkedEvent;
+ private Event<AdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
/**
* Default constructor
this.clear();
}
+ @Override
+ public String unlinkFaxContactData () {
+ // Is all data set
+ if (this.beanHelper.getFaxNumber() == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("this.beanHelper.faxNumber is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.faxNumber.phoneId is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.faxNumber.phoneId={0} is not valid", this.beanHelper.getFaxNumber().getPhoneId())); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.faxNumber.phoneNumber is null"); //NOI18N
+ } else if (this.beanHelper.getFaxNumber().getPhoneNumber() < 1) {
+ // Throw it again ...
+ throw new NullPointerException(MessageFormat.format("this.beanHelper.faxNumber.phoneNumber={0} is not valid.", this.beanHelper.getFaxNumber().getPhoneNumber())); //NOI18N
+ } else if (this.beanHelper.getContact() == null) {
+ // ... and throw again
+ throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() == null) {
+ // ... and again ...
+ throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ }
+
+ // Init contact instance
+ Contact updatedContact;
+
+ try {
+ // Unlink it and return contact without fax instance
+ updatedContact = this.adminPhoneBean.unlinkFaxDataFromContact(this.beanHelper.getContact(), this.beanHelper.getFaxNumber());
+ } catch (final FaxNumberNotLinkedException ex) {
+ // Did not work
+ this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.faxNumberUnlinkedEvent.fire(new AdminFaxNumberUnlinkedEvent(updatedContact, this.beanHelper.getFaxNumber()));
+
+ // All fine here
+ return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
+ }
+
+ @Override
+ public String unlinkLandLineContactData () {
+ // Is all data set
+ if (this.beanHelper.getLandLineNumber() == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("this.beanHelper.landLineNumber is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.landLineNumber.phoneId is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.landLineNumber.phoneId={0} is not valid", this.beanHelper.getLandLineNumber().getPhoneId())); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.beanHelper.landLineNumber.phoneNumber is null"); //NOI18N
+ } else if (this.beanHelper.getLandLineNumber().getPhoneNumber() < 1) {
+ // Throw it again ...
+ throw new NullPointerException(MessageFormat.format("this.beanHelper.landLineNumber.phoneNumber={0} is not valid.", this.beanHelper.getLandLineNumber().getPhoneNumber())); //NOI18N
+ } else if (this.beanHelper.getContact() == null) {
+ // ... and throw again
+ throw new NullPointerException("this.beanHelper.contact is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() == null) {
+ // ... and again ...
+ throw new NullPointerException("this.beanHelper.contact.contactId is null"); //NOI18N
+ } else if (this.beanHelper.getContact().getContactId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.contact.contactId={0} is invalid.", this.beanHelper.getContact().getContactId())); //NOI18N
+ }
+
+ // Init contact instance
+ Contact updatedContact;
+
+ try {
+ // Unlink it and return contact without landLine instance
+ updatedContact = this.adminPhoneBean.unlinkLandLineDataFromContact(this.beanHelper.getContact(), this.beanHelper.getLandLineNumber());
+ } catch (final LandLineNumberNotLinkedException ex) {
+ // Did not work
+ this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+ return ""; //NOI18N
+ }
+
+ // Fire event
+ this.landLineNumberUnlinkedEvent.fire(new AdminLandLineNumberUnlinkedEvent(updatedContact, this.beanHelper.getLandLineNumber()));
+
+ // All fine here
+ return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
+ }
+
@Override
public String unlinkMobileContactData () {
// Is all data set
}
// Fire event
- this.mobileDataUnlinkedEvent.fire(new AdminMobileNumberUnlinkedEvent(updatedContact, this.beanHelper.getMobileNumber()));
+ this.mobileNumberUnlinkedEvent.fire(new AdminMobileNumberUnlinkedEvent(updatedContact, this.beanHelper.getMobileNumber()));
// All fine here
return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
import org.mxchange.jphone.phonenumbers.DialableNumber;
import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber;
}
@Override
- public void afterAdminUnlinkedCellphoneContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) {
+ public void afterAdminUnlinkedFaxContactDataEvent (@Observes final AdminUnlinkedFaxNumberEvent event) {
// event should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUnlinkedCellphoneNumber() == null) {
+ } else if (event.getUnlinkedFaxNumber() == null) {
// Throw NPE again
- throw new NullPointerException("event.unlinkedCellphoneNumber is null"); //NOI18N
- } else if (event.getUnlinkedCellphoneNumber().getPhoneId() == null) {
+ throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
// userId is null
- throw new NullPointerException("event.unlinkedCellphoneNumber.contactId is null"); //NOI18N
- } else if (event.getUnlinkedCellphoneNumber().getPhoneId() < 1) {
+ throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
// Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedCellphoneNumber(), event.getUnlinkedCellphoneNumber().getPhoneId())); //NOI18N
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
}
// Remove it from list
- this.contacts.remove(event.getUnlinkedCellphoneNumber());
+ this.contacts.remove(event.getUnlinkedFaxNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final AdminUnlinkedLandLineNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.contacts.remove(event.getUnlinkedLandLineNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public void afterAdminUnlinkedMobileContactDataEvent (@Observes final AdminUnlinkedMobileNumberEvent event) {
+ // event should not be null
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from list
+ this.contacts.remove(event.getUnlinkedMobileNumber());
// Clear all data
this.clear();
import org.mxchange.jcontacts.contact.Contact;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event);
/**
- * Event observer for unlinked mobile-contact by administrators
+ * Event observer for unlinked fax contact by administrators
* <p>
- * @param event Unlinked mobile-contact event
+ * @param event Unlinked fax contact event
*/
- void afterAdminUnlinkedCellphoneContactDataEvent (final AdminUnlinkedMobileNumberEvent event);
+ void afterAdminUnlinkedFaxContactDataEvent (final AdminUnlinkedFaxNumberEvent event);
+
+ /**
+ * Event observer for unlinked land-line contact by administrators
+ * <p>
+ * @param event Unlinked land-line contact event
+ */
+ void afterAdminUnlinkedLandLineContactDataEvent (final AdminUnlinkedLandLineNumberEvent event);
+
+ /**
+ * Event observer for unlinked mobile contact by administrators
+ * <p>
+ * @param event Unlinked mobile contact event
+ */
+ void afterAdminUnlinkedMobileContactDataEvent (final AdminUnlinkedMobileNumberEvent event);
}