From: Roland Häder Date: Wed, 10 Aug 2016 15:40:26 +0000 (+0200) Subject: Continued with cell phone unlink: (please cherry-pick) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e5ffab1a103169f46a4765c06dc2c4584b476b7a;p=jjobs-war.git Continued with cell phone unlink: (please cherry-pick) - added error container for cell phone data template - fixed call of unlinkCellphoneDataFromContact() as a checked exception is thrown and 2nd parameter added Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java new file mode 100644 index 00000000..da456379 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestBean.java @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.contact.phone; + +import java.text.MessageFormat; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.Any; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +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.phone.AdminContactsPhoneSessionBeanRemote; +import org.mxchange.jjobs.beans.BaseJobsController; +import org.mxchange.jjobs.beans.helper.JobsWebRequestController; +import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; + +/** + * An administrative contact phone controller (bean) + *

+ * @author Roland Haeder + */ +@Named ("adminContactPhoneController") +@RequestScoped +public class JobsAdminContactPhoneWebRequestBean extends BaseJobsController implements JobsAdminContactPhoneWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * Administrative EJB for phone number + */ + private AdminContactsPhoneSessionBeanRemote adminPhoneBean; + + /** + * Admin helper instance + */ + @Inject + private JobsWebRequestController beanHelper; + + /** + * Event being fired when admin unlinks cellphone from contact + */ + @Inject + @Any + private Event cellphoneDataUnlinkedEvent; + + /** + * Default constructor + */ + public JobsAdminContactPhoneWebRequestBean () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup the beans + this.adminPhoneBean = (AdminContactsPhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/admincontactphone!org.mxchange.jcontacts.phone.AdminContactsPhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + + @Override + public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N + } + + // Clear this bean + this.clear(); + } + + @Override + public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + @Override + public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + @Override + public String unlinkCellphoneContactData () { + // Is all data set + if (this.beanHelper.getCellPhoneNumber() == null) { + // Not set, throw NPE + throw new NullPointerException("this.beanHelper.cellphoneNumber is null"); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.cellphoneNumber.phoneId is null"); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.cellphoneNumber.phoneId={0} is not valid", this.beanHelper.getCellPhoneNumber().getPhoneId())); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getCellphoneProvider() == null) { + // Throw NPE + throw new NullPointerException("this.beanHelper.cellphoneNumber.cellphoneProvider is null"); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getCellphoneProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("this.beanHelper.cellphoneNumber.cellphoneProvider.providerId is null"); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getCellphoneProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("this.beanHelper.cellphoneNumber.cellphoneProvider.providerId={0} is not valid.", this.beanHelper.getCellPhoneNumber().getCellphoneProvider().getProviderId())); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("this.beanHelper.cellphoneNumber.phoneNumber is null"); //NOI18N + } else if (this.beanHelper.getCellPhoneNumber().getPhoneNumber() < 1) { + // Throw it again ... + throw new NullPointerException(MessageFormat.format("this.beanHelper.cellphoneNumber.phoneNumber={0} is not valid.", this.beanHelper.getCellPhoneNumber().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 cell phone instance + updatedContact = this.adminPhoneBean.unlinkCellphoneDataFromContact(this.beanHelper.getContact(), this.beanHelper.getCellPhoneNumber()); + } catch (final CellphoneNotLinkedException ex) { + // Did not work + this.showFacesMessage("form_unlink_contact_cellphone:cellphoneId", ex); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.cellphoneDataUnlinkedEvent.fire(new AdminCellphoneNumberUnlinkedEvent(updatedContact, this.beanHelper.getCellPhoneNumber())); + + // All fine here + return "admin_show_contact?faces-redirect=true&includeViewParams=true"; //NOI18N + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java new file mode 100644 index 00000000..baae0ac9 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsAdminContactPhoneWebRequestController.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jjobs.beans.contact.phone; + +import java.io.Serializable; +import java.util.List; +import javax.ejb.Local; +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.jusercore.events.user.add.AdminAddedUserEvent; + +/** + * An interface for user beans + *

+ * @author Roland Haeder + */ +@Local +public interface JobsAdminContactPhoneWebRequestController extends Serializable { + + /** + * Getter for all contacts having current cellphone instance linked + *

+ * @return List of all linked contacts + */ + List allCellphoneContacts (); + + /** + * Event observer for newly added users by adminstrator + *

+ * @param event Event being fired + */ + void afterAdminAddedUserEvent (final AdminAddedUserEvent event); + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + void afterAdminAddedContact (final AdminAddedContactEvent event); + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ + void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event); + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java deleted file mode 100644 index 8c182c63..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.contact.phone; - -import java.text.MessageFormat; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Observes; -import javax.inject.Inject; -import javax.inject.Named; -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.jjobs.beans.BaseJobsController; -import org.mxchange.jjobs.beans.contact.JobsContactWebSessionController; -import org.mxchange.jjobs.beans.helper.JobsWebRequestController; -import org.mxchange.jjobs.beans.phone.JobsAdminPhoneWebRequestController; -import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; - -/** - * An administrative contact phone controller (bean) - *

- * @author Roland Haeder - */ -@Named ("contactPhoneController") -@RequestScoped -public class JobsContactPhoneWebRequestBean extends BaseJobsController implements JobsContactPhoneWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * <<<<<<< - * HEAD:src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java - * Administrative phone controller - */ - @Inject - private JobsAdminPhoneWebRequestController adminPhoneController; - - /** - * ======= >>>>>>> 2a40d73... Continued with cell phone unlink: (please - * cherry-pick):src/java/de/chotime/landingpage/beans/contact/phone/LandingContactPhoneWebSessionBean.java - * Admin helper instance - */ - @Inject - private JobsWebRequestController beanHelper; - - /** - * General contact controller - */ - @Inject - private JobsContactWebSessionController contactController; - - /** - * "Cache" for contact lists, mostly only one is assigned. So this cache - * shouldn't grow beyond control. - */ - private final Map> contacts; - - /** - * Default constructor - */ - public JobsContactPhoneWebRequestBean () { - // Init lists/maps - this.contacts = new HashMap<>(10); - } - - @Override - public void afterAdminAddedContact (@Observes final AdminAddedContactEvent event) { - // The event must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact() == null) { - // Throw again ... - throw new NullPointerException("event.addedContact is null"); //NOI18N - } else if (event.getAddedContact().getContactId() == null) { - // ... and again - throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N - } else if (event.getAddedContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N //NOI18N - } - - // Clear this bean - this.clear(); - } - - @Override - public void afterAdminAddedUserEvent (@Observes final AdminAddedUserEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedUser() == null) { - // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - @Override - public void afterAdminUpdatedContactDataEvent (@Observes final AdminUpdatedContactEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedContact() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedContact is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() == null) { - // userId is null - throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - @Override - public List allCellphoneContacts () { - // Get id - Long phoneId = this.beanHelper.getCellPhoneNumber().getPhoneId(); - - // Is cache there? - if (this.contacts.containsKey(phoneId)) { - // Return cached version - return this.contacts.get(phoneId); - } else { - // Ask bean - List list = new LinkedList<>(); - - // "Walk" through all contacts - for (final Contact contact : this.contactController.allContacts()) { - // Is cellphone instance the same? - if (Objects.equals(contact.getContactCellphoneNumber(), this.beanHelper.getCellPhoneNumber())) { - // Found one - list.add(contact); - } - } - - // Store result in cache - this.contacts.put(phoneId, list); - - // Return now-cached list - return list; - } - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestController.java deleted file mode 100644 index adeb1584..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestController.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2016 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.beans.contact.phone; - -import java.io.Serializable; -import java.util.List; -import javax.ejb.Local; -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.jusercore.events.user.add.AdminAddedUserEvent; - -/** - * An interface for user beans - *

- * @author Roland Haeder - */ -@Local -public interface JobsContactPhoneWebRequestController extends Serializable { - - /** - * Getter for all contacts having current cellphone instance linked - *

- * @return List of all linked contacts - */ - List allCellphoneContacts (); - - /** - * Event observer for newly added users by adminstrator - *

- * @param event Event being fired - */ - void afterAdminAddedUserEvent (final AdminAddedUserEvent event); - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - void afterAdminAddedContact (final AdminAddedContactEvent event); - - /** - * Event observer for updated contact data by administrators - *

- * @param event Updated contact data event - */ - void afterAdminUpdatedContactDataEvent (final AdminUpdatedContactEvent event); - -} diff --git a/web/WEB-INF/templates/admin/cellphone/admin_cellphone_data.tpl b/web/WEB-INF/templates/admin/cellphone/admin_cellphone_data.tpl index 46858e2e..bea54384 100644 --- a/web/WEB-INF/templates/admin/cellphone/admin_cellphone_data.tpl +++ b/web/WEB-INF/templates/admin/cellphone/admin_cellphone_data.tpl @@ -43,4 +43,8 @@ + +

+ +