]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Fri, 9 Oct 2015 19:33:57 +0000 (21:33 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 9 Oct 2015 19:33:57 +0000 (21:33 +0200)
- added constructor with address book name
- added Exception AddressbookNameAlreadyUsedException
- added new business methods createAddressbook() and isAddressbookNameUsed()

src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java [new file with mode: 0644]
src/org/mxchange/addressbook/model/addressbook/AddressbookSessionBeanRemote.java
src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java

diff --git a/src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java b/src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java
new file mode 100644 (file)
index 0000000..cb8f4d9
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 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.exceptions;
+
+import java.text.MessageFormat;
+import org.mxchange.addressbook.model.addressbook.Addressbook;
+
+/**
+ * An exception thrown when the user has already used the name.
+ * <p>
+ * @author Roland Haeder
+ */
+public class AddressbookNameAlreadyUsedException extends Exception {
+
+       /**
+        * Constructor with address book instance
+        * <p>
+        * @param addressbook Address book instance
+        */
+       public AddressbookNameAlreadyUsedException(final Addressbook addressbook) {
+               super(MessageFormat.format("User {0} has already used the name {1}.", addressbook.getAddressbookUser(), addressbook.getAddressbookName())); //NOI18N
+       }
+
+}
index b8f3c43e86ba7a1acadefa3829e0a196f4c43bc1..3ec1bcc883c94eb28004cad55e478175cf049c01 100644 (file)
@@ -19,6 +19,7 @@ package org.mxchange.addressbook.model.addressbook;
 import java.io.Serializable;
 import java.util.List;
 import javax.ejb.Remote;
+import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException;
 import org.mxchange.jusercore.model.user.User;
 
 /**
@@ -33,7 +34,29 @@ public interface AddressbookSessionBeanRemote extends Serializable {
         * Some "getter" for a list of address books the logged-in user has created
         * <p>
         * @param loggedInUser Logged-in user
+        * <p>
         * @return List of all address books
         */
-       public List<Addressbook> getUsersList (final User loggedInUser);
+       public List<Addressbook> getUsersList(final User loggedInUser);
+
+       /**
+        * Creates given address book by persisting it. A User instance must be set,
+        * else an exception is thrown.
+        * <p>
+        * @param addressbook Address book instance to create
+        * <p>
+        * @return Updated address book instance
+        * <p>
+        * @throws org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException If the address book's name has already been used by the user.
+        */
+       public Addressbook createAddressbook(final Addressbook addressbook) throws AddressbookNameAlreadyUsedException;
+
+       /**
+        * Checks if the given address book's name is already used by the user.
+        * <p>
+        * @param addressbook Address bok instance to check
+        * <p>
+        * @return Whether the name has already been used by the user
+        */
+       public boolean isAddressbookNameUsed(final Addressbook addressbook);
 }
index 730e9498cace4a02aefcdbf49cb17ce4e060726b..05dda5ad660efa262ba77d969a79c1f3fbc9a437 100644 (file)
@@ -94,6 +94,14 @@ public class UserAddressbook implements Addressbook, Comparable<Addressbook> {
        @Column (name = "addressbook_name", length = 50, nullable = false)
        private String addressbookName;
 
+       /**
+        * Public constructor with address book name
+        * @param addressbookName Address book name
+        */
+       public UserAddressbook(final String addressbookName) {
+               this.addressbookName = addressbookName;
+       }
+
        @Override
        public int compareTo (final Addressbook addressbook) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.