]> git.mxchange.org Git - jjobs-ejb.git/commitdiff
added files from addressbook-ejb:
authorRoland Haeder <roland@mxchange.org>
Wed, 2 Mar 2016 19:42:29 +0000 (20:42 +0100)
committerRoland Haeder <roland@mxchange.org>
Wed, 2 Mar 2016 19:42:29 +0000 (20:42 +0100)
- added a lot jars and classes which may need to be customized for jjobs
- updated project files

lib/jcore-logger-lib.jar [new file with mode: 0644]
lib/jcoreee.jar [new file with mode: 0644]
lib/juser-core.jar [new file with mode: 0644]
nbproject/build-impl.xml
nbproject/genfiles.properties
nbproject/project.properties
nbproject/project.xml
src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java [new file with mode: 0644]
src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java [new file with mode: 0644]
src/java/org/mxchange/jphone/phonenumbers/smsprovider/AddressbookSmsProviderSingletonBean.java [new file with mode: 0644]

diff --git a/lib/jcore-logger-lib.jar b/lib/jcore-logger-lib.jar
new file mode 100644 (file)
index 0000000..ea0ec33
Binary files /dev/null and b/lib/jcore-logger-lib.jar differ
diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar
new file mode 100644 (file)
index 0000000..8fa7868
Binary files /dev/null and b/lib/jcoreee.jar differ
diff --git a/lib/juser-core.jar b/lib/juser-core.jar
new file mode 100644 (file)
index 0000000..40c22b7
Binary files /dev/null and b/lib/juser-core.jar differ
index 064428ed009d210af4c28fb5d20e353e7e546132..21fa2d28cfa6b0e47085f781928e4c529811602a 100644 (file)
@@ -826,32 +826,44 @@ exists or setup the property manually. For example like this:
     </target>
     <target depends="compile,-library-inclusion-in-archive-weblogic,-library-inclusion-in-archive-by-user" name="library-inclusion-in-archive"/>
     <target if="is.jars.in.ejbjar" name="-library-inclusion-in-archive-by-user">
+        <copyfiles files="${file.reference.jcoreee.jar}" todir="${build.classes.dir}"/>
+        <copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcontacts-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcontacts-business-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jcountry-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${file.reference.jphone-core.jar}" todir="${build.classes.dir}"/>
+        <copyfiles files="${file.reference.juser-core.jar}" todir="${build.classes.dir}"/>
         <copyfiles files="${reference.jjobs-lib.jar}" todir="${build.classes.dir}"/>
     </target>
     <target if="is.server.weblogic" name="-library-inclusion-in-archive-weblogic">
+        <basename file="${file.reference.jcoreee.jar}" property="manifest.file.reference.jcoreee.jar"/>
+        <basename file="${file.reference.jcore-logger-lib.jar}" property="manifest.file.reference.jcore-logger-lib.jar"/>
         <basename file="${file.reference.jcontacts-core.jar}" property="manifest.file.reference.jcontacts-core.jar"/>
         <basename file="${file.reference.jcontacts-business-core.jar}" property="manifest.file.reference.jcontacts-business-core.jar"/>
         <basename file="${file.reference.jcountry-core.jar}" property="manifest.file.reference.jcountry-core.jar"/>
         <basename file="${file.reference.jphone-core.jar}" property="manifest.file.reference.jphone-core.jar"/>
+        <basename file="${file.reference.juser-core.jar}" property="manifest.file.reference.juser-core.jar"/>
         <basename file="${reference.jjobs-lib.jar}" property="manifest.reference.jjobs-lib.jar"/>
         <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update">
-            <attribute name="Extension-List" value="jar-1 jar-2 jar-3 jar-4 jar-5 "/>
-            <attribute name="jar-1-Extension-Name" value="${manifest.file.reference.jcontacts-core.jar}"/>
-            <attribute name="jar-2-Extension-Name" value="${manifest.file.reference.jcontacts-business-core.jar}"/>
-            <attribute name="jar-3-Extension-Name" value="${manifest.file.reference.jcountry-core.jar}"/>
-            <attribute name="jar-4-Extension-Name" value="${manifest.file.reference.jphone-core.jar}"/>
-            <attribute name="jar-5-Extension-Name" value="${manifest.reference.jjobs-lib.jar}"/>
+            <attribute name="Extension-List" value="jar-1 jar-2 jar-3 jar-4 jar-5 jar-6 jar-7 jar-8 "/>
+            <attribute name="jar-1-Extension-Name" value="${manifest.file.reference.jcoreee.jar}"/>
+            <attribute name="jar-2-Extension-Name" value="${manifest.file.reference.jcore-logger-lib.jar}"/>
+            <attribute name="jar-3-Extension-Name" value="${manifest.file.reference.jcontacts-core.jar}"/>
+            <attribute name="jar-4-Extension-Name" value="${manifest.file.reference.jcontacts-business-core.jar}"/>
+            <attribute name="jar-5-Extension-Name" value="${manifest.file.reference.jcountry-core.jar}"/>
+            <attribute name="jar-6-Extension-Name" value="${manifest.file.reference.jphone-core.jar}"/>
+            <attribute name="jar-7-Extension-Name" value="${manifest.file.reference.juser-core.jar}"/>
+            <attribute name="jar-8-Extension-Name" value="${manifest.reference.jjobs-lib.jar}"/>
         </manifest>
     </target>
     <target depends="compile" name="library-inclusion-in-manifest">
+        <copyfiles files="${file.reference.jcoreee.jar}" todir="${dist.ear.dir}/lib"/>
+        <copyfiles files="${file.reference.jcore-logger-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcontacts-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcontacts-business-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jcountry-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${file.reference.jphone-core.jar}" todir="${dist.ear.dir}/lib"/>
+        <copyfiles files="${file.reference.juser-core.jar}" todir="${dist.ear.dir}/lib"/>
         <copyfiles files="${reference.jjobs-lib.jar}" todir="${dist.ear.dir}/lib"/>
         <manifest file="${build.ear.classes.dir}/META-INF/MANIFEST.MF" mode="update"/>
     </target>
index 687679e65f47c19cddf9c6deeffc6eb1a0ed4e79..09b7572d3bb4e1a9abfbffba3cc2a130bc8f1f1a 100644 (file)
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=8561312a
+build.xml.data.CRC32=cd9fade4
 build.xml.script.CRC32=9c0f08a9
 build.xml.stylesheet.CRC32=5910fda3@1.55.1
 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
 # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=8561312a
-nbproject/build-impl.xml.script.CRC32=80436f3c
+nbproject/build-impl.xml.data.CRC32=cd9fade4
+nbproject/build-impl.xml.script.CRC32=fe25a685
 nbproject/build-impl.xml.stylesheet.CRC32=6096d939@1.55.1
index a52c6d618c509aac17a2aa99bdb5b3ab7bccb80f..921f78cc0af189ab01d40ef4f67f74c5b914e7fd 100644 (file)
@@ -23,8 +23,11 @@ endorsed.classpath=
 excludes=
 file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar
 file.reference.jcontacts-core.jar=lib/jcontacts-core.jar
+file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
+file.reference.jcoreee.jar=lib/jcoreee.jar
 file.reference.jcountry-core.jar=lib/jcountry-core.jar
 file.reference.jphone-core.jar=lib/jphone-core.jar
+file.reference.juser-core.jar=lib/juser-core.jar
 includes=**
 j2ee.compile.on.save=true
 j2ee.deploy.on.save=true
@@ -40,10 +43,13 @@ jar.compress=false
 jar.name=jjobs-ejb.jar
 jars.in.ejbjar=false
 javac.classpath=\
+    ${file.reference.jcoreee.jar}:\
+    ${file.reference.jcore-logger-lib.jar}:\
     ${file.reference.jcontacts-core.jar}:\
     ${file.reference.jcontacts-business-core.jar}:\
     ${file.reference.jcountry-core.jar}:\
     ${file.reference.jphone-core.jar}:\
+    ${file.reference.juser-core.jar}:\
     ${reference.jjobs-lib.jar}
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
 javac.debug=true
@@ -84,8 +90,11 @@ runmain.jvmargs=
 source.encoding=UTF-8
 source.reference.jcontacts-business-core.jar=../jcontacts-business-core/src/
 source.reference.jcontacts-core.jar=../jcontacts-core/src/
+source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
+source.reference.jcoreee.jar=../jcoreee/src/
 source.reference.jcountry-core.jar=../jcountry-core/src/
 source.reference.jphone-core.jar=../jphone-core/src/
+source.reference.juser-core.jar=../juser-core/src/
 source.root=src
 src.dir=${source.root}/java
 test.src.dir=test
index 08c49bc5a33d005d068c7145486850cf0ad406fc..54d757198e1d2c660e36fe1ca372cc47dcc5719b 100644 (file)
@@ -5,10 +5,13 @@
         <data xmlns="http://www.netbeans.org/ns/j2ee-ejbjarproject/3">
             <name>jjobs-ejb</name>
             <minimum-ant-version>1.6.5</minimum-ant-version>
+            <included-library dirs="200">file.reference.jcoreee.jar</included-library>
+            <included-library dirs="200">file.reference.jcore-logger-lib.jar</included-library>
             <included-library dirs="200">file.reference.jcontacts-core.jar</included-library>
             <included-library dirs="200">file.reference.jcontacts-business-core.jar</included-library>
             <included-library dirs="200">file.reference.jcountry-core.jar</included-library>
             <included-library dirs="200">file.reference.jphone-core.jar</included-library>
+            <included-library dirs="200">file.reference.juser-core.jar</included-library>
             <included-library dirs="200">reference.jjobs-lib.jar</included-library>
             <source-roots>
                 <root id="src.dir"/>
diff --git a/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java b/src/java/org/mxchange/addressbook/model/addressbook/AddressbookSessionBean.java
new file mode 100644 (file)
index 0000000..55aaafd
--- /dev/null
@@ -0,0 +1,402 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.model.addressbook;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.exceptions.AddressbookNameAlreadyUsedException;
+import org.mxchange.jjobs.exceptions.AddressbookNotFoundException;
+import org.mxchange.jjobs.model.addressbook.Addressbook;
+import org.mxchange.jjobs.model.addressbook.AddressbookSessionBeanRemote;
+import org.mxchange.jjobs.model.addressbook.UserAddressbook;
+import org.mxchange.jjobs.model.addressbook.entry.AddressbookEntry;
+import org.mxchange.jjobs.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless bean handling addressbooks
+ * <p>
+ * @author Roland Haeder
+ */
+@Stateless (name = "addressbook", mappedName = "ejb/stateless-addressbook", description = "A stateless bean for handling addressbooks")
+public class AddressbookSessionBean extends BaseDatabaseBean implements AddressbookSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 129_857_871_287_691L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<AddressbookEntry> allEntries (final Addressbook addressbook) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allEntries: addressbook={0} - CALLED!", addressbook)); //NOI18N
+
+               // Validate parameter
+               if (null == addressbook) {
+                       // Throw NPE
+                       throw new NullPointerException("addressbook is null");
+               } else if (addressbook.getAddressbookId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("addressbook.addressbookId is null");
+               } else if (addressbook.getAddressbookId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId()));
+               } else if (addressbook.getAddressbookUser() == null) {
+                       // Throw again NPE
+                       throw new NullPointerException("addressbook.addressbookUser is null");
+               } else if (addressbook.getAddressbookUser().getUserId() == null) {
+                       // Throw again NPE
+                       throw new NullPointerException("addressbook.addressbookUser.userId is null");
+               } else if (addressbook.getAddressbookUser().getUserId() < 1) {
+                       // Invalid id number again
+                       throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid", addressbook.getAddressbookUser().getUserId()));
+               }
+
+               // Generate query
+               Query query = this.getEntityManager().createNamedQuery("SearchUsersAddressbookEntries", List.class); //NOI18N
+
+               // Set parameters
+               query.setParameter("addressbook", addressbook); //NOI18N
+               query.setParameter("owner", addressbook.getAddressbookUser()); //NOI18N
+
+               // Return it
+               return query.getResultList();
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<User> allUsersNotSharing (final User user, final Addressbook addressbook) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: user={0},addressbook={1} - CALLED!", user, addressbook)); //NOI18N
+
+               // Test parameter
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               } else if (null == addressbook) {
+                       // Again NPE
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() == null) {
+                       // Again NPE
+                       throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("addressbook.getAddressbookId={0} is invalid", addressbook.getAddressbookId())); //NOI18N
+               }
+
+               // Get named query for a user list without given user
+               Query allUsersExceptQuery = this.getEntityManager().createNamedQuery("SearchAllUsersExcept", List.class); //NOI18N
+
+               // Set parameter
+               allUsersExceptQuery.setParameter("user", user); //NOI18N
+
+               // Get full list
+               List<User> allUsersExcept = allUsersExceptQuery.getResultList();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allUsersExcept.size()={0}", allUsersExcept.size())); //NOI18N
+
+               // Now get all shares this user has created
+               Query allSharesQuery = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N
+
+               // Set parameter
+               allSharesQuery.setParameter("user", user); //NOI18N
+
+               // Get full list again
+               List<ShareableAddressbook> allShares = allSharesQuery.getResultList();
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: allShares.size()={0}", allShares.size())); //NOI18N
+
+               // List for users aharing with given
+               List<User> sharingUsers = new ArrayList<>(allShares.size());
+
+               // Check all entries
+               for (final ShareableAddressbook share : allShares) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: share.shareUserSharee={0}", share.getShareUserSharee())); //NOI18N
+
+                       // Add it
+                       sharingUsers.add(share.getShareUserSharee());
+               }
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: sharingUsers.size()={0}", sharingUsers.size())); //NOI18N
+
+               // Init final user list
+               List<User> userList = new LinkedList<>();
+
+               // Walk through all users
+               for (final User foundUser : allUsersExcept) {
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0}", foundUser)); //NOI18N
+
+                       // Does the list contain it ?
+                       if (!sharingUsers.contains(foundUser)) {
+                               // Found one to add
+                               this.getLoggerBeanLocal().logDebug(MessageFormat.format("allUsersNotSharing: foundUser={0} - ADDING!", foundUser)); //NOI18N
+
+                               // Add it
+                               userList.add(foundUser);
+                       }
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allUsersNotSharing: userList.size()={0} - EXIT!", userList.size())); //NOI18N
+
+               // Return it
+               return userList;
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public Integer countAllUserSharedAddressbooks (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N
+
+               // user should be valid
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Invalid id
+                       throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
+               }
+
+               // Get named query
+               Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("user", user); //NOI18N
+
+               // Default is zero
+               Integer count = 0;
+
+               // Try it
+               try {
+                       // Get whole list
+                       List<ShareableAddressbook> dummy = query.getResultList();
+
+                       // Set size
+                       count = dummy.size();
+               } catch (final NoResultException ex) {
+                       // Need to catch this, so log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("countAllUserSharedAddressbooks: getResultList() failed: {0}", ex)); //NOI18N
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("countAllUserSharedAddressbooks: count={0} - EXIT!", count)); //NOI18N
+
+               // Return count
+               return count;
+       }
+
+       @Override
+       public Addressbook createAddressbook (final Addressbook addressbook) throws AddressbookNameAlreadyUsedException {
+               // Is it not null?
+               if (null == addressbook) {
+                       // Abort here
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (addressbook.getAddressbookUser() == null) {
+                       // User instance is null
+                       throw new NullPointerException("addressbook.user should not be null."); //NOI18N
+               } else if (addressbook.getAddressbookName() == null) {
+                       // Address book name not set
+                       throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
+               } else if (addressbook.getAddressbookName().isEmpty()) {
+                       // Address book name not set
+                       throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
+               } else if (this.isAddressbookNameUsed(addressbook)) {
+                       // The assigned user already used that name
+                       throw new AddressbookNameAlreadyUsedException(addressbook);
+               }
+
+               // Persist it now
+               this.getEntityManager().persist(addressbook);
+
+               // Flush it to get all data
+               this.getEntityManager().flush();
+
+               // Return it updated
+               return addressbook;
+       }
+
+       @Override
+       public Addressbook getAddressbookById (final Long addressbookId) throws AddressbookNotFoundException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getAddressbookById: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
+
+               // addressbookId should not be null or below 1
+               if (null == addressbookId) {
+                       // Throw NPE
+                       throw new NullPointerException("addressbookId is null"); //NOI18N
+               } else if (addressbookId < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
+               } else if (!this.isAddressbookIdUsed(addressbookId)) {
+                       // No address book found
+                       throw new AddressbookNotFoundException(addressbookId);
+               }
+
+               // Get named query instance
+               Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("id", addressbookId); //NOI18N
+
+               // Return it
+               return (Addressbook) query.getSingleResult();
+       }
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Addressbook> getUsersAddressbookList (final User loggedInUser) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("getUsersList: loggedInUser={0} - CALLED!", loggedInUser)); //NOI18N
+
+               // Is the user instance null?
+               if (null == loggedInUser) {
+                       // Abort here
+                       throw new NullPointerException("loggedInUser is null"); //NOI18N
+               }
+
+               // Get query instance
+               Query query = this.getEntityManager().createNamedQuery("AllUsersAddressbooks", List.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("param", loggedInUser); //NOI18N
+
+               // Get full list from JPA
+               List<Addressbook> addressbooks = query.getResultList();
+
+               // Return it
+               return addressbooks;
+       }
+
+       @Override
+       public boolean isAddressbookIdUsed (final Long addressbookId) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} - CALLED!", addressbookId)); //NOI18N
+
+               // Is it null or zero?
+               if (null == addressbookId) {
+                       // Throw NPE
+                       throw new NullPointerException("addressbookId is null"); //NOI18N
+               } else if (addressbookId < 1) {
+                       // Not valid id number
+                       throw new IllegalArgumentException(MessageFormat.format("addressbookId is not valid: {0}", addressbookId)); //NOI18N
+               }
+
+               // Get query instance
+               Query query = this.getEntityManager().createNamedQuery("SearchAddressbookById", UserAddressbook.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("id", addressbookId); //NOI18N
+
+               // Default is not valid
+               boolean isValid = false;
+
+               // Try it again, yes no other way
+               try {
+                       // Get single result
+                       Addressbook addressbook = (Addressbook) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbook={0} - FOUND!", addressbook)); //NOI18N
+
+                       // Found one!
+                       isValid = true;
+               } catch (final NoResultException ex) {
+                       // Debug log only, maybe out-dated link followed
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookIdUsed: addressbookId={0} is not valid: {1}", addressbookId, ex)); //NOI18N
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isAddressbookIdUsed: isValid={0} - EXIT!", isValid)); //NOI18N
+
+               // Return result
+               return isValid;
+       }
+
+       @Override
+       public boolean isAddressbookNameUsed (final Addressbook addressbook) {
+               // Is it not null?
+               if (null == addressbook) {
+                       // Abort here
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (addressbook.getAddressbookUser() == null) {
+                       // User instance is null
+                       throw new NullPointerException("addressbook.addressbookUser is null."); //NOI18N
+               } else if (addressbook.getAddressbookUser().getUserId() == null) {
+                       // User instance is null
+                       throw new NullPointerException("addressbook.addressbookUser.userId is null."); //NOI18N
+               } else if (addressbook.getAddressbookUser().getUserId() < 1) {
+                       // User instance is null
+                       throw new NullPointerException(MessageFormat.format("addressbook.addressbookUser.userId={0} is invalid.", addressbook.getAddressbookUser().getUserId())); //NOI18N
+               } else if (addressbook.getAddressbookName() == null) {
+                       // Address book name not set
+                       throw new NullPointerException("addressbook.addressbookName should not be null"); //NOI18N
+               } else if (addressbook.getAddressbookName().isEmpty()) {
+                       // Address book name not set
+                       throw new IllegalArgumentException("addressbook.addressbookName should not be empty"); //NOI18N
+               }
+
+               // Get query instance
+               Query query = this.getEntityManager().createNamedQuery("SearchUserAddressbookName", Addressbook.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("user", addressbook.getAddressbookUser()); //NOI18N
+               query.setParameter("name", addressbook.getAddressbookName()); //NOI18N
+
+               // Default is not found
+               boolean isUsed = false;
+
+               // Try it
+               try {
+                       // Get a single result
+                       Addressbook dummy = (Addressbook) query.getSingleResult();
+
+                       // Log it
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: Found an address book: {0}", dummy)); //NOI18N
+
+                       // Found one
+                       isUsed = true;
+               } catch (final NoResultException ex) {
+                       // No result found, so log it away
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isAddressbookNameUsed: getSingleResult() did not return a result: {0}", ex)); //NOI18N
+               }
+
+               // Return result
+               return isUsed;
+       }
+}
diff --git a/src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java b/src/java/org/mxchange/addressbook/model/shared/SharedAddressbooksSessionBean.java
new file mode 100644 (file)
index 0000000..31b1010
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.model.shared;
+
+import java.text.MessageFormat;
+import java.util.List;
+import java.util.Objects;
+import javax.ejb.Stateless;
+import javax.persistence.NoResultException;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+import org.mxchange.jjobs.exceptions.UserAlreadySharingAddressbookException;
+import org.mxchange.jjobs.model.addressbook.Addressbook;
+import org.mxchange.jjobs.model.addressbook.shared.AddressbookShare;
+import org.mxchange.jjobs.model.addressbook.shared.ShareableAddressbook;
+import org.mxchange.jjobs.model.shared.SharedAddressbooksSessionBeanRemote;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A stateless bean for handling address book sharing
+ * <p>
+ * @author Roland Haeder
+ */
+@Stateless (name = "share", mappedName = "ejb/stateless-share", description = "A stateless bean for handling shared addressbooks")
+public class SharedAddressbooksSessionBean extends BaseDatabaseBean implements SharedAddressbooksSessionBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 136_984_697_285_694_710L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<ShareableAddressbook> allSharedAddressbooks (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allSharedAddressbooks: user={0} - CALLED!", user)); //NOI18N
+
+               // Is user null?
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Null userId is not allowed
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Not allowed value
+                       throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N
+               }
+
+               // Get named query
+               Query query = this.getEntityManager().createNamedQuery("SearchUserSharedAddressbooks", List.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("user", user); //NOI18N
+
+               // Return full list
+               List<ShareableAddressbook> list = query.getResultList();
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("allSharedAddressbooks: list.size()={0} - EXIT!", list.size()));
+
+               // Return list
+               return list;
+       }
+
+       @Override
+       public Boolean isUserSharingAddressbooks (final User user) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: user={0} - CALLED!", user)); //NOI18N
+
+               // Is user null?
+               if (null == user) {
+                       // Throw NPE
+                       throw new NullPointerException("user is null"); //NOI18N
+               } else if (user.getUserId() == null) {
+                       // Null userId is not allowed
+                       throw new NullPointerException("user.userId is null"); //NOI18N
+               } else if (user.getUserId() < 1) {
+                       // Not allowed value
+                       throw new IllegalArgumentException(MessageFormat.format("user.UserId={0} is an invalid value", user.getUserId())); //NOI18N
+               }
+
+               // Get results
+               List<ShareableAddressbook> list = this.allSharedAddressbooks(user);
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserSharingAddressbooks: list.size()={0}", list.size())); //NOI18N
+
+               // Is it not empty?
+               Boolean isSharing = (!list.isEmpty());
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserSharingAddressbooks: iSharing={0} - EXIT!", isSharing)); //NOI18N
+
+               // Return it
+               return isSharing;
+       }
+
+       @Override
+       public ShareableAddressbook startSharing (final User sharee, final Addressbook addressbook) throws UserAlreadySharingAddressbookException {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("startSharing: sharee={0},addressbook={1} - CALLED!", sharee, addressbook)); //NOI18N
+
+               // Check all conditions
+               if (null == sharee) {
+                       // Throw NPE
+                       throw new NullPointerException("sharee is null"); //NOI18N
+               } else if (sharee.getUserId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("sharee.userId is null"); //NOI18N
+               } else if (sharee.getUserId() < 1) {
+                       // Invalid id number
+                       throw new IllegalStateException(MessageFormat.format("sharee.userId={0} is invalid", sharee.getUserId())); //NOI18N
+               } else if (null == addressbook) {
+                       // Throw NPE again
+                       throw new NullPointerException("addressbook is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() == null) {
+                       // Throw NPE again
+                       throw new NullPointerException("addressbook.addressbookId is null"); //NOI18N
+               } else if (addressbook.getAddressbookId() < 1) {
+                       // Invalid id number
+                       throw new IllegalArgumentException(MessageFormat.format("addressbook.addressbookId={0} is invalid.", addressbook.getAddressbookId())); //NOI18N
+               } else if (Objects.equals(addressbook.getAddressbookUser(), sharee)) {
+                       // Sharing with yourself!
+                       throw new IllegalStateException("User tries to share with himself."); //NOI18N
+               }
+
+               // Is the entry already there?
+               if (this.isUserAlreadySharingAddressbook(addressbook, sharee)) {
+                       // Abort here
+                       throw new UserAlreadySharingAddressbookException(addressbook, sharee);
+               }
+
+               // All fine so far, then create the instance
+               ShareableAddressbook share = new AddressbookShare(addressbook, sharee);
+
+               // Debug message
+               this.getLoggerBeanLocal().logDebug(MessageFormat.format("startSharing: share={0}", share)); //NOI18N
+
+               // Persist it
+               this.getEntityManager().persist(share);
+
+               // Flush to get id number
+               this.getEntityManager().flush();
+
+               // Return updated instance
+               return share;
+       }
+
+       /**
+        * Checks whether the owner of the given address book is already sharing it
+        * with the sharee.
+        * <p>
+        * @param addressbook Address book to be shared with
+        * @param sharee User sharee instance
+        * <p>
+        * @return Wether the address book is already shared with the sharee
+        */
+       private boolean isUserAlreadySharingAddressbook (final Addressbook addressbook, final User sharee) {
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserAlreadySharingAddressbook: addressbook={0},sharee={1} - CALLED!", addressbook, sharee)); //NOI18N
+
+               // Get named query
+               Query query = this.getEntityManager().createNamedQuery("SearchShareeAddressbookShare", AddressbookShare.class); //NOI18N
+
+               // Set parameter
+               query.setParameter("addressbook", addressbook); //NOI18N
+               query.setParameter("sharee", sharee); //NOI18N
+
+               // Default is not found
+               boolean isFound = false;
+
+               // Try it
+               try {
+                       // Get single instance
+                       ShareableAddressbook share = (ShareableAddressbook) query.getSingleResult();
+
+                       // Debug message
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserAlreadySharingAddressbook: share={0} - FOUND!", share)); //NOI18N
+
+                       // Set found
+                       isFound = true;
+               } catch (final NoResultException ex) {
+                       // Not found, log exception
+                       this.getLoggerBeanLocal().logDebug(MessageFormat.format("isUserAlreadySharingAddressbook: Notfound. Exception: {0}", ex)); //NOI18N
+               }
+
+               // Trace message
+               this.getLoggerBeanLocal().logTrace(MessageFormat.format("isUserAlreadySharingAddressbook: isFound={0} - EXIT!", isFound)); //NOI18N
+
+               // Return it
+               return isFound;
+       }
+}
diff --git a/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java b/src/java/org/mxchange/jcountry/data/AddressbookCountrySingletonBean.java
new file mode 100644 (file)
index 0000000..da3e44a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcountry.data;
+
+import java.util.List;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+
+/**
+ * A singleton bean for country informations
+ * <p>
+ * @author Roland Haeder
+ */
+@Startup
+@Singleton (name = "country", mappedName = "ejb/addressbook-singleton-country", description = "A singleton session bean for country informations")
+public class AddressbookCountrySingletonBean extends BaseDatabaseBean implements AddressbookCountrySingletonBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 15_846_983_298_691_207L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<Country> allCountries () {
+               // Init query
+               Query query = this.getEntityManager().createNamedQuery("AllCountries", List.class); //NOI18N
+
+               // Return it
+               return query.getResultList();
+       }
+
+}
diff --git a/src/java/org/mxchange/jphone/phonenumbers/smsprovider/AddressbookSmsProviderSingletonBean.java b/src/java/org/mxchange/jphone/phonenumbers/smsprovider/AddressbookSmsProviderSingletonBean.java
new file mode 100644 (file)
index 0000000..3f348d2
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jphone.phonenumbers.smsprovider;
+
+import java.util.List;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.persistence.Query;
+import org.mxchange.jcoreee.database.BaseDatabaseBean;
+
+/**
+ * A singleton bean for country informations
+ * <p>
+ * @author Roland Haeder
+ */
+@Startup
+@Singleton (name = "smsprovider", mappedName = "ejb/addressbook-singleton-smsprovider", description = "A singleton session bean for SMS provider informations")
+public class AddressbookSmsProviderSingletonBean extends BaseDatabaseBean implements AddressbookSmsProviderSingletonBeanRemote {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 15_846_983_298_691_207L;
+
+       @Override
+       @SuppressWarnings ("unchecked")
+       public List<SmsProvider> allSmsProvider () {
+               // Init query
+               Query query = this.getEntityManager().createNamedQuery("AllSmsProvider", List.class); //NOI18N
+
+               // Return it
+               return query.getResultList();
+       }
+
+}