/*
- * Copyright (C) 2016 Roland Häder
+ * Copyright (C) 2016 - 2022 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 java.util.Iterator;
import java.util.List;
import java.util.Objects;
+import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
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.jcountry.data.Country;
+import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent;
import org.mxchange.jphone.events.mobileprovider.added.AdminMobileProviderAddedEvent;
import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException;
-import org.mxchange.jphone.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote;
-import org.mxchange.jphone.phonenumbers.mobileprovider.CellphoneProvider;
-import org.mxchange.jphone.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.pizzaapplication.beans.BasePizzaController;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.pizzaapplication.beans.BasePizzaBean;
/**
* Administrative bean (controller) for mobile provider
*/
@Named ("adminMobileProviderController")
@RequestScoped
-public class PizzaAdminMobileProviderWebRequestBean extends BasePizzaController implements PizzaAdminMobileProviderWebRequestController {
+public class PizzaAdminMobileProviderWebRequestBean extends BasePizzaBean implements PizzaAdminMobileProviderWebRequestController {
/**
* Serial number
/**
* Remote EJB for mobile providers (administrative)
*/
+ @EJB (lookup = "java:global/pizzaservice-ejb/adminMobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote")
private AdminMobileProviderSessionBeanRemote adminRemoteBean;
/**
* Default constructor
*/
public PizzaAdminMobileProviderWebRequestBean () {
- // Try it
- try {
- // Get initial context
- Context context = new InitialContext();
-
- // Try to lookup the beans
- this.adminRemoteBean = (AdminMobileProviderSessionBeanRemote) context.lookup("java:global/pizzaservice-ejb/adminmobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote"); //NOI18N
- } catch (final NamingException e) {
- // Throw it again
- throw new FaceletException(e);
- }
+ // Call super constructor
+ super();
}
- @Override
+ /**
+ * Adds a mobile provider to database by calling the EJB. A pre-check on
+ * dial-prefix and country combination is done, if found, an exception is
+ * thrown. A redirect should take place after successfull creation.
+ * <p>
+ * @return Redirect outcome
+ * <p>
+ * @todo Add field validation
+ */
public String addMobileProvider () {
// Create mobile provider instance
- MobileProvider mobileProvider = new CellphoneProvider(this.getProviderDialPrefix(), this.getProviderName(), this.getProviderCountry(), this.getProviderMailPattern());
+ final MobileProvider mobileProvider = new CellphoneProvider(this.getProviderDialPrefix(), this.getProviderName(), this.getProviderCountry(), this.getProviderMailPattern());
// Is the provider already created?
if (this.isMobileProviderCreated(mobileProvider)) {
// Then throw exception
- this.showFacesMessage("form_add_mobile_provider:providerDialPrefix", new MobileProviderAlreadyAddedException(mobileProvider)); //NOI18N
- return ""; //NOI18N
+ this.showFacesException("form_add_mobile_provider:providerDialPrefix", new MobileProviderAlreadyAddedException(mobileProvider), FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
}
// Init variable
- MobileProvider updatedProvider = null;
+ final MobileProvider updatedProvider;
try {
// Call remote EJB and get back an updated instance
return "admin_list_mobile_provider"; //NOI18N
}
- @Override
+ /**
+ * Getter for country instance ('s dial data)
+ * <p>
+ * @return Country instance
+ */
public Country getProviderCountry () {
return this.providerCountry;
}
- @Override
+ /**
+ * Setter for country instance ('s dial data)
+ * <p>
+ * @param providerCountry Country instance
+ */
public void setProviderCountry (final Country providerCountry) {
this.providerCountry = providerCountry;
}
- @Override
+ /**
+ * Getter for provider dial prefix
+ * <p>
+ * @return Provider dial prefix
+ */
public Long getProviderDialPrefix () {
return this.providerDialPrefix;
}
- @Override
+ /**
+ * Setter for provider dial prefix
+ * <p>
+ * @param providerDialPrefix Provider dial prefix
+ */
public void setProviderDialPrefix (final Long providerDialPrefix) {
this.providerDialPrefix = providerDialPrefix;
}
- @Override
+ /**
+ * Getter for pattern for mail gateway
+ * <p>
+ * @return Pattern for mail gateway
+ */
public String getProviderMailPattern () {
return this.providerMailPattern;
}
- @Override
+ /**
+ * Setter for pattern for mail gateway
+ * <p>
+ * @param providerMailPattern Pattern for mail gateway
+ */
public void setProviderMailPattern (final String providerMailPattern) {
this.providerMailPattern = providerMailPattern;
}
- @Override
+ /**
+ * Getter for provider name
+ * <p>
+ * @return Provider name
+ */
public String getProviderName () {
return this.providerName;
}
- @Override
+ /**
+ * Setter for provider name
+ * <p>
+ * @param providerName Provider name
+ */
public void setProviderName (final String providerName) {
this.providerName = providerName;
}