]> git.mxchange.org Git - jshop-core.git/commitdiff
renamed class + removed generic method as it exists in jcustomer-core, too.
authorRoland Häder <roland@mxchange.org>
Wed, 19 Apr 2017 18:54:46 +0000 (20:54 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 19 Apr 2017 18:54:46 +0000 (20:54 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jshopcore/model/customer/CustomerUtils.java [deleted file]
src/org/mxchange/jshopcore/model/customer/ShopCustomerUtils.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java
deleted file mode 100644 (file)
index b0b33f9..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2016 Roland Häder
- *
- * 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.jshopcore.model.customer;
-
-import java.sql.SQLException;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityNotFoundException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.digest.Sha2Crypt;
-import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.jshopcore.model.order.Orderable;
-import org.mxchange.jshopcore.model.order.ShopOrder;
-
-/**
- * An utilities class for customers
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class CustomerUtils {
-
-       /**
-        * Generates an unique access key.
-        * <p>
-        * @param em       Entity manager instance
-        * @param customer Customer instance
-        * <p>
-        * @return An unique access key
-        */
-       public static String generateAccessKey (final EntityManager em, final Customer customer) {
-               // Trace message
-               // @TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: connection={0} - CALLED!", connection));
-
-               // em cannot be null
-               if (null == em) {
-                       // Abort here
-                       throw new NullPointerException("em is null"); //NOI18N
-               } else if (!em.isOpen()) {
-                       // Not open
-                       throw new IllegalStateException("Entity manager is closed.");
-               }
-
-               // Generate fake order instance
-               Orderable orderable = null;
-
-               // Generate access keyy
-               String accessKey = null;
-
-               // Default is found
-               boolean isFound = true;
-
-               // Is the number used?
-               while (isFound) {
-                       // Both number parts
-                       String randString = String.format("%s:%s:%s", Long.toHexString(Math.round(Math.random() * 1_000_000)), em, customer.getCustomerNumber());
-
-                       // Generate access key, use SHA512 hashing and BASE64-encoding for strong key generation
-                       accessKey = Base64.encodeBase64String(Sha2Crypt.sha512Crypt(randString.getBytes()).getBytes()).substring(0, 100);
-
-                       // Try this
-                       try {
-                               // Get reference
-                               orderable = em.getReference(ShopOrder.class, accessKey);
-                       } catch (final EntityNotFoundException ex) {
-                               // Not found, so abort loop here
-                               isFound = false;
-                       }
-               }
-
-               // Trace message
-               // @TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: accessKey={0} - EXIT!", accessKey));
-               // Found one
-               return accessKey;
-       }
-
-       /**
-        * Generates an unique customer number by checking is existence
-        * <p>
-        * @param em Entity manager instance
-        * <p>
-        * @return Generated customer number (not used before)
-        * <p>
-        * @throws java.sql.SQLException If any SQL error occured
-        */
-       public static String generateCustomerNumber (final EntityManager em) throws SQLException {
-               // Trace message
-               // @TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: connection={0} - CALLED!", connection));
-
-               // em cannot be null
-               if (null == em) {
-                       // Abort here
-                       throw new NullPointerException("em is null"); //NOI18N
-               } else if (!em.isOpen()) {
-                       // Not open
-                       throw new IllegalStateException("Entity manager is closed.");
-               }
-
-               // Generate number
-               String customerNumber = null;
-
-               // Default is found
-               boolean isFound = true;
-
-               // Is the number used?
-               while (isFound) {
-                       // Both number parts
-                       long part1 = Math.round(Math.random() * 100_000);
-                       long part2 = Math.round(Math.random() * 1_000);
-
-                       // Generate new number
-                       customerNumber = String.format("%s-%s", part1, part2); //NOI18N
-
-                       // Try it
-                       try {
-                               // Get instance
-                               Customer customer = em.getReference(Customer.class, customerNumber);
-                       } catch (final EntityNotFoundException ex) {
-                               // Not found
-                               isFound = false;
-                       }
-               }
-
-               // Trace message
-               // @TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
-               // Found one
-               return customerNumber;
-       }
-
-       /**
-        * Private constructor
-        */
-       private CustomerUtils () {
-               // Prevents making instances from utilities classes
-       }
-
-}
diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomerUtils.java
new file mode 100644 (file)
index 0000000..145fa85
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2016 Roland Häder
+ *
+ * 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.jshopcore.model.customer;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.digest.Sha2Crypt;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jshopcore.model.order.Orderable;
+import org.mxchange.jshopcore.model.order.ShopOrder;
+
+/**
+ * An utilities class for customers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ShopCustomerUtils {
+
+       /**
+        * Generates an unique access key.
+        * <p>
+        * @param em       Entity manager instance
+        * @param customer Customer instance
+        * <p>
+        * @return An unique access key
+        */
+       public static String generateAccessKey (final EntityManager em, final Customer customer) {
+               // em cannot be null
+               if (null == em) {
+                       // Abort here
+                       throw new NullPointerException("em is null"); //NOI18N
+               } else if (!em.isOpen()) {
+                       // Not open
+                       throw new IllegalStateException("Entity manager is closed.");
+               }
+
+               // Generate fake order instance
+               Orderable orderable = null;
+
+               // Generate access keyy
+               String accessKey = null;
+
+               // Default is found
+               boolean isFound = true;
+
+               // Is the number used?
+               while (isFound) {
+                       // Both number parts
+                       String randString = String.format("%s:%s:%s", Long.toHexString(Math.round(Math.random() * 1_000_000)), em, customer.getCustomerNumber());
+
+                       // Generate access key, use SHA512 hashing and BASE64-encoding for strong key generation
+                       accessKey = Base64.encodeBase64String(Sha2Crypt.sha512Crypt(randString.getBytes()).getBytes()).substring(0, 100);
+
+                       // Try this
+                       try {
+                               // Get reference
+                               orderable = em.getReference(ShopOrder.class, accessKey);
+                       } catch (final EntityNotFoundException ex) {
+                               // Not found, so abort loop here
+                               isFound = false;
+                       }
+               }
+
+               // Found one
+               return accessKey;
+       }
+
+       /**
+        * Private constructor
+        */
+       private ShopCustomerUtils () {
+               // Prevents making instances from utilities classes
+       }
+
+}