]> git.mxchange.org Git - jjobs-war.git/commitdiff
added from lib project as there are only project-specific remote interfaces
authorRoland Haeder <roland@mxchange.org>
Wed, 25 May 2016 19:18:27 +0000 (21:18 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 25 May 2016 19:18:27 +0000 (21:18 +0200)
src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/validator/birthday/PizzaBirthdayValidator.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/validator/booleans/JobsUserProfileVisibilityValidator.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/validator/names/JobsNameValidator.java [new file with mode: 0644]
src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java [new file with mode: 0644]

diff --git a/src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java b/src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java
new file mode 100644 (file)
index 0000000..5b6f029
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.validator.addressbook;
+
+import java.text.MessageFormat;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
+import org.mxchange.jaddressbookcore.exceptions.AddressbookNotFoundException;
+import org.mxchange.jaddressbookcore.model.addressbook.Addressbook;
+import org.mxchange.jcoreee.validator.number.BaseLongValidator;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+
+/**
+ * A validator for address book id verification
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator (value = "AddressbookIdValidator")
+public class JobsAddressbookIdValidator extends BaseLongValidator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 158_768_467_186_951_809L;
+
+       /**
+        * Remote bean
+        */
+       private AddressbookSessionBeanRemote addressbookBean;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Public consutructor
+        */
+       public JobsAddressbookIdValidator () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+
+                       // ... and user controller
+                       this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("java:global/jjobs-ejb/jjobs-adr!org.mxchange.jjobs.model.addressbook.JobsAddressbookSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // All accepted, required fields
+               String[] requiredFields = {"addressbookId"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // Cast to long
+               Long addressbookId = (Long) value;
+
+               // Is the address book id valid?
+               if (!this.addressbookBean.isAddressbookIdUsed(addressbookId)) {
+                       // Is not valid
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("No address book found with id {0}. Please check your link.", addressbookId))); //NOI18N
+               }
+
+               // Init variable
+               Addressbook addressbook;
+
+               // Try it
+               try {
+                       // Get full data
+                       addressbook = this.addressbookBean.getAddressbookById(addressbookId);
+
+                       // Is it set?
+                       if (null == addressbook) {
+                               // Is null?!
+                               throw new NullPointerException(MessageFormat.format("addressbook for id={0} is null", addressbookId)); //NOI18N
+                       }
+               } catch (final AddressbookNotFoundException ex) {
+                       // Continue to throw
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("Cannot find address book with id {0}", addressbookId)), ex); //NOI18N
+               }
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+}
diff --git a/src/java/org/mxchange/jjobs/validator/birthday/PizzaBirthdayValidator.java b/src/java/org/mxchange/jjobs/validator/birthday/PizzaBirthdayValidator.java
new file mode 100644 (file)
index 0000000..159c904
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.validator.birthday;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreee.validator.date.BaseDateValidator;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+
+/**
+ * A birthday validator
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator("BirthdayValidator")
+public class PizzaBirthdayValidator extends BaseDateValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 28_735_756_819_460L;
+
+       /**
+        * Logger bean
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Default constructor
+        */
+       public PizzaBirthdayValidator () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // All accepted, required fields
+               String[] requiredFields = {"birthday", "contactBirthday"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // Cast value
+               Date birthday = (Date) value;
+
+               // @TODO Finish this, e.g. load maximum,minimum birthday from properties file
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+
+}
diff --git a/src/java/org/mxchange/jjobs/validator/booleans/JobsUserProfileVisibilityValidator.java b/src/java/org/mxchange/jjobs/validator/booleans/JobsUserProfileVisibilityValidator.java
new file mode 100644 (file)
index 0000000..a9d5496
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.validator.booleans;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jcoreee.validator.bool.BaseBooleanValidator;
+
+/**
+ * A validator for user profile visibility
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator (value = "UserProfileVisibilityValidator")
+public class JobsUserProfileVisibilityValidator extends BaseBooleanValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 185_768_717_676_910_450L;
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // All accepted, required fields
+               String[] requiredFields = {"publicUserProfileFlag"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("validate: EXIT!"); //NOI18N
+       }
+
+}
diff --git a/src/java/org/mxchange/jjobs/validator/names/JobsNameValidator.java b/src/java/org/mxchange/jjobs/validator/names/JobsNameValidator.java
new file mode 100644 (file)
index 0000000..5c7b972
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.validator.names;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validation class for addressbook names, such as first name or family name.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator (value = "AddressbookNameValidator")
+public class JobsNameValidator extends BaseStringValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 27_587_896_710_689_451L;
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // All accepted, required fields
+               String[] requiredFields = {"addressbookName"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // Trace message
+               //* NOISY-DEBUG: */ System.out.println("validate: EXIT!"); //NOI18N
+       }
+}
diff --git a/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java b/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java
new file mode 100644 (file)
index 0000000..27f7011
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jjobs.validator.user;
+
+import java.text.MessageFormat;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.enterprise.event.Observes;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.mxchange.jcoreee.validator.number.BaseLongValidator;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
+import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+
+/**
+ * A validator for user ids
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@FacesValidator (value = "UserIdValidator")
+public class JobsUserIdValidator extends BaseLongValidator implements Validator {
+
+       /**
+        * Cached user status
+        */
+       private static final Set<Long> cachedStatus = new TreeSet<>();
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 12_869_569_314_764_690L;
+
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
+       /**
+        * Remote bean
+        */
+       private UserSessionBeanRemote userBean;
+
+       /**
+        * Initialization of this converter
+        */
+       public JobsUserIdValidator () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+
+                       // ... and user controller
+                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
+               }
+       }
+
+       /**
+        * Event fired when the user registration is complete
+        * <p>
+        * @param event User registration event
+        */
+       public void afterRegistrationEvent (@Observes final UserRegisteredEvent event) {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("UserIdValidator:afterRegistrationEvent: event={0} - CALLED!", event)); //NOI18N
+
+               // event should not be null
+               if (null == event) {
+                       // Throw NPE
+                       throw new NullPointerException("event is null"); //NOI18N
+               } else if (event.getRegisteredUser() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("event.user is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() == null) {
+                       // userId is null
+                       throw new NullPointerException("event.user.userId is null"); //NOI18N
+               } else if (event.getRegisteredUser().getUserId() < 1) {
+                       // Not avalid id
+                       throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+               }
+
+               // Get user instance
+               User registeredUser = event.getRegisteredUser();
+
+               // Debug message
+               this.loggerBeanLocal.logDebug(MessageFormat.format("UserIdValidator:afterRegistrationEvent: registeredUser={0}", registeredUser)); //NOI18N
+
+               // Update cache
+               JobsUserIdValidator.cachedStatus.add(registeredUser.getUserId());
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("UserIdValidator:afterRegistrationEvent: EXIT!"); //NOI18N
+       }
+
+       @Override
+       public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Trace message
+               this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+
+               // All accepted, required fields
+               String[] requiredFields = {"userId"}; //NOI18N
+
+               // Pre-validation (example: not null, not a string, empty string ...)
+               super.preValidate(context, component, value, requiredFields, false);
+
+               // Cast value
+               Long userId = (Long) value;
+
+               // Define variable
+               Boolean ifUserExists;
+
+               // Is a map entry there?
+               if (JobsUserIdValidator.cachedStatus.contains(userId)) {
+                       // Get from cache
+                       ifUserExists = Boolean.TRUE;
+               } else {
+                       // Get status
+                       ifUserExists = this.userBean.ifUserIdExists(userId);
+               }
+
+               // Is the user id valid?
+               if (!ifUserExists) {
+                       // Is not valid
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("No user found with id {0}. Please check your link.", userId))); //NOI18N
+               }
+
+               // Add to cache if valid
+               JobsUserIdValidator.cachedStatus.add(userId);
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+
+}