From: Roland Häder Date: Tue, 23 Aug 2016 10:54:52 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5e6b302f9f8605e85350f8d723a434b3acc3598a;p=jjobs-war.git Please cherry-pick: - added more controller (managed bean) methods for deleting/updating fax/land-line numbers Signed-off-by: Roland Häder --- diff --git a/src/java/de/chotime/landingpage/converter/fax/LandingFaxNumberConverter.java b/src/java/de/chotime/landingpage/converter/fax/LandingFaxNumberConverter.java deleted file mode 100644 index 7bd5fd33..00000000 --- a/src/java/de/chotime/landingpage/converter/fax/LandingFaxNumberConverter.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (C) 2016 Cho-Time GmbH - * - * 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 de.chotime.landingpage.converter.fax; - -import java.text.MessageFormat; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.phonenumbers.DialableNumber; -import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; -import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; - -/** - * Converter for fax id <-> valid fax number instance - *

- * @author Roland Haeder - */ -@FacesConverter (value = "FaxNumberConverter") -public class LandingFaxNumberConverter implements Converter { - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Phone EJB - */ - private PhoneSessionBeanRemote phoneBean; - - /** - * Initialization of this converter - */ - public LandingFaxNumberConverter () { - // Try to get it - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup logger - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - - // ... and user controller - this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - - @Override - public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Log message - this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - DialableFaxNumber faxNumber = null; - - try { - // Try to parse the value as long - Long faxNumberId = Long.valueOf(submittedValue); - - // Log message - this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N - - // Try to get mobile instance from it - faxNumber = this.phoneBean.findFaxNumberById(faxNumberId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final PhoneEntityNotFoundException ex) { - // Debug message - this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Log message - this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: faxNumber={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N - - // Return it - return faxNumber; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { - // Is the object null? - if ((null == value) || ((String.valueOf(value)).isEmpty())) { - // Is null - return ""; //NOI18N - } else if (!(value instanceof DialableNumber)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N - } - - // Return category id - return String.valueOf(((DialableNumber) value).getPhoneId()); - } - -} diff --git a/src/java/de/chotime/landingpage/converter/landline/LandingLandLineNumberConverter.java b/src/java/de/chotime/landingpage/converter/landline/LandingLandLineNumberConverter.java deleted file mode 100644 index 2630663b..00000000 --- a/src/java/de/chotime/landingpage/converter/landline/LandingLandLineNumberConverter.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2016 Cho-Time GmbH - * - * 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 de.chotime.landingpage.converter.landline; - -import java.text.MessageFormat; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; -import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; -import org.mxchange.jphone.phonenumbers.DialableNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; - -/** - * Converter for land-line id <-> valid land-line number instance - *

- * @author Roland Haeder - */ -@FacesConverter (value = "LandLineNumberConverter") -public class LandingLandLineNumberConverter implements Converter { - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Phone EJB - */ - private PhoneSessionBeanRemote phoneBean; - - /** - * Initialization of this converter - */ - public LandingLandLineNumberConverter () { - // Try to get it - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup logger - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - - // ... and user controller - this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - - @Override - public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - DialableLandLineNumber landLineNumber = null; - - try { - // Try to parse the value as long - Long landLineNumberId = Long.valueOf(submittedValue); - - // Try to get mobile instance from it - landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final PhoneEntityNotFoundException ex) { - // Debug message - this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return landLineNumber; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { - // Is the object null? - if ((null == value) || ((String.valueOf(value)).isEmpty())) { - // Is null - return ""; //NOI18N - } else if (!(value instanceof DialableNumber)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N - } - - // Return category id - return String.valueOf(((DialableNumber) value).getPhoneId()); - } - -} diff --git a/src/java/de/chotime/landingpage/debug/LandingDebugLifeCycleListener.java b/src/java/de/chotime/landingpage/debug/LandingDebugLifeCycleListener.java deleted file mode 100644 index 2a1c24a4..00000000 --- a/src/java/de/chotime/landingpage/debug/LandingDebugLifeCycleListener.java +++ /dev/null @@ -1,51 +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 de.chotime.landingpage.debug; - -import java.text.MessageFormat; -import javax.faces.event.PhaseEvent; -import javax.faces.event.PhaseId; -import javax.faces.event.PhaseListener; - -/** - * A listener for debugging JSF lifecycle phases - *

- * @author Roland Haeder - */ -public class LandingDebugLifeCycleListener implements PhaseListener { - - /** - * Serial number - */ - private static final long serialVersionUID = 523_467_675_719_515L; - - @Override - public void afterPhase (final PhaseEvent event) { - System.out.println(MessageFormat.format("<--- End phase {0}", event.getPhaseId())); //NOI18N - } - - @Override - public void beforePhase (final PhaseEvent event) { - System.out.println(MessageFormat.format("---> Start phase {0}", event.getPhaseId())); //NOI18N - } - - @Override - public PhaseId getPhaseId () { - return PhaseId.ANY_PHASE; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index 596d0a3e..10397cf5 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -31,10 +31,18 @@ import javax.naming.NamingException; import org.mxchange.jcountry.data.Country; import org.mxchange.jjobs.beans.BaseJobsController; import org.mxchange.jjobs.beans.helper.JobsWebViewController; +import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; +import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent; import org.mxchange.jphone.events.fax.removed.AdminFaxNumberRemovedFromListEvent; import org.mxchange.jphone.events.fax.removed.AdminRemoveFaxNumberFromListEvent; +import org.mxchange.jphone.events.fax.updated.AdminFaxNumberUpdatedEvent; +import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; +import org.mxchange.jphone.events.landline.deleted.AdminLandLineNumberDeletedEvent; import org.mxchange.jphone.events.landline.removed.AdminLandLineNumberRemovedFromListEvent; import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent; +import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent; +import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent; import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent; import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent; @@ -92,6 +100,33 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements */ private DialableMobileNumber choosenMobileNumber; + /** + * Event being fired when an administrator has deleted fax number + */ + @Inject + @Any + private Event faxNumberDeletedEvent; + + + /** + * Event being fired when an administrator has updated fax number + */ + @Inject + @Any + private Event faxNumberUpdatedEvent; + /** + * Event being fired when an administrator has deleted land-line number + */ + @Inject + @Any + private Event landLineNumberDeletedEvent; + + /** + * Event being fired when an administrator has updated fax number + */ + @Inject + @Any + private Event landLineNumberUpdatedEvent; /** * Event being fired when an administrator has deleted mobile number */ @@ -100,7 +135,7 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements private Event mobileNumberDeletedEvent; /** - * Event being fired when an administrator has updated mobile number + * Event being fired when an administrator has updated land-line number */ @Inject @Any @@ -211,6 +246,102 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements return list; } + @Override + public String deleteFaxData (final DialableFaxNumber faxNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Call EJB + this.adminPhoneBean.deleteFaxData(faxNumber); + + // Fire event + this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(faxNumber)); + + // All fine, redirect + return "admin_list_fax"; //NOI18N + } + + @Override + public String deleteLandLineData (final DialableLandLineNumber landLineNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Call EJB + this.adminPhoneBean.deleteLandLineData(landLineNumber); + + // Fire event + this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(landLineNumber)); + + // All fine, redirect + return "admin_list_landline"; //NOI18N + } + @Override public String deleteMobileData (final DialableMobileNumber mobileNumber) { // Log message @@ -253,6 +384,136 @@ public class JobsAdminPhoneWebRequestBean extends BaseJobsController implements return "admin_list_mobile"; //NOI18N } + @Override + public String editFaxData (final DialableFaxNumber faxNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.deleteFaxData: faxNumber={1} - CALLED!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Is all data set + if (faxNumber == null) { + // Not set, throw NPE + throw new NullPointerException("faxNumber is null"); //NOI18N + } else if (faxNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N + } else if (faxNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid", faxNumber.getPhoneId())); //NOI18N + } else if (faxNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("faxNumber.phoneCountry.countryId is null"); //NOI18N + } else if (faxNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("faxNumber.phoneCountry.countryId={0} is not valid", faxNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (faxNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("faxNumber.phoneAreaCode is null"); //NOI18N + } else if (faxNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneAreaCode={0} is not valid.", faxNumber.getPhoneAreaCode())); //NOI18N + } else if (faxNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("faxNumber.phoneNumber is null"); //NOI18N + } else if (faxNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("faxNumber.phoneNumber={0} is not valid.", faxNumber.getPhoneNumber())); //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getPhoneCountry(), faxNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), faxNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), faxNumber.getPhoneNumber()))) { + // Log message + System.out.println(MessageFormat.format("{0}.editFaxData: No difference - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Show message + this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + faxNumber.setPhoneCountry(this.getPhoneCountry()); + faxNumber.setPhoneAreaCode(this.getPhoneAreaCode()); + faxNumber.setPhoneNumber(this.getPhoneNumber()); + + // Send to bean + DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(faxNumber); + + // Fire event + this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_fax"; //NOI18N + } + + @Override + public String editLandLineData (final DialableLandLineNumber landLineNumber) { + // Log message + System.out.println(MessageFormat.format("{0}.deleteLandLineData: landLineNumber={1} - CALLED!", this.getClass().getSimpleName(), landLineNumber)); //NOI18N + + // Is all data set + if (landLineNumber == null) { + // Not set, throw NPE + throw new NullPointerException("landLineNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneId() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N + } else if (landLineNumber.getPhoneId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid", landLineNumber.getPhoneId())); //NOI18N + } else if (landLineNumber.getPhoneCountry() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() == null) { + // Throw NPE + throw new NullPointerException("landLineNumber.phoneCountry.countryId is null"); //NOI18N + } else if (landLineNumber.getPhoneCountry().getCountryId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneCountry.countryId={0} is not valid", landLineNumber.getPhoneCountry().getCountryId())); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() == null) { + // ... throw again + throw new NullPointerException("landLineNumber.phoneAreaCode is null"); //NOI18N + } else if (landLineNumber.getPhoneAreaCode() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneAreaCode={0} is not valid.", landLineNumber.getPhoneAreaCode())); //NOI18N + } else if (landLineNumber.getPhoneNumber() == null) { + // Throw NPE again + throw new NullPointerException("landLineNumber.phoneNumber is null"); //NOI18N + } else if (landLineNumber.getPhoneNumber() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("landLineNumber.phoneNumber={0} is not valid.", landLineNumber.getPhoneNumber())); //NOI18N + } + + // Is the mobile provider and number the same? + if ((Objects.equals(this.getPhoneCountry(), landLineNumber.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), landLineNumber.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), landLineNumber.getPhoneNumber()))) { + // Log message + System.out.println(MessageFormat.format("{0}.editLandLineData: No difference - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Show message + this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N + + // No difference in both together, no need to edit + return ""; //NOI18N + } + + // Set all data + landLineNumber.setPhoneCountry(this.getPhoneCountry()); + landLineNumber.setPhoneAreaCode(this.getPhoneAreaCode()); + landLineNumber.setPhoneNumber(this.getPhoneNumber()); + + // Send to bean + DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(landLineNumber); + + // Fire event + this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber)); + + // All fine, redirect + return "admin_show_landline"; //NOI18N + } + @Override public String editMobileData (final DialableMobileNumber mobileNumber) { // Log message diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java index 436a48d1..5f068c4a 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestController.java @@ -55,6 +55,42 @@ public interface JobsAdminPhoneWebRequestController extends Serializable { */ List allNonLinkedLandLineNumbers (); + /** + * Deletes given fax entry data + *

+ * @param faxNumber Fax number to delete + *

+ * @return Redirect outcome + */ + String deleteFaxData (final DialableFaxNumber faxNumber); + + /** + * Changes fax entry data + *

+ * @param faxNumber Fax number to change data + *

+ * @return Redirect outcome + */ + String editFaxData (final DialableFaxNumber faxNumber); + + /** + * Deletes given land-line entry data + *

+ * @param landLineNumber Land-line number to delete + *

+ * @return Redirect outcome + */ + String deleteLandLineData (final DialableLandLineNumber landLineNumber); + + /** + * Changes land-line entry data + *

+ * @param landLineNumber Land-line number to change data + *

+ * @return Redirect outcome + */ + String editLandLineData (final DialableLandLineNumber landLineNumber); + /** * Deletes given mobile entry data *

diff --git a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java new file mode 100644 index 00000000..5548d4d1 --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java @@ -0,0 +1,130 @@ +/* + * 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.converter.fax; + +import java.text.MessageFormat; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcoreeelogger.beans.local.logger.Log; +import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; +import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.fax.DialableFaxNumber; +import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Converter for fax id <-> valid fax number instance + *

+ * @author Roland Haeder + */ +@FacesConverter (value = "FaxNumberConverter") +public class JobsFaxNumberConverter implements Converter { + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Phone EJB + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Initialization of this converter + */ + public JobsFaxNumberConverter () { + // Try to get it + try { + // Get initial context + Context context = new InitialContext(); + + // Lookup logger + this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N + + // ... and user controller + this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + + @Override + public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Log message + this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + DialableFaxNumber faxNumber = null; + + try { + // Try to parse the value as long + Long faxNumberId = Long.valueOf(submittedValue); + + // Log message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N + + // Try to get mobile instance from it + faxNumber = this.phoneBean.findFaxNumberById(faxNumberId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final PhoneEntityNotFoundException ex) { + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Log message + this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: faxNumber={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N + + // Return it + return faxNumber; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if ((null == value) || ((String.valueOf(value)).isEmpty())) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof DialableNumber)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((DialableNumber) value).getPhoneId()); + } + +} diff --git a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java new file mode 100644 index 00000000..8cff9bb1 --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -0,0 +1,121 @@ +/* + * 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.converter.landline; + +import java.text.MessageFormat; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcoreeelogger.beans.local.logger.Log; +import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; +import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; +import org.mxchange.jphone.phonenumbers.DialableNumber; +import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; +import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; + +/** + * Converter for land-line id <-> valid land-line number instance + *

+ * @author Roland Haeder + */ +@FacesConverter (value = "LandLineNumberConverter") +public class JobsLandLineNumberConverter implements Converter { + + /** + * Logger instance + */ + @Log + private LoggerBeanLocal loggerBeanLocal; + + /** + * Phone EJB + */ + private PhoneSessionBeanRemote phoneBean; + + /** + * Initialization of this converter + */ + public JobsLandLineNumberConverter () { + // Try to get it + try { + // Get initial context + Context context = new InitialContext(); + + // Lookup logger + this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N + + // ... and user controller + this.phoneBean = (PhoneSessionBeanRemote) context.lookup("java:global/jlandingpage-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N + } catch (final NamingException ex) { + // Continue to throw it + throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N + } + } + + @Override + public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + DialableLandLineNumber landLineNumber = null; + + try { + // Try to parse the value as long + Long landLineNumberId = Long.valueOf(submittedValue); + + // Try to get mobile instance from it + landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final PhoneEntityNotFoundException ex) { + // Debug message + this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return landLineNumber; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + // Is the object null? + if ((null == value) || ((String.valueOf(value)).isEmpty())) { + // Is null + return ""; //NOI18N + } else if (!(value instanceof DialableNumber)) { + // Not same interface + throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N + } + + // Return category id + return String.valueOf(((DialableNumber) value).getPhoneId()); + } + +} diff --git a/src/java/org/mxchange/jjobs/debug/JobsDebugLifeCycleListener.java b/src/java/org/mxchange/jjobs/debug/JobsDebugLifeCycleListener.java new file mode 100644 index 00000000..b3ce4ffa --- /dev/null +++ b/src/java/org/mxchange/jjobs/debug/JobsDebugLifeCycleListener.java @@ -0,0 +1,51 @@ +/* + * 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.debug; + +import java.text.MessageFormat; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.faces.event.PhaseListener; + +/** + * A listener for debugging JSF lifecycle phases + *

+ * @author Roland Haeder + */ +public class JobsDebugLifeCycleListener implements PhaseListener { + + /** + * Serial number + */ + private static final long serialVersionUID = 523_467_675_719_515L; + + @Override + public void afterPhase (final PhaseEvent event) { + System.out.println(MessageFormat.format("<--- End phase {0}", event.getPhaseId())); //NOI18N + } + + @Override + public void beforePhase (final PhaseEvent event) { + System.out.println(MessageFormat.format("---> Start phase {0}", event.getPhaseId())); //NOI18N + } + + @Override + public PhaseId getPhaseId () { + return PhaseId.ANY_PHASE; + } + +}