]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/beans/localization/JobsLocalizationSessionBean.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / beans / localization / JobsLocalizationSessionBean.java
index 62d99a8b650fb982e3dfc8583d8be60c08bf8e78..941da4bc30665897a795cf7123b1a8d3535fbfab 100644 (file)
  */
 package org.mxchange.jjobs.beans.localization;
 
+import java.text.MessageFormat;
 import java.util.Locale;
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Observes;
 import javax.faces.context.FacesContext;
 import javax.inject.Named;
-import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.beans.BaseJobsController;
+import org.mxchange.jusercore.events.login.UserLoggedInEvent;
+import org.mxchange.jusercore.events.logout.ObserveableUserLogoutEvent;
 
 /**
  * A session bean for handling localization/internationalization changes. This
@@ -33,7 +37,7 @@ import org.mxchange.jcoreee.database.BaseDatabaseBean;
  */
 @Named ("localizationController")
 @SessionScoped
-public class JobsLocalizationSessionBean extends BaseDatabaseBean implements JobsLocalizationSessionController {
+public class JobsLocalizationSessionBean extends BaseJobsController implements JobsLocalizationSessionController {
 
        /**
         * Serial number
@@ -45,16 +49,61 @@ public class JobsLocalizationSessionBean extends BaseDatabaseBean implements Job
         */
        private Locale locale;
 
+       @Override
+       public void afterUserLoginEvent (@Observes final UserLoggedInEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedInUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.loggedInUser is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N
+               } else if (event.getLoggedInUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
+               }
+
+               // Is the locale set?
+               if (event.getLoggedInUser().getUserLocale() instanceof Locale) {
+                       // Set locale here
+                       this.setLocale(event.getLoggedInUser().getUserLocale());
+               }
+       }
+
+       @Override
+       public void afterUserLogoutEvent (@Observes final ObserveableUserLogoutEvent event) {
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getLoggedOutUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.loggedOutUser is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.loggedOutUser.userId is null"); //NOI18N
+               } else if (event.getLoggedOutUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedOutUser(), event.getLoggedOutUser().getUserId())); //NOI18N
+               }
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("LandingLocalizationSessionBean:afterUserLogin - EXIT!"); //NOI18N
+       }
+
        @Override
        public String getLanguage () {
-               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::getLanguage(): locale.language={0} - EXIT!", this.getLocale().getLanguage())); //NOI18N
                return this.getLocale().getLanguage().toLowerCase();
        }
 
        @Override
        public void setLanguage (final String language) {
                // Log trace message
-               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: language={0} - CALLED!", language)); //NOI18N
 
                // Is the language null?
                if (null == language) {
@@ -72,25 +121,25 @@ public class JobsLocalizationSessionBean extends BaseDatabaseBean implements Job
                Locale loc = new Locale(splits[0], splits[1]);
 
                // Log debug message
-               //this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLanguage: loc={0}", loc)); //NOI18N
 
                // Set it here and in the JSF context
                this.setLocale(loc);
                FacesContext.getCurrentInstance().getViewRoot().setLocale(loc);
 
                // Log trace message
-               //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::setLanguage: EXIT!"); //NOI18N
        }
 
        @Override
        public Locale getLocale () {
-               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::getLocale(): locale={0} - EXIT!", this.locale)); //NOI18N
                return this.locale;
        }
 
        @Override
        public void setLocale (final Locale locale) {
-               //this.getLoggerBeanLocal().logTrace(MessageFormat.format("JobsLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::setLocale(): locale={0} - CALLED!", locale)); //NOI18N
                this.locale = locale;
        }
 
@@ -109,19 +158,19 @@ public class JobsLocalizationSessionBean extends BaseDatabaseBean implements Job
        @PostConstruct
        public void init () {
                // Log trace message
-               //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: CALLED!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::init: CALLED!"); //NOI18N
 
                // Create locale instance from context
                Locale loc = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
 
                // Log debug message
-               //this.getLoggerBeanLocal().logDebug(MessageFormat.format("JobsLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("JobsLocalizationSessionBean::init: loc={0}", loc)); //NOI18N
 
                // Set it here
                this.setLocale(loc);
 
                // Log trace message
-               //this.getLoggerBeanLocal().logTrace("JobsLocalizationSessionBean::init: EXIT!"); //NOI18N
+               //* NOISY-DEBUG: */ System.out.println("JobsLocalizationSessionBean::init: EXIT!"); //NOI18N
        }
 
 }