]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
renamed to have project's name in + added missing dependencies juser-core/lib
authorRoland Häder <roland@mxchange.org>
Fri, 20 May 2016 14:59:40 +0000 (16:59 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 21 May 2016 12:05:36 +0000 (14:05 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java [new file with mode: 0644]
src/org/mxchange/addressbook/validator/user/UserIdValidator.java [deleted file]

index 204c33bee68b7509ada59a8fa39f179ca2f1b69d..d616ac6f1863f78ad2b51139b8b2f3bba18c8ed3 100644 (file)
@@ -38,9 +38,11 @@ file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
 file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
 file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
+file.reference.jcountry-lib.jar=lib\\jcountry-lib.jar
 file.reference.jphone-core.jar=lib/jphone-core.jar
 file.reference.juser-core.jar=lib/juser-core.jar
 file.reference.juser-lib.jar=lib/juser-lib.jar
+file.reference.addressbook-core.jar=lib/addressbook-core.jar
 includes=**
 jar.archive.disabled=${jnlp.enabled}
 jar.compress=false
@@ -57,8 +59,8 @@ javac.classpath=\
     ${file.reference.jaddressbook-core.jar}:\
     ${file.reference.jaddressbook-lib.jar}:\
     ${file.reference.addressbook-core.jar}:\
-    ${libs.javaee-api-7.0.classpath}:\
-    ${libs.jpa20-persistence.classpath}
+    ${file.reference.jcountry-lib.jar}:\
+    ${libs.javaee-api-7.0.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
 javac.deprecation=true
@@ -116,8 +118,10 @@ source.reference.jcontacts-core.jar=../jcontacts-core/src/
 source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
 source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
+source.reference.jcountry-lib.jar=../jcountry-lib/src/
 source.reference.jphone-core.jar=../jphone-core/src/
 source.reference.juser-core.jar=../juser-core/src/
 source.reference.juser-lib.jar=../juser-lib/src/
+source.reference.addressbook-core.jar=../addressbook-core/src/
 src.dir=src
 test.src.dir=test
diff --git a/src/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java b/src/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java
new file mode 100644 (file)
index 0000000..1644d61
--- /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.addressbook.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 AddressbookUserIdValidator 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 AddressbookUserIdValidator () {
+               // 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/jlandingpage-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 (final @Observes 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
+               AddressbookUserIdValidator.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 (AddressbookUserIdValidator.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
+               AddressbookUserIdValidator.cachedStatus.add(userId);
+
+               // Trace message
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+
+}
diff --git a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java
deleted file mode 100644 (file)
index d273aca..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.addressbook.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 UserIdValidator 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 UserIdValidator () {
-               // 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/addressbook-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 (final @Observes 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
-               UserIdValidator.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 (UserIdValidator.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
-               UserIdValidator.cachedStatus.add(userId);
-
-               // Trace message
-               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
-       }
-
-}