]> 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 02bc4ff2b6a8b5aff663029279029b311d5f92c2..d23618cb02f6566b6ec661f61dc2bdd0d51642cd 100644 (file)
  */
 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.added.ObservableAdminAddedCountryEvent;
-import org.mxchange.jcountry.exceptions.CountryNotFoundException;
-import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
 import org.mxchange.jjobs.beans.BaseJobsBean;
 
@@ -54,13 +42,6 @@ public class JobsCountryWebRequestBean extends BaseJobsBean implements JobsCount
        @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
         */
@@ -69,91 +50,4 @@ public class JobsCountryWebRequestBean extends BaseJobsBean implements JobsCount
                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;
-       }
-
-       @Override
-       public Country findCountryById (final Long countryId) throws CountryNotFoundException {
-               // Validate parameter
-               if (null == countryId) {
-                       // Throw NPE
-                       throw new NullPointerException("countryId is null"); //NOI18N
-               } else if (countryId < 1) {
-                       // Throw IAE
-                       throw new IllegalArgumentException("countryId=" + countryId + " is invalid"); //NOI18N
-               } else if (!this.countryCache.containsKey(countryId)) {
-                       // Not found
-                       throw new CountryNotFoundException(countryId);
-               }
-
-               // Get it from cache
-               final Country country = this.countryCache.get(countryId);
-
-               // Return it
-               return country;
-       }
-
-       /**
-        * Post-construction method
-        */
-       @PostConstruct
-       public void init () {
-               // Is cache there?
-               if (!this.countryCache.iterator().hasNext()) {
-                       // Get whole list from EJB
-                       final List<Country> countries = this.countryBean.allCountries();
-
-                       // Add all
-                       for (final Country country : countries) {
-                               // Add it to cache
-                               this.countryCache.put(country.getCountryId(), country);
-                       }
-               }
-       }
-
 }