*/
package org.mxchange.pizzaapplication.beans.customer;
+import java.text.MessageFormat;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
return "admin_list_customer"; //NOI18N
}
+ @Override
+ public void copyCustomerToController (final Customer customer) {
+ // Parameters must be valid
+ if (null == customer) {
+ // Throw NPE
+ throw new NullPointerException("customer is null");
+ } else if (customer.getCustomerId() == null) {
+ // Throw again ...
+ throw new NullPointerException("customer.customerId is null");
+ } else if (customer.getCustomerId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("customer.customerId={0} is not valid", customer.getCustomerId()));
+ } else if (customer.getCustomerContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("customer.customerContact is null");
+ } else if (customer.getCustomerContact().getContactId() == null) {
+ // .. and again
+ throw new NullPointerException("customer.customerContact.contactId is null");
+ } else if (customer.getCustomerContact().getContactId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("customer.customerContact.contactId={0} is not valid", customer.getCustomerContact().getContactId()));
+ }
+
+ // @TODO Set all data
+ }
+
/**
* Post-initialization of this class
*/
package org.mxchange.pizzaapplication.beans.customer;
import java.io.Serializable;
+import org.mxchange.jcustomercore.model.customer.Customer;
/**
* An interface for user beans
*/
public interface PizzaAdminCustomerWebRequestController extends Serializable {
+ public void copyCustomerToController (Customer customer);
+
/**
* Adds customer to database if not already added. This method should return
* a redirect outcome on success.
import java.io.Serializable;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.jusercore.model.user.User;
/**
*/
void setContact (final Contact contact);
+ /**
+ * Getter for customer instance
+ * <p>
+ * @return Customer instance
+ */
+ Customer getCustomer ();
+
+ /**
+ * Setter for customer instance
+ * <p>
+ * @param customer Contact instance
+ */
+ void setCustomer (final Customer customer);
+
/**
* Copies currently set contact instance's data to adminContactController
*/
void copyContactToController ();
+ /**
+ * Copies currently set customer instance's data to adminCustomerController
+ */
+ void copyCustomerToController ();
+
}
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcustomercore.model.customer.Customer;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.pizzaapplication.beans.contact.PizzaAdminContactWebRequestController;
import org.mxchange.pizzaapplication.beans.customer.PizzaAdminCustomerWebRequestController;
*/
private Contact contact;
+ /**
+ * Contact instance
+ */
+ private Customer customer;
+
/**
* General user controller
*/
//* NOISY-DEBUG: */ System.out.println("AdminHelper::copyContactToController - EXIT!"); //NOI18N
}
+ @Override
+ public void copyCustomerToController () {
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - CALLED!"); //NOI18N
+
+ // Validate user instance
+ if (this.getCustomer() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.customer is null"); //NOI18N
+ } else if (this.getCustomer().getCustomerId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.customer.customerId is null"); //NOI18N
+ } else if (this.getCustomer().getCustomerId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.customer.customerId={0} is not valid.", this.getCustomer().getCustomerId())); //NOI18N
+ }
+
+ // Set all fields: user
+ this.adminCustomerController.copyCustomerToController(this.getCustomer());
+
+ // Log message
+ //* NOISY-DEBUG: */ System.out.println("AdminHelper::copyCustomerToController - EXIT!"); //NOI18N
+ }
+
@Override
public void copyUserToController () {
// Log message
this.contact = contact;
}
+ @Override
+ public Customer getCustomer () {
+ return this.customer;
+ }
+
+ @Override
+ public void setCustomer (final Customer customer) {
+ this.customer = customer;
+ }
+
@Override
public User getUser () {
return this.user;
contact = this.contactBean.findContactById(contactId);
// Debug message
- // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: user={0}", user)); //NOI18N
+ // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: contact={0}", contact)); //NOI18N
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.pizzaapplication.converter.customer;
+
+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.jcustomercore.exceptions.CustomerNotFoundException;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.pizzaapplication.model.customer.PizzaCustomerSessionBeanRemote;
+
+/**
+ * Converter for customer id <-> valid customer instance
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesConverter (value = "CustomerConverter")
+public class PizzaCustomerConverter implements Converter {
+
+ /**
+ * User EJB
+ */
+ private PizzaCustomerSessionBeanRemote customerBean;
+
+ /**
+ * Logger instance
+ */
+ @Log
+ private LoggerBeanLocal loggerBeanLocal;
+
+ /**
+ * Initialization of this converter
+ */
+ public PizzaCustomerConverter () {
+ // 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.customerBean = (PizzaCustomerSessionBeanRemote) context.lookup("java:global/jratecalc-ejb/customer!de.chotime.jratecalc.model.customer.PizzaCustomerSessionBeanRemote"); //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) {
+ // Trace message
+ // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: context={0},component={1},submittedValue={2} - CALLED!", 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
+ Customer customer = null;
+
+ try {
+ // Try to parse the value as long
+ Long customerId = Long.valueOf(submittedValue);
+
+ // Debug message
+ // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: customerId{0}", customerId)); //NOI18N
+
+ // Try to get user instance from it
+ customer = this.customerBean.findCustomerById(customerId);
+
+ // Debug message
+ // NOISY-DEBUG: this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: customer={0}", customer)); //NOI18N
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final CustomerNotFoundException ex) {
+ // Debug message
+ this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Trace message
+ // NOISY-DEBUG: this.loggerBeanLocal.logTrace(MessageFormat.format("getAsObject: contact={0} - EXIT!", contact)); //NOI18N
+
+ // Return it
+ return customer;
+ }
+
+ @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 Customer)) {
+ // Not same interface
+ throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement Customer.", value)); //NOI18N
+ }
+
+ // Return category id
+ return String.valueOf(((Customer) value).getCustomerId());
+ }
+
+}
xmlns:f="http://xmlns.jcp.org/jsf/core"
>
+ <f:metadata>
+ <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+ </f:metadata>
+
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_DELETE_CUSTOMER}</ui:define>
xmlns:f="http://xmlns.jcp.org/jsf/core"
>
+ <f:metadata>
+ <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+ </f:metadata>
+
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_EDIT_CUSTOMER}</ui:define>
xmlns:f="http://xmlns.jcp.org/jsf/core"
>
+ <f:metadata>
+ <f:viewParam name="customerId" value="#{adminHelper.customer}" converter="CustomerConverter" required="true" requiredMessage="#{msg.ERROR_PARAMETER_CUSTOMER_ID_NOT_SET}" />
+ <f:viewAction action="#{adminHelper.copyCustomerToController()}" />
+ </f:metadata>
+
<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl">
<ui:define name="admin_title">#{msg.PAGE_TITLE_ADMIN_SHOW_CUSTOMER}</ui:define>