]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/country/JobsCountryWebApplicationBean.java
Continued with splitting/cleanup: (please cherry-pick)
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / country / JobsCountryWebApplicationBean.java
index 355d491adf987739dfc1d6016aede65d95916123..ff02ee7a6ee202a5d04d476c9b046712c7f4e2fe 100644 (file)
  */
 package org.mxchange.jjobs.beans.country;
 
-import java.util.Collections;
+import java.text.MessageFormat;
 import java.util.List;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
 import javax.faces.view.facelets.FaceletException;
 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.data.JobsCountrySingletonBeanRemote;
+import org.mxchange.jcountry.data.CountrySingletonBeanRemote;
+import org.mxchange.jcountry.events.AdminAddedCountryEvent;
+import org.mxchange.jjobs.beans.BaseJobsController;
 
 /**
  * A country bean
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
-@Named ("country")
+@Named ("countryController")
 @ApplicationScoped
-public class JobsCountryWebApplicationBean implements JobsCountryWebApplicationController {
+public class JobsCountryWebApplicationBean extends BaseJobsController implements JobsCountryWebApplicationController {
 
        /**
         * Serial number
@@ -45,7 +48,7 @@ public class JobsCountryWebApplicationBean implements JobsCountryWebApplicationC
        /**
         * Remote country EJB
         */
-       private JobsCountrySingletonBeanRemote countryBean;
+       private CountrySingletonBeanRemote countryBean;
 
        /**
         * List of all countries
@@ -62,17 +65,38 @@ public class JobsCountryWebApplicationBean implements JobsCountryWebApplicationC
                        Context context = new InitialContext();
 
                        // Try to lookup the bean
-                       this.countryBean = (JobsCountrySingletonBeanRemote) context.lookup("java:global/jjobs-ejb/country!org.mxchange.jcountry.data.JobsCountrySingletonBeanRemote"); //NOI18N
+                       this.countryBean = (CountrySingletonBeanRemote) context.lookup("java:global/jjobs-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); //NOI18N
                } catch (final NamingException ex) {
                        // Continue to throw
                        throw new FaceletException(ex);
                }
        }
 
+       @Override
+       public void afterAdminAddedCountry (@Observes final AdminAddedCountryEvent event) {
+               // Is all valid?
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getAddedCountry() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("event.addedCountry is null"); //NOI18N
+               } else if (event.getAddedCountry().getCountryId() == null) {
+                       // And again ...
+                       throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N
+               } else if (event.getAddedCountry().getCountryId() < 1) {
+                       // Id is invalid
+                       throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N
+               }
+
+               // Add the event
+               this.countryList.add(event.getAddedCountry());
+       }
+
        @Override
        public List<Country> allCountries () {
                // Return "cached" version
-               return Collections.unmodifiableList(this.countryList);
+               return this.countryList;
        }
 
        /**