* @param object Other object to check
*/
@Override
- public boolean equals (final Object object);
+ boolean equals (final Object object);
/**
* Getter for item amount
* <p>
* @return the amount
*/
- public Long getOrderedAmount ();
+ Long getOrderedAmount ();
/**
* Setter for item amount
* <p>
* @param amount the amount to set
*/
- public void setOrderedAmount (final Long amount);
+ void setOrderedAmount (final Long amount);
/**
* Getter for entry id (from database backend)
* <p>
* @return the id
*/
- public Long getItemId ();
+ Long getItemId ();
/**
* Setter for entry id (from database backend)
* <p>
* @param id the id to set
*/
- public void setItemId (final Long id);
+ void setItemId (final Long id);
/**
* Getter for item type
* <p>
* @return the type
*/
- public String getItemType ();
+ String getItemType ();
/**
* Setter for item type
* <p>
* @param type the type to set
*/
- public void setItemType (final String type);
+ void setItemType (final String type);
/**
* Getter for product instance
* <p>
* @return the product
*/
- public Product getItemProduct ();
+ Product getItemProduct ();
/**
* Setter fo product instance
* <p>
* @param product the product to set
*/
- public void setItemProduct (final Product product);
+ void setItemProduct (final Product product);
/**
* Hash-code calculattion
*/
@Override
- public int hashCode ();
+ int hashCode ();
/**
* Determines whether the item has a Product instance set
* <p>
* @return Whether a Product instance is set
*/
- public boolean isProductType ();
+ boolean isProductType ();
}
* @throws org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException
* If the item instance has already been added
*/
- public void addItem (final T item) throws BasketItemAlreadyAddedException;
+ void addItem (final T item) throws BasketItemAlreadyAddedException;
/**
* Clears the basket instance
*/
- public void clear ();
+ void clear ();
/**
* Some "getter" for all entries in this basket
* <p>
* @return Map on all basket items
*/
- public List<T> getAll ();
+ List<T> getAll ();
/**
* Getter for last entry
* <p>
* @return Last added item in basket
*/
- public T getLast ();
+ T getLast ();
/**
* Getter for last num rows
* <p>
* @return Last num rows
*/
- public int getLastNumRows ();
+ int getLastNumRows ();
/**
* Checks whether the given item has already been added by checking the
* <p>
* @return Whether the given item has been found
*/
- public boolean isAdded (final T item);
+ boolean isAdded (final T item);
/**
* Checks if the basket is empty
* <p>
* @return Whether the basket is empty
*/
- public boolean isEmpty ();
+ boolean isEmpty ();
}
* <p>
* @param category Source category instance
*/
- public void copyAll (final Category category);
+ void copyAll (final Category category);
/**
* Id number of category
* <p>
* @return the id
*/
- public Long getCategoryId ();
+ Long getCategoryId ();
/**
* Id number of category
* <p>
* @param id the id to set
*/
- public void setCategoryId (final Long id);
+ void setCategoryId (final Long id);
/**
* Parent category
* <p>
* @return the parent category
*/
- public Category getParentCategory ();
+ Category getParentCategory ();
/**
* Parent category
* <p>
* @param parentCategory the parent category to set
*/
- public void setParentCategory (final Category parentCategory);
+ void setParentCategory (final Category parentCategory);
/**
* Title of category
* <p>
* @return the title
*/
- public String getCategoryTitle ();
+ String getCategoryTitle ();
/**
* Title of category
* <p>
* @param title the title to set
*/
- public void setCategoryTitle (final String title);
+ void setCategoryTitle (final String title);
}
* <p>
* @param customer Source instance
*/
- public void copyAll (final Customer customer);
+ void copyAll (final Customer customer);
/**
* Getter for contact instance
* <p>
* @return Contact id number
*/
- public Contact getContact ();
+ Contact getContact ();
/**
* Setter for contact instance
* <p>
* @param contact Contact instance
*/
- public void setContact (final Contact contact);
+ void setContact (final Contact contact);
/**
* Getter for confirmation key
* <p>
* @return Confirmation key
*/
- public String getCustomerConfirmKey ();
+ String getCustomerConfirmKey ();
/**
* Setter for confirmation key
* <p>
* @param customerConfirmKey Confirmation key
*/
- public void setCustomerConfirmKey (final String customerConfirmKey);
+ void setCustomerConfirmKey (final String customerConfirmKey);
/**
* Getter for "created" timestamp
* <p>
* @return "created" timestamp
*/
- public Calendar getCustomerCreated ();
+ Calendar getCustomerCreated ();
/**
* Setter for "created" timestamp
* <p>
* @param customerCreated "created" timestamp
*/
- public void setCustomerCreated (final Calendar customerCreated);
+ void setCustomerCreated (final Calendar customerCreated);
/**
* Getter for customer id number
* <p>
* @return Customer id number
*/
- public Long getCustomerId ();
+ Long getCustomerId ();
/**
* Settte for customer id number
* <p>
* @param customerId Customer id number
*/
- public void setCustomerId (final Long customerId);
+ void setCustomerId (final Long customerId);
/**
* Getter for "locked" timestamp
* <p>
* @return "locked" timestamp
*/
- public Calendar getCustomerLocked ();
+ Calendar getCustomerLocked ();
/**
* Getter for "locked" timestamp
* <p>
* @param customerLocked "locked" timestamp
*/
- public void setCustomerLocked (final Calendar customerLocked);
+ void setCustomerLocked (final Calendar customerLocked);
/**
* Getter for customer number
* <p>
* @return Customer number
*/
- public String getCustomerNumber ();
+ String getCustomerNumber ();
/**
* Setter for customer number
* <p>
* @param customerNumber Customer number
*/
- public void setCustomerNumber (final String customerNumber);
+ void setCustomerNumber (final String customerNumber);
/**
* Getter for password hash
* <p>
* @return Password hash
*/
- public String getCustomerPasswordHash ();
+ String getCustomerPasswordHash ();
/**
* Setter for password hash
* <p>
* @param customerPasswordHash Password hash
*/
- public void setCustomerPasswordHash (final String customerPasswordHash);
+ void setCustomerPasswordHash (final String customerPasswordHash);
/**
* Getter for account status
* <p>
* @return Account status
*/
- public CustomerAccountStatus getCustomerAccountStatus ();
+ CustomerAccountStatus getCustomerAccountStatus ();
/**
* Setter for account status
* <p>
* @param customerStatus Account status
*/
- public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus);
+ void setCustomerAccountStatus (final CustomerAccountStatus customerStatus);
}
public class CustomerUtils extends BaseFrameworkSystem {
/**
- * No instance from this class
- */
- private CustomerUtils () {
- }
-
- /**
- * Generates an unique customer number by checking is existence
+ * Generates an unique access key.
* <p>
* @param em Entity manager instance
+ * @param customer Customer instance
* <p>
- * @return Generated customer number (not used before)
- * <p>
- * @throws java.sql.SQLException If any SQL error occured
+ * @return An unique access key
*/
- public static String generateCustomerNumber (final EntityManager em) throws SQLException {
+ public static String generateAccessKey (final EntityManager em, final Customer customer) {
// Trace message
- // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: connection={0} - CALLED!", connection));
+ // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: connection={0} - CALLED!", connection));
// em cannot be null
if (null == em) {
// Not open
throw new IllegalStateException("Entity manager is closed.");
}
-
- // Generate number
- String customerNumber = null;
-
+
+ // 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
- 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
+ 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 instance
- Customer customer = em.getReference(ShopCustomer.class, customerNumber);
+ // Get reference
+ orderable = em.getReference(ShopOrder.class, accessKey);
} catch (final EntityNotFoundException ex) {
- // Not found
+ // Not found, so abort loop here
isFound = false;
}
}
// Trace message
- // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
+ // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: accessKey={0} - EXIT!", accessKey));
// Found one
- return customerNumber;
+ return accessKey;
}
/**
- * Generates an unique access key.
+ * Generates an unique customer number by checking is existence
* <p>
* @param em Entity manager instance
- * @param customer Customer instance
* <p>
- * @return An unique access key
+ * @return Generated customer number (not used before)
+ * <p>
+ * @throws java.sql.SQLException If any SQL error occured
*/
- public static String generateAccessKey (final EntityManager em, final Customer customer) {
+ public static String generateCustomerNumber (final EntityManager em) throws SQLException {
// Trace message
- // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: connection={0} - CALLED!", connection));
+ // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: connection={0} - CALLED!", connection));
// em cannot be null
if (null == em) {
throw new IllegalStateException("Entity manager is closed.");
}
- // Generate fake order instance
- Orderable orderable = null;
-
- // Generate access keyy
- String accessKey = null;
+ // Generate number
+ String customerNumber = 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());
+ long part1 = Math.round(Math.random() * 100_000);
+ long part2 = Math.round(Math.random() * 1_000);
- // Generate access key, use SHA512 hashing and BASE64-encoding for strong key generation
- accessKey = Base64.encodeBase64String(Sha2Crypt.sha512Crypt(randString.getBytes()).getBytes()).substring(0, 100);
+ // Generate new number
+ customerNumber = String.format("%s-%s", part1, part2); //NOI18N
- // Try this
+ // Try it
try {
- // Get reference
- orderable = em.getReference(ShopOrder.class, accessKey);
+ // Get instance
+ Customer customer = em.getReference(ShopCustomer.class, customerNumber);
} catch (final EntityNotFoundException ex) {
- // Not found, so abort loop here
+ // Not found
isFound = false;
}
}
// Trace message
- // TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: accessKey={0} - EXIT!", accessKey));
+ // TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
// Found one
- return accessKey;
+ return customerNumber;
+ }
+
+ /**
+ * No instance from this class
+ */
+ private CustomerUtils () {
}
}
* <p>
* @return Access key
*/
- public String getAccessKey ();
+ String getAccessKey ();
/**
* Setter for access key
* <p>
* @param accessKey Access key
*/
- public void setAccessKey (final String accessKey);
+ void setAccessKey (final String accessKey);
/**
* Getter for created timestamp
* <p>
* @return Created timestamp
*/
- public Calendar getOrderCreated ();
+ Calendar getOrderCreated ();
/**
* Setter for created timestamp
* <p>
* @param created Created timestamp
*/
- public void setOrderCreated (final Calendar created);
+ void setOrderCreated (final Calendar created);
/**
* Getter for customer instance
* <p>
* @return Customer instance
*/
- public Customer getCustomer ();
+ Customer getCustomer ();
/**
* Setter for customer instance
* <p>
* @param customer Customer instance
*/
- public void setCustomer (final Customer customer);
+ void setCustomer (final Customer customer);
/**
* Getter for order id
* <p>
* @return Order id
*/
- public Long getOrderId ();
+ Long getOrderId ();
/**
* Setter for order id
* <p>
* @param id Order id
*/
- public void setOrderId (final Long id);
+ void setOrderId (final Long id);
/**
* Getter for list of ordered basket items
* <p>
* @return List of items
*/
- public List<AddableBasketItem> getOrderedItems ();
+ List<AddableBasketItem> getOrderedItems ();
/**
* Setter for list of ordered basket items
* <p>
* @param orderedItems List of ordered items
*/
- public void setOrderedItems (final List<AddableBasketItem> orderedItems);
+ void setOrderedItems (final List<AddableBasketItem> orderedItems);
}
* <p>
* @param product Source product
*/
- public void copyAll (final Product product);
+ void copyAll (final Product product);
/**
* Getter for product availability
* <p>
* @return Product availability
*/
- public Boolean getProductAvailability ();
+ Boolean getProductAvailability ();
/**
* Setter for product availability
* <p>
* @param productAvailability Product availability
*/
- public void setProductAvailability (final Boolean productAvailability);
+ void setProductAvailability (final Boolean productAvailability);
/**
* Getter for product category id
* <p>
* @return Product category id
*/
- public Category getProductCategory ();
+ Category getProductCategory ();
/**
* Setter for product category
* <p>
* @param productCategory Product category
*/
- public void setProductCategory (final Category productCategory);
+ void setProductCategory (final Category productCategory);
/**
* Getter for id number, suitable for form fields.
* <p>
* @return Id number of product
*/
- public Long getProductId ();
+ Long getProductId ();
/**
* Id number of product
* <p>
* @param productId the id number to set
*/
- public void setProductId (final Long productId);
+ void setProductId (final Long productId);
/**
* Getter for raw price.
* <p>
* @return Single price of product
*/
- public Float getProductPrice ();
+ Float getProductPrice ();
/**
* Price of product
* <p>
* @param productPrice the price to set
*/
- public void setProductPrice (final Float productPrice);
+ void setProductPrice (final Float productPrice);
/**
* Getter for title.
* <p>
* @return Title of product
*/
- public String getProductTitle ();
+ String getProductTitle ();
/**
* Title of product
* <p>
* @param productTitle the title to set
*/
- public void setProductTitle (final String productTitle);
+ void setProductTitle (final String productTitle);
}
* <p>
* @return Customer indstance
*/
- public Customer getCustomer ();
+ Customer getCustomer ();
/**
* Setter for customer instance
* <p>
* @param customer Customer instance
*/
- public void setCustomer (final Customer customer);
+ void setCustomer (final Customer customer);
/**
* Getter for a List of AddableBasktem instances
* <p>
* @return List with AddableBasketItem instances
*/
- public List<AddableBasketItem> getList ();
+ List<AddableBasketItem> getList ();
/**
* Setter for a List of AddableBasktem instances
* <p>
* @param list List with AddableBasketItem instances
*/
- public void setList (final List<AddableBasketItem> list);
+ void setList (final List<AddableBasketItem> list);
}