]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/country/JobsCountryWebRequestBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / country / JobsCountryWebRequestBean.java
index 964b26bef6f3261c8c29deeca3ed43f091007bed..d23618cb02f6566b6ec661f61dc2bdd0d51642cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2020 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
  */
 package org.mxchange.jjobs.beans.country;
 
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
 import javax.ejb.EJB;
 import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
 import javax.inject.Named;
-import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
-import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
-import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jjobs.beans.BaseJobsBean;
 
 /**
  * A country bean
@@ -40,7 +29,7 @@ import org.mxchange.jjobs.beans.BaseJobsController;
  */
 @Named ("countryController")
 @RequestScoped
-public class JobsCountryWebRequestBean extends BaseJobsController implements JobsCountryWebRequestController {
+public class JobsCountryWebRequestBean extends BaseJobsBean implements JobsCountryWebRequestController {
 
        /**
         * Serial number
@@ -53,13 +42,6 @@ public class JobsCountryWebRequestBean extends BaseJobsController implements Job
        @EJB (lookup = "java:global/jjobs-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote")
        private CountrySingletonBeanRemote countryBean;
 
-       /**
-        * List of all countries
-        */
-       @Inject
-       @NamedCache (cacheName = "countryCache")
-       private Cache<Long, Country> countryCache;
-
        /**
         * Default constructor
         */
@@ -68,73 +50,4 @@ public class JobsCountryWebRequestBean extends BaseJobsController implements Job
                super();
        }
 
-       /**
-        * Observing method when the event is fired that an administrator added a
-        * new country
-        * <p>
-        * @param event Event instance
-        */
-       public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent 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.countryCache.put(event.getAddedCountry().getCountryId(), event.getAddedCountry());
-       }
-
-       @Override
-       @SuppressWarnings ("ReturnOfCollectionOrArrayField")
-       public List<Country> allCountries () {
-               // Init list
-               final List<Country> list = new LinkedList<>();
-
-               // Get iterator
-               final Iterator<Cache.Entry<Long, Country>> iterator = this.countryCache.iterator();
-
-               // Loop over all
-               while (iterator.hasNext()) {
-                       // Get next entry
-                       final Cache.Entry<Long, Country> next = iterator.next();
-
-                       // Add value to list
-                       list.add(next.getValue());
-               }
-
-               // Return it
-               return list;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Is cache there?
-               if (!this.countryCache.iterator().hasNext()) {
-                       // Get whole list
-                       final List<Country> list = this.countryBean.allCountries();
-
-                       // Add all
-                       for (final Iterator<Country> iterator = list.iterator(); iterator.hasNext();) {
-                               // Get next element
-                               final Country next = iterator.next();
-
-                               // Add it to cache
-                               this.countryCache.put(next.getCountryId(), next);
-                       }
-               }
-       }
-
 }