]> git.mxchange.org Git - pizzaservice-ejb.git/commitdiff
Please cherry-pick/rename:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Mar 2018 22:05:44 +0000 (23:05 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 15 Jul 2019 05:11:20 +0000 (07:11 +0200)
- Headquarter is enough for bean name (please rename)
- removed some no longer recommended business methods
- removed no longer used private methods
- made some local variables final which helps the Java compiler in optimization
  of resulting byte-code
- added session EJB for user activity
- other improvements (?)
- changed/updated copyright to Free Software Foundation

Signed-off-by: Roland Häder <roland@mxchange.org>
48 files changed:
src/java/log4j2.xml
src/java/org/mxchange/jcontacts/model/contact/PizzaAdminContactSessionBean.java
src/java/org/mxchange/jcontacts/model/contact/PizzaContactSessionBean.java
src/java/org/mxchange/jcontacts/model/phone/PizzaAdminContactPhoneSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaAdminBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/basicdata/PizzaBusinessDataSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaAdminBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/branchoffice/PizzaBranchOfficeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/PizzaAdminDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/department/PizzaDepartmentSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/PizzaAdminEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/employee/PizzaEmployeeSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaHeadquarterSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaAdminHeadquartersSessionBean.java [deleted file]
src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaHeadquartersSessionBean.java [deleted file]
src/java/org/mxchange/jcontactsbusiness/model/opening_time/PizzaAdminOpeningTimesSessionBean.java
src/java/org/mxchange/jcontactsbusiness/model/opening_time/PizzaOpeningTimesSessionBean.java
src/java/org/mxchange/jcountry/model/data/PizzaAdminCountrySingletonBean.java
src/java/org/mxchange/jcountry/model/data/PizzaCountrySingletonBean.java
src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaAdminMobileProviderSessionBean.java
src/java/org/mxchange/jphone/model/phonenumbers/mobileprovider/PizzaMobileProviderSingletonBean.java
src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaAdminPhoneSessionBean.java
src/java/org/mxchange/jphone/model/phonenumbers/phone/PizzaPhoneSessionBean.java
src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jproduct/model/category/PizzaProductCategorySessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jproduct/model/product/PizzaGenericProductSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jshopreceipt/receipt/PdfReceiptBean.java
src/java/org/mxchange/jshopreceipt/receipt/ReceiptFactory.java
src/java/org/mxchange/jusercore/model/user/PizzaAdminUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/PizzaUserSessionBean.java
src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivityLogMessageBean.java
src/java/org/mxchange/jusercore/model/user/activity/PizzaUserActivitySessionBean.java
src/java/org/mxchange/jusercore/model/user/email_address/PizzaUserEmailChangeSessionBean.java
src/java/org/mxchange/jusercore/model/user/password_history/PizzaUserPasswordHistorySessionBean.java
src/java/org/mxchange/juserlogincore/model/user/login/PizzaUserLoginSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/register/PizzaUserRegistrationSessionBean.java
src/java/org/mxchange/juserlogincore/model/user/resendlink/PizzaResendLinkSessionBean.java
src/java/org/mxchange/pizzaapplication/enterprise/BasePizzaEnterpriseBean.java
src/java/org/mxchange/pizzaapplication/model/basket/PizzaBasketSessionBean.java
src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/model/checkout/PizzaCheckoutMessageBean.java
src/java/org/mxchange/pizzaapplication/model/customer/PizzaAdminCustomerSessionBean.java
src/java/org/mxchange/pizzaapplication/model/customer/PizzaCustomerSessionBean.java
src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java [deleted file]
src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java [deleted file]

index 98e9a65f642174f1e53f38823251423cf6e9f0d3..90439ed601d6c2526267e601e8531774159f6c0b 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-Copyright (C) 2016, 2017 Roland Häder
+Copyright (C) 2016 - 2018 Free Software Foundation
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
index faa9092d2280385e7766c9c22fc274ef7c02d9ca..6317ad61f57f7356e420b14680edf306106c17c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -23,7 +23,7 @@ import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * An administrative contact EJB
index 6eb664935ec325dd33f803aadb21ef3dfc9144a6..ac0c522cd05dd6451c42752cc25a3c20af69ee11 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -24,7 +24,7 @@ import javax.ejb.Stateless;
 import javax.persistence.NoResultException;
 import javax.persistence.Query;
 import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 /**
  * A contact EJB
  * <p>
@@ -65,62 +65,6 @@ public class PizzaContactSessionBean extends BasePizzaEnterpriseBean implements
                return contacts;
        }
 
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<String> allEmailAddresses () {
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList - CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Create query instance
-               final Query query = this.getEntityManager().createNamedQuery("AllContactEmailAddresses"); //NOI18N
-
-               // Get list
-               final List<String> emailAddresses = query.getResultList();
-
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddresses.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddresses.size())); //NOI18N
-
-               // Return it
-               return emailAddresses;
-       }
-
-       @Override
-       public boolean isEmailAddressRegistered (final String emailAddress) {
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
-
-               // The email address should be valid
-               if (null == emailAddress) {
-                       // Is null
-                       throw new NullPointerException("emailAddress is null"); //NOI18N
-               } else if (emailAddress.isEmpty()) {
-                       // Is empty
-                       throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
-               }
-
-               // Default is not found
-               boolean isFound = false;
-
-               try {
-                       // Ask other method for contact instance
-                       final Contact contact = this.findContactByEmailAddress(emailAddress);
-
-                       // Log debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.isEmailAddressRegistered: Found contact={1} for emailAddress={2}", this.getClass().getSimpleName(), contact, emailAddress)); //NOI18N
-
-                       // It is found ...
-                       isFound = true;
-               } catch (final ContactNotFoundException ex) {
-                       // @TODO Was not found, log exception for spam check?
-               }
-
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.isEmailAddressRegistered: isFound={1} - EXIT!", this.getClass().getSimpleName(), isFound)); //NOI18N
-
-               // Return status
-               return isFound;
-       }
-
        @Override
        public Contact lookupContact (final Contact contact) {
                // Log trace message
@@ -159,7 +103,7 @@ public class PizzaContactSessionBean extends BasePizzaEnterpriseBean implements
                // Loop through all
                while (iterator.hasNext()) {
                        // Get contact
-                       Contact next = iterator.next();
+                       final Contact next = iterator.next();
 
                        // Is same contact?
                        if ((Objects.equals(contact, next)) || (ContactUtils.isSameContact(contact, next))) {
@@ -200,7 +144,7 @@ public class PizzaContactSessionBean extends BasePizzaEnterpriseBean implements
                this.setAllContactPhoneEntriesUpdated(contact, isCellphoneUnlinked, isLandlineUnlinked, isFaxUnlinked);
 
                // Merge mobile, land-line and fix
-               Contact detachedContact = this.mergeContactData(contact);
+               final Contact detachedContact = this.mergeContactData(contact);
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
@@ -227,12 +171,12 @@ public class PizzaContactSessionBean extends BasePizzaEnterpriseBean implements
                }
 
                // Is cell phone/land-line/fax number unlinked?
-               boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null);
-               boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null);
-               boolean isFaxUnlinked = (contact.getContactFaxNumber() == null);
+               final boolean isCellphoneUnlinked = (contact.getContactMobileNumber() == null);
+               final boolean isLandLineUnlinked = (contact.getContactLandLineNumber() == null);
+               final boolean isFaxUnlinked = (contact.getContactFaxNumber() == null);
 
                // Call other Method
-               Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked);
+               final Contact detachedContact = this.updateContactData(contact, isCellphoneUnlinked, isLandLineUnlinked, isFaxUnlinked);
 
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateContactData: detachedContact={1} - EXIT!", this.getClass().getSimpleName(), detachedContact)); //NOI18N
@@ -241,57 +185,6 @@ public class PizzaContactSessionBean extends BasePizzaEnterpriseBean implements
                return detachedContact;
        }
 
-       /**
-        * Returns a contact instance which has the given email address.
-        * <p>
-        * @param emailAddress Email address
-        * <p>
-        * @return Contact instance
-        * <p>
-        * @throws ContactNotFoundException If the contact was not found
-        */
-       private Contact findContactByEmailAddress (final String emailAddress) throws ContactNotFoundException {
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: emailAddress={1} - CALLED!", this.getClass().getSimpleName(), emailAddress)); //NOI18N
-
-               // The parameter must be valid
-               if (null == emailAddress) {
-                       // Throw NPE
-                       throw new NullPointerException("emailAddress is null"); //NOI18N
-               } else if (emailAddress.isEmpty()) {
-                       // Not valid
-                       throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
-               }
-
-               // Get query instance
-               final Query query = this.getEntityManager().createNamedQuery("SearchContactByEmailAddress", UserContact.class); //NOI18N
-
-               // Set parameter and limit
-               query.setParameter("emailAddress", emailAddress); //NOI18N
-               query.setMaxResults(1);
-
-               // Init contact instance
-               final Contact contact;
-
-               // Try to find a result
-               try {
-                       // Find a single result
-                       contact = (Contact) query.getSingleResult();
-
-                       // Log trace message
-                       this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: Found contact={1}", this.getClass().getSimpleName(), contact)); //NOI18N
-               } catch (final NoResultException ex) {
-                       // No result found
-                       throw new ContactNotFoundException(emailAddress, ex);
-               }
-
-               // Log trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.findContactByEmailAddress: contact={1} - EXIT!", this.getClass().getSimpleName(), contact)); //NOI18N
-
-               // Return found instance
-               return contact;
-       }
-
        /**
         * Returns a contact instance which has the given id number.
         * <p>
index 5386da4cd78a3adbc8e1706a3b52d4221dc8bc6e..293855e4051d938632840f353915950c3cf85abf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -28,7 +28,7 @@ import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException;
 import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A session EJB for administrative contact's phone number purposes
index a35b11324b2494234abcc45ec7b8a05faa29e496..ca87ac01e2540b512c7d872e43912ba606db9c52 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -24,8 +24,9 @@ import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
 import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * An administrative stateless session bean for business data
@@ -101,6 +102,15 @@ public class PizzaAdminBusinessDataSessionBean extends BasePizzaEnterpriseBean i
                        basicData.setCompanyContactEmployee(managedEmployee);
                }
 
+               // Is a headquarter set?
+               if (basicData.getCompanyHeadquarterData()instanceof Headquarter) {
+                       // Get managed instance
+                       final Headquarter managedHeadquarter = this.createManaged(basicData.getCompanyHeadquarterData());
+
+                       // Set it back
+                       basicData.setCompanyHeadquarterData(managedHeadquarter);
+               }
+
                // Set created timestamps for any assigned numbers
                this.setAllPhoneEntriesCreated(basicData);
 
index 3cae7d68ff3644bd8f720fc6cb98cc6d0ceb6e03..cc114134136a0a6fc6b9ae47ccfe57f751200912 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for business data
index c0d50004ceb49edaab796b7c62f678b59c84aaf0..497ddec1c3d79da7b076ffd9d4307fa9ce33f4f9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -22,10 +22,11 @@ import java.util.List;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
 import org.mxchange.jcountry.model.data.Country;
 import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 
 /**
index 185f4bcbcc339a7ecff75e5696679a2461c7472c..099bf6566a97f2da5fb2d6d33c7824c560af872d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for general branch office purposes
index d5bb9273a528e92b9d67c709dffe9baca6c30cfe..cf15b7f5f2b3a8cec2b85352065671b9f76e06a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -22,12 +22,12 @@ import java.util.List;
 import javax.ejb.EJB;
 import javax.ejb.Stateless;
 import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
-import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jcontactsbusiness.model.employee.Employable;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
-import org.mxchange.jcontactsbusiness.model.headquarters.Headquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for administrative department purposes
@@ -106,13 +106,13 @@ public class PizzaAdminDepartmentSessionBean extends BasePizzaEnterpriseBean imp
                        department.setDepartmentBranchOffice(managedBranchOffice);
                }
 
-               // Is headquarters set?
-               if (department.getDepartmentHeadquarters() instanceof Headquarter) {
-                       // Get managed headquarters
-                       final Headquarter managedHeadquarters = this.createManaged(department.getDepartmentHeadquarters());
+               // Is headquarter set?
+               if (department.getDepartmentHeadquarter() instanceof Headquarter) {
+                       // Get managed headquarter
+                       final Headquarter managedHeadquarter = this.createManaged(department.getDepartmentHeadquarter());
 
                        // Set it back
-                       department.setDepartmentHeadquarters(managedHeadquarters);
+                       department.setDepartmentHeadquarter(managedHeadquarter);
                }
 
                // Is lead employee set?
index 777e4a317b7a97ef5a51933245ebb8a779981313..e41518c0b9d925c984495bdfccf611f140afc7f5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for general department purposes
index 54761b59ce3aead4ad95a96824df424ae6409a3c..7eecf34dffb19bc5b94c70176f5adaf53125c2ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
  */
 package org.mxchange.jcontactsbusiness.model.employee;
 
+import java.text.MessageFormat;
+import java.util.Date;
+import javax.ejb.EJB;
 import javax.ejb.Stateless;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.jobposition.JobPosition;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless bean for administrative purposes for company employees.
@@ -32,6 +44,12 @@ public class PizzaAdminEmployeeSessionBean extends BasePizzaEnterpriseBean imple
         */
        private static final long serialVersionUID = 26_458_796_703_761L;
 
+       /**
+        * EJB for general company employee purposes
+        */
+       @EJB (lookup = "java:global/pizzaapplication-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote")
+       private EmployeeSessionBeanRemote employeeBean;
+
        /**
         * Default constructor
         */
@@ -39,4 +57,191 @@ public class PizzaAdminEmployeeSessionBean extends BasePizzaEnterpriseBean imple
                super();
        }
 
+       @Override
+       public Employable addEmployee (final Employable employee) throws EmployeeAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addEmployee(): employee={1} - CALLED!", this.getClass().getSimpleName(), employee)); //NOI18N
+
+               // Validate parameter
+               if (null == employee) {
+                       // Throw NPE
+                       throw new NullPointerException("employee is null"); //NOI18N
+               } else if (employee.getEmployeeId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeId={0} is unexpected.", employee.getEmployeeId())); //NOI18N
+               } else if (employee.getEmployeeCompany() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeeCompany is null"); //NOI18N
+               } else if (employee.getEmployeeCompany().getBasicDataId() == null) {
+                       // Throw it again
+                       throw new NullPointerException("employee.employeeCompany.basicDataId is null"); //NOI18N
+               } else if (employee.getEmployeeCompany().getBasicDataId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeCompany.basicDataId={0} is invalid.", employee.getEmployeeCompany().getBasicDataId())); //NOI18N
+               } else if (employee.getEmployeeBranchOffice() == null && employee.getEmployeeDepartment() == null && employee.getEmployeeHeadquarter() == null) {
+                       // At least one must be set
+                       throw new NullPointerException("employee.employeeBranchOffice, employee.employeeDepartment and employee.employeeHeadquarter is null"); //NOI18N
+               } else if (employee.getEmployeeBranchOffice() != null && employee.getEmployeeBranchOffice().getBranchId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeeBranchOffice.branchId is null"); //NOI18N
+               } else if (employee.getEmployeeBranchOffice() != null && employee.getEmployeeBranchOffice().getBranchId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeBranchOffice.branchId={0} is invalid.", employee.getEmployeeBranchOffice().getBranchId())); //NOI18N
+               } else if (employee.getEmployeeDepartment() != null && employee.getEmployeeDepartment().getDepartmentId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeeDepartment.departmentId is null"); //NOI18N
+               } else if (employee.getEmployeeDepartment() != null && employee.getEmployeeDepartment().getDepartmentId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeDepartment.departmentId={0} is invalid.", employee.getEmployeeDepartment().getDepartmentId())); //NOI18N
+               } else if (employee.getEmployeeHeadquarter() != null && employee.getEmployeeHeadquarter().getHeadquarterId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeeHeadquarter.headquarterId is null"); //NOI18N
+               } else if (employee.getEmployeeHeadquarter() != null && employee.getEmployeeHeadquarter().getHeadquarterId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeHeadquarter.headquarterId={0} is invalid.", employee.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N
+               } else if ((employee.getEmployeePersonalData() == null) && (employee.getEmployeeNumber() == null)) {
+                       // Both are null
+                       throw new NullPointerException("employee.employeePersonalData and employee.employeeNumber are null"); //NOI18N
+               } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() == null)) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeePersonalData.contactId is null"); //NOI18N
+               } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeePersonalData.contactId={0} is invalid.", employee.getEmployeePersonalData().getContactId())); //NOI18N
+               } else if ((employee.getEmployeeNumber() != null) && (employee.getEmployeeNumber().isEmpty())) {
+                       // Throw it again
+                       throw new IllegalArgumentException("employee.employeeNumber is empty"); //NOI18N
+               } else if ((employee.getEmployeeMobileNumber() != null) && (employee.getEmployeeMobileNumber().getPhoneId() != null)) {
+                       // Throw once more
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeMobileNumber.phoneId={0} is unexpected.", employee.getEmployeeMobileNumber().getPhoneId())); //NOI18N
+               } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() == null)) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeePersonalData.contactId is null"); //NOI18N
+               } else if ((employee.getEmployeePersonalData() != null) && (employee.getEmployeePersonalData().getContactId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeePersonalData.contactId={0} is unexpected.", employee.getEmployeePersonalData().getContactId())); //NOI18N
+               } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() == null)) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeePosition.jobPositionId is null"); //NOI18N
+               } else if ((employee.getEmployeePosition() != null) && (employee.getEmployeePosition().getJobPositionId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeePosition.jobPositionId={0} is unexpected.", employee.getEmployeePosition().getJobPositionId())); //NOI18N
+               } else if ((employee.getEmployeeUserOwner() != null) && (employee.getEmployeeUserOwner().getUserId() == null)) {
+                       // Throw NPE
+                       throw new NullPointerException("employee.employeeUserOwner.userId is null"); //NOI18N
+               } else if ((employee.getEmployeeUserOwner() != null) && (employee.getEmployeeUserOwner().getUserId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("employee.employeeUserOwner.userId={0} is unexpected.", employee.getEmployeeUserOwner().getUserId())); //NOI18N
+               } else if (this.isEmployeeAdded(employee)) {
+                       // Throw exception
+                       throw new EmployeeAlreadyAddedException();
+               }
+
+               // Make company (basic data) managed
+               employee.setEmployeeCompany(this.createManaged(employee.getEmployeeCompany()));
+
+               // Is branch office set?
+               if (employee.getEmployeeBranchOffice() instanceof BranchOffice) {
+                       // Then make it managed
+                       final BranchOffice branchOffice = this.createManaged(employee.getEmployeeBranchOffice());
+
+                       // Set it back
+                       employee.setEmployeeBranchOffice(branchOffice);
+               }
+
+               // Is department set?
+               if (employee.getEmployeeDepartment() instanceof Department) {
+                       // Then make it managed
+                       final Department department = this.createManaged(employee.getEmployeeDepartment());
+
+                       // Set it back
+                       employee.setEmployeeDepartment(department);
+               }
+
+               // Is headquarter set?
+               if (employee.getEmployeeHeadquarter() instanceof Headquarter) {
+                       // Then make it managed
+                       final Headquarter headquarter = this.createManaged(employee.getEmployeeHeadquarter());
+
+                       // Set it back
+                       employee.setEmployeeHeadquarter(headquarter);
+               }
+
+               // Is personal data set?
+               if (employee.getEmployeePersonalData() instanceof Contact) {
+                       // Then make it managed
+                       final Contact contact = this.createManaged(employee.getEmployeePersonalData());
+
+                       // Set it back
+                       employee.setEmployeePersonalData(contact);
+               }
+
+               // Is headquarter set?
+               if (employee.getEmployeePosition() instanceof JobPosition) {
+                       // Then make it managed
+                       final JobPosition jobPosition = this.createManaged(employee.getEmployeePosition());
+
+                       // Set it back
+                       employee.setEmployeePosition(jobPosition);
+               }
+
+               // Is headquarter set?
+               if (employee.getEmployeeUserOwner() instanceof User) {
+                       // Then make it managed
+                       final User user = this.createManaged(employee.getEmployeeUserOwner());
+
+                       // Set it back
+                       employee.setEmployeeUserOwner(user);
+               }
+
+               // Is mobile number set?
+               if (employee.getEmployeeMobileNumber() instanceof DialableMobileNumber) {
+                       // Yes, then set created there as well
+                       employee.getEmployeeMobileNumber().setPhoneEntryCreated(new Date());
+
+                       // Make mobile provider managed
+                       final MobileProvider mobileProvider = this.createManaged(employee.getEmployeeMobileNumber().getMobileProvider());
+
+                       // Set it back
+                       employee.getEmployeeMobileNumber().setMobileProvider(mobileProvider);
+               }
+
+               // Set created timestamp
+               employee.setEmployeeCreated(new Date());
+
+               // Persist it
+               this.getEntityManager().persist(employee);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addEmployee(): employee.employeeId={1} - EXIT!", this.getClass().getSimpleName(), employee.getEmployeeId())); //NOI18N
+
+               // Return it
+               return employee;
+       }
+
+       /**
+        * Checks whether employee is already added
+        * <p>
+        * @param employee Employee to be checked
+        * <p>
+        * @return Whether employee is already added
+        */
+       private boolean isEmployeeAdded (final Employable employee) {
+               // Default is not added
+               boolean isFound = false;
+
+               // Check all entries
+               for (final Employable otherEmployee : this.employeeBean.allEmployees()) {
+                       // Is same found?
+                       if (Employees.isSameEmployeeFound(employee, otherEmployee)) {
+                               // Found it
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
 }
index 09cf26802999c328c8cb8b48b08b16ccbb3d699a..32f0fe0eb27c390ca1c872d610a4ca95b5c4f648 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless bean for general purposes for company employees.
@@ -33,7 +33,7 @@ public class PizzaEmployeeSessionBean extends BasePizzaEnterpriseBean implements
        /**
         * Serial number
         */
-       private static final long serialVersionUID = 26_458_796_703_761L;
+       private static final long serialVersionUID = 26_458_796_703_762L;
 
        /**
         * Default constructor
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaAdminHeadquarterSessionBean.java
new file mode 100644 (file)
index 0000000..dd1f169
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarter;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
+
+/**
+ * A stateless session bean for administrative branch office purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminHeadquarter", description = "An administrative statless bean for handling branch office data (all)")
+public class PizzaAdminHeadquarterSessionBean extends BasePizzaEnterpriseBean implements AdminHeadquarterSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       /**
+        * General branch office bean
+        */
+       @EJB (lookup = "java:global/pizzaapplication-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote")
+       private HeadquarterSessionBeanRemote headquarterBean;
+
+       /**
+        * Default constructor
+        */
+       public PizzaAdminHeadquarterSessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public Headquarter addHeadquarter (final Headquarter headquarter) throws HeadquarterAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarter(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
+
+               // Validate parameter
+               if (null == headquarter) {
+                       // Throw NPE
+                       throw new NullPointerException("headquarter is null"); //NOI18N
+               } else if (headquarter.getHeadquarterId() instanceof Long) {
+                       // Should not happen
+                       throw new IllegalArgumentException("headquarter.branchId should not be set."); //NOI18N
+               } else if (this.isHeadquarterFound(headquarter)) {
+                       // Already added, abort here
+                       throw new HeadquarterAlreadyAddedException(headquarter);
+               }
+
+               // Add created timestamp
+               headquarter.setHeadquarterCreated(new Date());
+
+               // Is user instance set?
+               if (headquarter.getHeadquarterUserOwner() instanceof User) {
+                       // Get managed instance back
+                       final User managedUser = this.createManaged(headquarter.getHeadquarterUserOwner());
+
+                       // Set it back in branch office
+                       headquarter.setHeadquarterUserOwner(managedUser);
+               }
+
+               // Is user instance set?
+               if (headquarter.getHeadquarterCountry() instanceof Country) {
+                       // Get managed instance back
+                       final Country managedCountry = this.createManaged(headquarter.getHeadquarterCountry());
+
+                       // Set it back in branch office
+                       headquarter.setHeadquarterCountry(managedCountry);
+               }
+
+               // Set "created" timestamp on any number assigned
+               this.setAllPhoneEntriesCreated(headquarter);
+
+               // Get opening times
+               final List<OpeningTime> openingTimes = headquarter.getHeadquarterOpeningTimes();
+
+               // Debugging:
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarter(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
+
+               // Is opening times set and not empty?
+               if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
+                       // Add created timestamp for all times
+                       this.setAllOpeningTimesCreated(openingTimes);
+               } else {
+                       // Set all to null
+                       headquarter.setHeadquarterOpeningTimes(null);
+               }
+
+               // Persist it
+               this.getEntityManager().persist(headquarter);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarter(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquarterId())); //NOI18N
+
+               // Return updated instance
+               return headquarter;
+       }
+
+       /**
+        * Checks if given branch office's address is already persisted. The whole
+        * (persisted) list is being loaded and each address is being matched
+        * against the given branch office's address.
+        * <p>
+        * @param headquarter Headquarter office being checked
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isHeadquarterFound (final Headquarter headquarter) {
+               // Get whole list
+               final List<Headquarter> headquarters = this.headquarterBean.allHeadquarters();
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Check all single addresses
+               for (final Headquarter hq : headquarters) {
+                       // Is the same address found?
+                       if (Headquarters.isSameAddress(hq, headquarter)) {
+                               // Found one
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return flag
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaHeadquarterSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarter/PizzaHeadquarterSessionBean.java
new file mode 100644 (file)
index 0000000..8382583
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarter;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
+
+/**
+ * A stateless session bean for general headquarter purposes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "headquarter", description = "A general statless bean for handling headquarter data (all)")
+public class PizzaHeadquarterSessionBean extends BasePizzaEnterpriseBean implements HeadquarterSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 58_467_386_571_701L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Headquarter> allHeadquarters () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllHeadquarters"); //NOI18N
+
+               // Get list from it
+               final List<Headquarter> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaAdminHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaAdminHeadquartersSessionBean.java
deleted file mode 100644 (file)
index 0ad1cdd..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcontactsbusiness.model.headquarters;
-
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import org.mxchange.jcontactsbusiness.exceptions.headquarters.HeadquartersAlreadyAddedException;
-import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
-import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * A stateless session bean for administrative branch office purposes
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "adminHeadquarter", description = "An administrative statless bean for handling branch office data (all)")
-public class PizzaAdminHeadquartersSessionBean extends BasePizzaEnterpriseBean implements AdminHeadquartersSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_467_386_571_701L;
-
-       /**
-        * General branch office bean
-        */
-       @EJB (lookup = "java:global/pizzaapplication-ejb/headquarters!org.mxchange.jcontactsbusiness.model.headquarters.HeadquarterSessionBeanRemote")
-       private HeadquartersSessionBeanRemote headquartersBean;
-
-       /**
-        * Default constructor
-        */
-       public PizzaAdminHeadquartersSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public Headquarter addHeadquarters (final Headquarter headquarter) throws HeadquartersAlreadyAddedException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter={1} - CALLED!", this.getClass().getSimpleName(), headquarter)); //NOI18N
-
-               // Validate parameter
-               if (null == headquarter) {
-                       // Throw NPE
-                       throw new NullPointerException("headquarter is null"); //NOI18N
-               } else if (headquarter.getHeadquartersId() instanceof Long) {
-                       // Should not happen
-                       throw new IllegalArgumentException("headquarter.branchId should not be set."); //NOI18N
-               } else if (this.isHeadquarterFound(headquarter)) {
-                       // Already added, abort here
-                       throw new HeadquartersAlreadyAddedException(headquarter);
-               }
-
-               // Add created timestamp
-               headquarter.setHeadquartersCreated(new Date());
-
-               // Is user instance set?
-               if (headquarter.getHeadquartersUserOwner() instanceof User) {
-                       // Get managed instance back
-                       final User managedUser = this.createManaged(headquarter.getHeadquartersUserOwner());
-
-                       // Set it back in branch office
-                       headquarter.setHeadquartersUserOwner(managedUser);
-               }
-
-               // Is user instance set?
-               if (headquarter.getHeadquartersCountry() instanceof Country) {
-                       // Get managed instance back
-                       final Country managedCountry = this.createManaged(headquarter.getHeadquartersCountry());
-
-                       // Set it back in branch office
-                       headquarter.setHeadquartersCountry(managedCountry);
-               }
-
-               // Set "created" timestamp on any number assigned
-               this.setAllPhoneEntriesCreated(headquarter);
-
-               // Get opening times
-               final List<OpeningTime> openingTimes = headquarter.getHeadquartersOpeningTimes();
-
-               // Debugging:
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("{0}.addHeadquarters(): headquarter.headquarterOpeningTimes={1}", this.getClass().getSimpleName(), openingTimes));
-
-               // Is opening times set and not empty?
-               if ((openingTimes instanceof List) && (!openingTimes.isEmpty())) {
-                       // Add created timestamp for all times
-                       this.setAllOpeningTimesCreated(openingTimes);
-               } else {
-                       // Set all to null
-                       headquarter.setHeadquartersOpeningTimes(null);
-               }
-
-               // Persist it
-               this.getEntityManager().persist(headquarter);
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addHeadquarters(): headquarter.branchId={1} - EXIT!", this.getClass().getSimpleName(), headquarter.getHeadquartersId())); //NOI18N
-
-               // Return updated instance
-               return headquarter;
-       }
-
-       /**
-        * Checks if given branch office's address is already persisted. The whole
-        * (persisted) list is being loaded and each address is being matched
-        * against the given branch office's address.
-        * <p>
-        * @param headquarter Headquarters office being checked
-        * <p>
-        * @return Whether it has been found
-        */
-       private boolean isHeadquarterFound (final Headquarter headquarter) {
-               // Get whole list
-               final List<Headquarter> headquarters = this.headquartersBean.allHeadquarters();
-
-               // Default is not found
-               boolean isFound = false;
-
-               // Check all single addresses
-               for (final Headquarter hq : headquarters) {
-                       // Is the same address found?
-                       if (Headquarters.isSameAddress(hq, headquarter)) {
-                               // Found one
-                               isFound = true;
-                               break;
-                       }
-               }
-
-               // Return flag
-               return isFound;
-       }
-
-}
diff --git a/src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaHeadquartersSessionBean.java b/src/java/org/mxchange/jcontactsbusiness/model/headquarters/PizzaHeadquartersSessionBean.java
deleted file mode 100644 (file)
index 2f0e6bb..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcontactsbusiness.model.headquarters;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.Query;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * A stateless session bean for general headquarters purposes
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "headquarters", description = "A general statless bean for handling headquarters data (all)")
-public class PizzaHeadquartersSessionBean extends BasePizzaEnterpriseBean implements HeadquartersSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_467_386_571_701L;
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<Headquarter> allHeadquarters () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get query
-               final Query query = this.getEntityManager().createNamedQuery("AllHeadquarters"); //NOI18N
-
-               // Get list from it
-               final List<Headquarter> list = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allHeadquarters: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
-
-               // Return it
-               return list;
-       }
-
-}
index 1418e16749fccbd063fa2cda5f895b1656da312b..936db7baba9115478ed9845e6faeccf92a4ed86a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -19,7 +19,7 @@ package org.mxchange.jcontactsbusiness.model.opening_time;
 import java.text.MessageFormat;
 import java.util.Date;
 import javax.ejb.Stateless;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for administrative opening times purposes
index bca9a6f7d6670458a4fdb641ef0d7da8d855160b..2bfefd6f24dc3e7f281df2ffdcca9f470c9bb5bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Roland Häder
+ * Copyright (C) 2017, 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
-import org.mxchange.pizzaapplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless session bean for general opening times purposes
index c0db4755e54086d44b388c91d2609a32bde84346..9fd3f9ff53ca09422736d08de6ba81009da24568 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index b27f35671bf984c457cc70cf5e205cb2beea5de9..1b05eb8c4b4dc496ec52355e0461728cc152cb21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -21,7 +21,7 @@ import java.util.List;
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.persistence.Query;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A singleton EJB for country informations
index 73754cc2a1c1f0bb8ce4ce0fa5ebd4a9fc41d194..cdbad539580d56fc26a9864616541bc043968c24 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,7 +20,7 @@ import java.text.MessageFormat;
 import java.util.Date;
 import javax.ejb.Stateless;
 import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * Administrative singleton EJB for mobile provider informations
index eddf8ee96ba825da7179534088367750fc93e98a..a25ed3e7fa45363aadb555aaa4e95bdd95ccdc9b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -21,7 +21,7 @@ import java.util.List;
 import javax.ejb.Singleton;
 import javax.ejb.Startup;
 import javax.persistence.Query;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A singleton EJB for mobile provider informations
index 45d0264f8216be8083aafacfc12ace5763871bd7..0bc050f9bc8575d28a0682ab318818e6c6fe7303 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -25,7 +25,7 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumbers;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumbers;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * An EJB for administrative phone purposes
index a99267c46019d849ba841ee3029a24466e031cd6..46bc0edda222c360671a1a8ffe9742fce2e38d53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -27,7 +27,7 @@ import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A general phone EJB
diff --git a/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java b/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java
new file mode 100644 (file)
index 0000000..3051411
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.category;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jproduct.exceptions.category.CategoryAlreadyAddedException;
+import org.mxchange.pizzaapplication.database.product.BasePizzaProductEnterpriseBean;
+
+/**
+ * An administrative stateless session bean for product categories.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminCategory", description = "An administrative stateless session bean for product categories.")
+public class PizzaAdminProductCategorySessionBean extends BasePizzaProductEnterpriseBean implements AdminCategorySessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 23_865_767_165_437_802L;
+
+       /**
+        * Regular user bean
+        */
+       @EJB (lookup = "java:global/pizzaapplication-ejb/category!org.mxchange.jproduct.model.category.CategorySessionBeanRemote")
+       private CategorySessionBeanRemote categoryBean;
+
+       /**
+        * Default constructor
+        */
+       public PizzaAdminProductCategorySessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       public Category addProductCategory (final Category category) throws CategoryAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.adminAddProductCategory: category={1} - CALLED!", this.getClass().getSimpleName(), category)); //NOI18N
+
+               // Validate parameter
+               if (null == category) {
+                       // Throw NPE
+                       throw new NullPointerException("category is null"); //NOI18N
+               } else if (category.getCategoryI18nKey() == null) {
+                       // Throw it again
+                       throw new NullPointerException("category.categoryI18nKey is null"); //NOI18N
+               } else if (category.getCategoryI18nKey().isEmpty()) {
+                       // Throw it again
+                       throw new IllegalArgumentException("category.categoryI18nKey is empty"); //NOI18N
+               } else if (category.getCategoryId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("category.categoryId={0} is not expected.", category.getCategoryId())); //NOI18N
+               } else if (this.isCategoryCreated(category)) {
+                       // Is already created (by name)
+                       throw new CategoryAlreadyAddedException(category);
+               }
+
+               // Is a parent category set?
+               if (category.getParentCategory() instanceof Category) {
+                       // Then make it managed
+                       final Category managedCategory = this.createManaged(category.getParentCategory());
+
+                       // Set it back
+                       category.setParentCategory(managedCategory);
+               }
+
+               // Set created instance
+               category.setCategoryCreated(new Date());
+
+               // Persist it
+               this.getEntityManager().persist(category);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.adminAddProductCategory: category.categoryId={1} - EXIT!", this.getClass().getSimpleName(), category.getCategoryId())); //NOI18N
+
+               // Return it
+               return category;
+       }
+
+       /**
+        * Checks if given category is already added by it's title.
+        * <p>
+        * @param category Category to check
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isCategoryCreated (final Category category) {
+               // Validate parameter
+               if (null == category) {
+                       // Throw NPE
+                       throw new NullPointerException("category is null"); //NOI18N
+               } else if (category.getCategoryI18nKey() == null) {
+                       // Throw it again
+                       throw new NullPointerException("category.categoryI18nKey is null"); //NOI18N
+               } else if (category.getCategoryI18nKey().isEmpty()) {
+                       // Throw it again
+                       throw new IllegalArgumentException("category.categoryI18nKey is empty"); //NOI18N
+               } else if (category.getCategoryId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("category.categoryId={0} is not expected.", category.getCategoryId())); //NOI18N
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Get full list from other EJB
+               final List<Category> list = this.categoryBean.allCategories();
+
+               // Check each entry
+               for (final Category createdCategory : list) {
+                       // Is same name?
+                       if (Objects.equals(createdCategory.getCategoryI18nKey(), category.getCategoryI18nKey())) {
+                               // Found it, then stop here
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return result
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jproduct/model/category/PizzaProductCategorySessionBean.java b/src/java/org/mxchange/jproduct/model/category/PizzaProductCategorySessionBean.java
new file mode 100644 (file)
index 0000000..0e75dcc
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.category;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
+
+/**
+ * A general stateless session bean for product categories.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "category", description = "A general stateless session bean for product categories.")
+public class PizzaProductCategorySessionBean extends BasePizzaEnterpriseBean implements CategorySessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 23_865_767_165_437_801L;
+
+       /**
+        * Default constructor
+        */
+       public PizzaProductCategorySessionBean () {
+               // Call super constructor
+               super();
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Category> allCategories () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCategories: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllProductCategories", ProductCategory.class); //NOI18N
+
+               // Get list from it
+               final List<Category> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allCategories: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+}
diff --git a/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java b/src/java/org/mxchange/jproduct/model/product/PizzaAdminGenericProductSessionBean.java
new file mode 100644 (file)
index 0000000..fb5852c
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.product;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.ejb.Stateless;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException;
+import org.mxchange.jproduct.model.category.Category;
+import org.mxchange.pizzaapplication.database.product.BasePizzaProductEnterpriseBean;
+
+/**
+ * An administrative stateless session bean for generic products.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "adminProduct", description = "A stateless session bean for general purposes for generic products.")
+public class PizzaAdminGenericProductSessionBean extends BasePizzaProductEnterpriseBean implements AdminProductSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 184_573_667_215_549_811L;
+
+       /**
+        * Regular user bean
+        */
+       @EJB (lookup = "java:global/pizzaapplication-ejb/product!org.mxchange.jproduct.model.product.ProductSessionBeanRemote")
+       private ProductSessionBeanRemote productBean;
+
+       @Override
+       public Product addGenericProduct (final Product product) throws ProductAlreadyAddedException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addGenericProduct: product={1} - CALLED!", this.getClass().getSimpleName(), product)); //NOI18N
+
+               // Validate parameter
+               if (null == product) {
+                       // Throw NPE
+                       throw new NullPointerException("product is null"); //NOI18N
+               } else if (product.getProductI18nKey() == null) {
+                       // Throw it again
+                       throw new NullPointerException("product.productI18nKey is null"); //NOI18N
+               } else if (product.getProductI18nKey().isEmpty()) {
+                       // Throw it again
+                       throw new IllegalArgumentException("product.productI18nKey is empty"); //NOI18N
+               } else if (product.getProductId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is not expected.", product.getProductId())); //NOI18N
+               } else if (product.getProductCategory() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("product.productCategory is null"); //NOI18N
+               } else if (product.getProductCategory().getCategoryId() == null) {
+                       // Throw NPE
+                       throw new NullPointerException("product.productCategory.categoryId is null"); //NOI18N
+               } else if (product.getProductCategory().getCategoryId() < 1) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("product.productCategory.categoryId={0} is invalid", product.getProductCategory().getCategoryId())); //NOI18N
+               } else if ((product.getProductManufacturer() instanceof BasicData) && (product.getProductManufacturer().getBasicDataId() == null)) {
+                       // Throw NPE
+                       throw new NullPointerException("product.productManufacturer.basicDataId is null"); //NOI18N
+               } else if ((product.getProductManufacturer() instanceof BasicData) && (product.getProductManufacturer().getBasicDataId() < 1)) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("product.productManufacturer.basicDataId={0} is invalid", product.getProductManufacturer().getBasicDataId())); //NOI18N
+               } else if (this.isProductCreated(product)) {
+                       // Is already created (by name)
+                       throw new ProductAlreadyAddedException(product);
+               }
+
+               // Created a managed instance from product's category
+               final Category managedCategory = this.createManaged(product.getProductCategory());
+
+               // Set it back
+               product.setProductCategory(managedCategory);
+
+               // Is a manufacturer (basic_data entity) set?
+               if (product.getProductManufacturer() instanceof BasicData) {
+                       // Get managed instance from it
+                       final BasicData managedBasicData = this.createManaged(product.getProductManufacturer());
+
+                       // Set it back
+                       product.setProductManufacturer(managedBasicData);
+               }
+
+               // Set created instance
+               product.setProductCreated(new Date());
+
+               // Persist it
+               this.getEntityManager().persist(product);
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addGenericProduct: product.productId={1} - EXIT!", this.getClass().getSimpleName(), product.getProductId())); //NOI18N
+
+               // Return it
+               return product;
+       }
+
+       /**
+        * Checks if given product is already added by it's title.
+        * <p>
+        * @param product Product to check
+        * <p>
+        * @return Whether it has been found
+        */
+       private boolean isProductCreated (final Product product) {
+               // Validate parameter
+               if (null == product) {
+                       // Throw NPE
+                       throw new NullPointerException("product is null"); //NOI18N
+               } else if (product.getProductI18nKey() == null) {
+                       // Throw it again
+                       throw new NullPointerException("product.productI18nKey is null"); //NOI18N
+               } else if (product.getProductI18nKey().isEmpty()) {
+                       // Throw it again
+                       throw new IllegalArgumentException("product.productI18nKey is empty"); //NOI18N
+               } else if (product.getProductId() != null) {
+                       // Throw IAE
+                       throw new IllegalArgumentException(MessageFormat.format("product.productId={0} is not expected.", product.getProductId())); //NOI18N
+               }
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Get full list from other EJB
+               final List<Product> list = this.productBean.allProducts();
+
+               // Check each entry
+               for (final Product createdProduct : list) {
+                       // Is same name?
+                       if (Objects.equals(createdProduct.getProductI18nKey(), product.getProductI18nKey())) {
+                               // Found it, then stop here
+                               isFound = true;
+                               break;
+                       }
+               }
+
+               // Return result
+               return isFound;
+       }
+
+}
diff --git a/src/java/org/mxchange/jproduct/model/product/PizzaGenericProductSessionBean.java b/src/java/org/mxchange/jproduct/model/product/PizzaGenericProductSessionBean.java
new file mode 100644 (file)
index 0000000..935af87
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017, 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.product;
+
+import java.text.MessageFormat;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.Query;
+import org.mxchange.pizzaapplication.enterprise.BasePizzaEnterpriseBean;
+
+/**
+ * A general stateless session bean for generic products.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Stateless (name = "product", description = "A general stateless session bean for generic products.")
+public class PizzaGenericProductSessionBean extends BasePizzaEnterpriseBean implements ProductSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 184_573_667_215_549_810L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Product> allAvailableProducts () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allAvailableProducts: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllAvailableProducts", GenericProduct.class); //NOI18N
+
+               // Get list from it
+               final List<Product> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allAvailableProducts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Product> allProducts () {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allProducts: CALLED!", this.getClass().getSimpleName())); //NOI18N
+
+               // Get query
+               final Query query = this.getEntityManager().createNamedQuery("AllProducts", GenericProduct.class); //NOI18N
+
+               // Get list from it
+               final List<Product> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allProducts: list.size()={1} - EXIT!", this.getClass().getSimpleName(), list.size())); //NOI18N
+
+               // Return it
+               return list;
+       }
+
+}
index 2aa4e20d7eb08f0ec43e9be815c68d3747933061..2830f2445ddc5becaffd35dcd163769aa99a218e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index 0910f984783b1b9fadd4ac8240335665c8a3f0b1..019e0d07d3dfc1283583703622b67e1be079b6ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index e91b35d85762c217c09c82d02dda88e88c7dbfab..da0dd187b9a62958e25544b4cf82ae71a408b7f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -29,7 +29,7 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * An administrative user EJB
@@ -69,7 +69,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaEnterpriseBean implement
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.addUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
-               // user should not be null
+               // Validate parameter
                if (null == user) {
                        // Abort here
                        throw new NullPointerException("user is null"); //NOI18N
@@ -109,7 +109,7 @@ public class PizzaAdminUserSessionBean extends BasePizzaEnterpriseBean implement
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.deleteUser: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
 
-               // user should not be null
+               // Validate parameters
                if (null == user) {
                        // Abort here
                        throw new NullPointerException("user is null"); //NOI18N
index d62171c0adca13a71089629cf60a635cc186fd74..64d36595193f00da0e7687ec820d5d0bae89afdf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -39,10 +39,9 @@ import org.mxchange.jusercore.exceptions.UserStatusLockedException;
 import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
 import org.mxchange.jusercore.model.user.password_history.PasswordHistory;
 import org.mxchange.jusercore.model.user.password_history.UserPasswordHistory;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A user EJB
@@ -73,53 +72,7 @@ public class PizzaUserSessionBean extends BasePizzaEnterpriseBean implements Use
 
        @Override
        @SuppressWarnings ("unchecked")
-       public List<User> allMemberPublicVisibleUsers () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get named query
-               final Query query = this.getEntityManager().createNamedQuery("AllMemberPublicUsers", LoginUser.class); //NOI18N
-
-               // Set parameters
-               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
-               query.setParameter("members", ProfileMode.MEMBERS); //NOI18N
-               query.setParameter("public", ProfileMode.PUBLIC); //NOI18N
-
-               // Get result
-               final List<User> users = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allMemberPublicVisibleUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
-               // Return full list
-               return users;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<User> allPublicUsers () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get named query
-               final Query query = this.getEntityManager().createNamedQuery("AllPublicUsers", LoginUser.class); //NOI18N
-
-               // Set parameters
-               query.setParameter("status", UserAccountStatus.CONFIRMED); //NOI18N
-               query.setParameter("mode", ProfileMode.PUBLIC); //NOI18N
-
-               // Get result
-               final List<User> users = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.allPublicUsers: users.size()={1} - EXIT!", this.getClass().getSimpleName(), users.size())); //NOI18N
-
-               // Return full list
-               return users;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
+       @Deprecated
        public List<String> allUserNames () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getUserNameList: CALLED!", this.getClass().getSimpleName())); //NOI18N
@@ -207,6 +160,7 @@ public class PizzaUserSessionBean extends BasePizzaEnterpriseBean implements Use
        }
 
        @Override
+       @Deprecated
        public User fillUserData (final User user) throws UserNotFoundException {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.fillUserData: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
@@ -253,6 +207,7 @@ public class PizzaUserSessionBean extends BasePizzaEnterpriseBean implements Use
        }
 
        @Override
+       @Deprecated
        public String generateRandomUserName () {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.generateRandomUserName - CALLED!", this.getClass().getSimpleName())); //NOI18N
@@ -277,25 +232,7 @@ public class PizzaUserSessionBean extends BasePizzaEnterpriseBean implements Use
        }
 
        @Override
-       @SuppressWarnings ("unchecked")
-       public List<String> getEmailAddressList () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: CALLED!", this.getClass().getSimpleName())); //NOI18N
-
-               // Get query
-               final Query query = this.getEntityManager().createNamedQuery("AllEmailAddresses", String.class); //NOI18N
-
-               // Get result list
-               final List<String> emailAddressList = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.getEmailAddressList: emailAddressList.size()={1} - EXIT!", this.getClass().getSimpleName(), emailAddressList.size())); //NOI18N
-
-               // Return it
-               return emailAddressList;
-       }
-
-       @Override
+       @Deprecated
        public boolean ifUserExists (final User user) {
                // Trace message
                this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.ifUserExists: user={1} - CALLED!", this.getClass().getSimpleName(), user)); //NOI18N
index b12a5c4cb99ea46f3758ef19cd27256e8d43d1e3..62c5abaaad28465fb823beb3d5eb32724ca96c8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -25,7 +25,7 @@ import javax.jms.Message;
 import javax.jms.MessageListener;
 import javax.jms.ObjectMessage;
 import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A message-driven bean for adding user activity log
index 737aa183404b7fbe0fd266ced1942648a52d797c..aba908ccd6d284faa788a05754bba0cc00e3337e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index 03810b767949aee3140a5ea70fc3625de0c814ff..151ba7d668351ed3e05e674566ee041e4c091c53 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -28,7 +28,7 @@ import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
 import org.mxchange.jusercore.model.email_address.EmailAddressChange;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.juserlogincore.login.UserLoginUtils;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A session-scoped bean for changing email addresses
index 0d309b7d8143a28794ced90dfc92d42480bf0564..da3a49440f7459d37e7662f21926df5bdba62e36 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -21,7 +21,7 @@ import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.Query;
 import org.mxchange.jusercore.model.user.User;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A user password history EJB
index 9c3b67c0d97a8342e8443f52020aaa964a685fc4..c601a918369a6def69911707529ec76e7e0552fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -29,7 +29,7 @@ import org.mxchange.juserlogincore.container.login.LoginContainer;
 import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
 import org.mxchange.juserlogincore.login.UserLoginUtils;
 import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A session EJB for user logins
@@ -95,6 +95,7 @@ public class PizzaUserLoginSessionBean extends BasePizzaEnterpriseBean implement
                }
 
                // Get user instance from persistance
+               // @TODO Rewrite this to use JCache instead
                final User updatedUser = this.userBean.fillUserData(container.getUser());
 
                // Debug message
index 35257cc22a273c0d4eab93948b4121f3038e8e39..dae7e01f78048b413353164048017c72bf5d620b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -30,7 +30,7 @@ import org.mxchange.jusercore.model.user.LoginUser;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.juserlogincore.login.UserLoginUtils;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A session-scoped bean for user registration
index 37a665108c24a080cafc8bc99d94d21afce45332..500726125bddb7e79b103d80ea195d58d3dd08bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -28,7 +28,7 @@ import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
 import org.mxchange.jusercore.model.user.status.UserAccountStatus;
 import org.mxchange.juserlogincore.model.user.register.UserRegistrationSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A session-based EJB for resending confirmation links
index b18c388febb4c5cebf5e3915be36be65f2150168..e6a2b9c2858f9d409127b5fab82a37f081c34dd2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * 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
index 4daede242d4db98a11ed93641c5c19e94252021f..ec4115d1e287ce9c9c82312b576de1429b408408 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -29,7 +29,7 @@ import org.mxchange.jshopcore.model.basket.ShopBasket;
 import org.mxchange.jshopcore.model.customer.ShopCustomerUtils;
 import org.mxchange.jshopcore.model.order.Orderable;
 import org.mxchange.jshopcore.model.order.ShopOrder;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A basket for orderable items
diff --git a/src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java b/src/java/org/mxchange/pizzaapplication/model/category/PizzaAdminCategorySessionBean.java
deleted file mode 100644 (file)
index c65ddd9..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.model.category;
-
-import java.text.MessageFormat;
-import javax.ejb.Stateless;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.jproduct.exceptions.CannotAddCategoryException;
-import org.mxchange.jproduct.exceptions.CategoryTitleAlreadyUsedException;
-import org.mxchange.jproduct.model.category.Category;
-import org.mxchange.jproduct.model.category.ProductCategory;
-import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * An EJB for administrative access on categories
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "adminCategory", description = "An administrative bean handling product categories")
-public class PizzaAdminCategorySessionBean extends BasePizzaEnterpriseBean implements AdminCategorySessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 26_143_895_789_581L;
-
-       /**
-        * Default constructor
-        */
-       public PizzaAdminCategorySessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public Category doAdminAddCategory (final Category category) throws CategoryTitleAlreadyUsedException, CannotAddCategoryException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("doAdminAddCategory: category={0} - CALLED!", category)); //NOI18N
-
-               if (null == category) {
-                       // category is null
-                       throw new NullPointerException("category is null"); //NOI18N
-               } else if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // The connection must be there
-               if (this.isCategoryTitleUsed(category)) {
-                       // Then abort here
-                       throw new CategoryTitleAlreadyUsedException(category);
-               }
-
-               // Perist the category
-               this.getEntityManager().persist(category);
-
-               // Flush it
-               this.getEntityManager().flush();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("doAdminAddCategory: category={0} - EXIT!", category)); //NOI18N
-
-               // Return it
-               return category;
-       }
-
-       /**
-        * Checks if the category's title has already been used as they need to be
-        * unique. This method works case-insensitive. Any spaces, new-line,
-        * carriage-return or tabulator characters are trimmed away. If the title
-        * has been used already, for performance reasons, the id and parent id are
-        * set in the category object.
-        * <p>
-        * @param category Category instance
-        * <p>
-        * @return Whether the category's title has been used
-        */
-       private boolean isCategoryTitleUsed (final Category category) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isCategoryTitleUsed: category={0} - CALLED!", category)); //NOI18N
-
-               // The connection must be there
-               if (null == category) {
-                       // category is null
-                       throw new NullPointerException("category is null"); //NOI18N
-               } else if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // Default is not found
-               boolean isUsed = false;
-
-               // Debug message
-               this.getLoggerBeanLocal().logDebug(MessageFormat.format("isCategoryTitleUsed: category.id={0},category.title={1},category.parentId={2}", category.getCategoryId(), category.getCategoryTitle(), category.getParentCategory())); //NOI18N
-
-               // Try to locate it
-               try {
-                       // Get query instance
-                       Query query = this.getEntityManager().createQuery("SELECT c FROM category AS c WHERE LOWER(c.categoryTitle) = LOWER(:param)", ProductCategory.class); //NOI18N
-                       query.setParameter("param", category.getCategoryTitle()); //NOI18N
-                       Category cat = (Category) query.getSingleResult();
-
-                       // Is found, so copy the object
-                       category.copyAll(cat);
-
-                       // Mark as found
-                       isUsed = true;
-               } catch (final EntityNotFoundException | NoResultException e) {
-                       // Not found
-                       this.getLoggerBeanLocal().logWarning(e.getMessage());
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isCategoryTitleUsed: isUsed={0} - EXIT!", isUsed)); //NOI18N
-
-               // Return it
-               return isUsed;
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java b/src/java/org/mxchange/pizzaapplication/model/category/PizzaCategorySessionBean.java
deleted file mode 100644 (file)
index 6462ec0..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.model.category;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.Query;
-import org.mxchange.jproduct.model.category.Category;
-import org.mxchange.jproduct.model.category.ProductCategory;
-import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * Main shop class
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "category", description = "A bean handling categories for all others (non-admin)")
-public class PizzaCategorySessionBean extends BasePizzaEnterpriseBean implements CategorySessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 58_137_539_530_279L;
-
-       /**
-        * Default constructor
-        */
-       public PizzaCategorySessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<Category> getAllCategories () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("getAllCategories: CALLED!"); //NOI18N
-
-               // The connection must be there
-               if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // Create statement
-               Query query = this.getEntityManager().createQuery("SELECT c FROM category AS c ORDER BY c.categoryId ASC", ProductCategory.class);
-
-               // Get result
-               List<Category> list = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAllCategories: list({0})={1} - EXIT!", list.size(), list)); //NOI18N
-
-               // Return it
-               return list;
-       }
-
-}
index 723653d8a24991cedca966c4725f8b65709b549e..a9795f25178eca2a5fa9a0d2151b889f9435a684 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index 48bccc4c5bef6292bd5c96c911f84c251fcdd191..c8010c539657bf319f26b37b67850ecf602551b3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -29,7 +29,7 @@ import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
 import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
 import org.mxchange.jcustomercore.model.customer.Customer;
 import org.mxchange.jcustomercore.utils.CustomerUtils;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless administrative customer session-scoped bean (EJB)
index 78fe234a1f0bdc5d69b8e46ced5193e7470c2994..42d6be949b8ecb6bc43626febcde18563fc17e30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -23,7 +23,7 @@ import javax.persistence.Query;
 import org.mxchange.jcustomercore.exceptions.CustomerAlreadyRegisteredException;
 import org.mxchange.jcustomercore.exceptions.CustomerNotFoundException;
 import org.mxchange.jcustomercore.model.customer.Customer;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
+import org.mxchange.pizzaaplication.enterprise.BasePizzaEnterpriseBean;
 
 /**
  * A stateless customer session-scoped bean (EJB)
diff --git a/src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/product/PizzaAdminProductSessionBean.java
deleted file mode 100644 (file)
index 4a8a02e..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.model.product;
-
-import java.text.MessageFormat;
-import java.util.List;
-import javax.ejb.Stateless;
-import javax.persistence.EntityExistsException;
-import javax.persistence.EntityNotFoundException;
-import javax.persistence.NoResultException;
-import javax.persistence.Query;
-import org.mxchange.jproduct.exceptions.CannotAddProductException;
-import org.mxchange.jproduct.exceptions.ProductTitleAlreadyUsedException;
-import org.mxchange.jproduct.model.product.GenericProduct;
-import org.mxchange.jproduct.model.product.Product;
-import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * A session-scoped bean for non-administrative roles for products
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "adminProduct", description = "An administrative bean handling products")
-public class PizzaAdminProductSessionBean extends BasePizzaEnterpriseBean implements AdminProductSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 65_173_487_394_812L;
-
-       /**
-        * Default constructor
-        */
-       public PizzaAdminProductSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public Product doAdminAddProduct (final Product product) throws ProductTitleAlreadyUsedException, CannotAddProductException {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("doAdminAddProduct: product={0} - CALLED!", product)); //NOI18N
-
-               // Check if product's title is used
-               if (null == product) {
-                       // product is null
-                       throw new NullPointerException("product is null"); //NOI18N
-               } else if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               } else if (this.isProductTitleUsed(product)) {
-                       // Throw exception
-                       throw new ProductTitleAlreadyUsedException(product);
-               }
-
-               try {
-                       // Persist it
-                       this.getEntityManager().persist(product);
-
-                       // Flush it as the id might be needed immediately
-                       this.getEntityManager().flush();
-               } catch (final EntityExistsException ex) {
-                       // Continue to throw
-                       throw new CannotAddProductException(ex);
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("doAdminAddProduct: product={0} - EXIT!", product)); //NOI18N
-
-               // Return it
-               return product;
-       }
-
-       @Override
-       @SuppressWarnings ("unchecked")
-       public List<Product> getAllProducts () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("getAllProducts: CALLED!"); //NOI18N
-
-               // The connection must be there
-               if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // Create statement
-               Query query = this.getEntityManager().createQuery("SELECT p FROM products AS p ORDER BY p.productId ASC", GenericProduct.class); //NOI18N
-
-               // Get list
-               List<Product> list = query.getResultList();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAllProducts: list({0})={1} - EXIT!", list.size(), list)); //NOI18N
-
-               // Return it
-               return list;
-       }
-
-       /**
-        * Checks if the product's title has already been used as they need to be
-        * unique. This method works case-insensitive. Any spaces, new-line,
-        * carriage-return or tabulator characters are trimmed away. If the title
-        * has been used already, for performance reasons, the whole data is set in
-        * the product object.
-        * <p>
-        * @param product Product instance
-        * <p>
-        * @return Whether the product's title has been used
-        */
-       private boolean isProductTitleUsed (final Product product) {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isProductTitleUsed: Product={0} - CALLED!", product)); //NOI18N
-
-               // The connection must be there
-               if (null == product) {
-                       // product is null
-                       throw new NullPointerException("product is null"); //NOI18N
-               } else if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // Default is not found
-               boolean isUsed = false;
-
-               // Try to locate it
-               try {
-                       // Get query instance
-                       Query query = this.getEntityManager().createQuery("SELECT p FROM products AS p WHERE LOWER(p.productTitle) = LOWER(:param)", GenericProduct.class); //NOI18N
-                       query.setParameter("param", product.getProductTitle()); //NOI18N
-                       Product pro = (Product) query.getSingleResult();
-
-                       // Is found, so copy the object
-                       product.copyAll(pro);
-
-                       // Mark as found
-                       isUsed = true;
-               } catch (final EntityNotFoundException | NoResultException e) {
-                       // Not found
-                       this.getLoggerBeanLocal().logWarning(e.getMessage());
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isProductTitleUsed: isUsed={0} - EXIT!", isUsed)); //NOI18N
-
-               // Return it
-               return isUsed;
-       }
-
-}
diff --git a/src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java b/src/java/org/mxchange/pizzaapplication/model/product/PizzaProductSessionBean.java
deleted file mode 100644 (file)
index 136dd7f..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2016, 2017 Roland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.model.product;
-
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.ejb.EJB;
-import javax.ejb.Stateless;
-import org.mxchange.jproduct.model.product.Product;
-import org.mxchange.jshopcore.model.product.AdminProductSessionBeanRemote;
-import org.mxchange.jshopcore.model.product.ProductSessionBeanRemote;
-import org.mxchange.pizzaaplication.enterpriseBasePizzaEnterpriseBean;
-
-/**
- * A session-scoped bean for non-administrative roles for products
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Stateless (name = "product", description = "A bean handling products for all others (non-admin)")
-public class PizzaProductSessionBean extends BasePizzaEnterpriseBean implements ProductSessionBeanRemote {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 65_173_487_394_812L;
-
-       /**
-        * Administrative bean
-        */
-       @EJB
-       private AdminProductSessionBeanRemote adminProductBean;
-
-       /**
-        * Default constructor
-        */
-       public PizzaProductSessionBean () {
-               // Call super constructor
-               super();
-       }
-
-       @Override
-       public List<Product> getAvailableProducts () {
-               // Trace message
-               this.getLoggerBeanLocal().logTrace("getAvailableProducts: CALLED!"); //NOI18N
-
-               // The connection must be there
-               if (this.getEntityManager() == null) {
-                       // Connection is not there
-                       throw new NullPointerException("connection is null"); //NOI18N
-               }
-
-               // Get all products
-               List<Product> allProducts = this.adminProductBean.getAllProducts();
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: allProducts({0})={1}", allProducts.size(), allProducts)); //NOI18N
-
-               // Init deque
-               List<Product> deque = new LinkedList<>();
-
-               // Get iterator
-               Iterator<Product> iterator = allProducts.iterator();
-
-               // Walk through all and add only available
-               while (iterator.hasNext()) {
-                       // Get element
-                       Product localProduct = iterator.next();
-
-                       // Debug message
-                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0}", localProduct)); //NOI18N
-
-                       // Is this available?
-                       if (localProduct.getProductAvailability()) {
-                               // Debug message
-                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("getAvailableProducts: localProduct={0} - ADDED!", localProduct)); //NOI18N
-
-                               // Add it
-                               deque.add(localProduct);
-                       }
-               }
-
-               // Trace message
-               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAvailableProducts: deque({0})={1} - EXIT!", deque.size(), deque)); //NOI18N
-
-               // Return it
-               return deque;
-       }
-
-}