From: Roland Haeder Date: Fri, 9 Oct 2015 19:33:57 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=50fefc73d1ad8e2301d0f8fb77c0fd1ee0b5760b;p=jfinancials-lib.git Continued: - added constructor with address book name - added Exception AddressbookNameAlreadyUsedException - added new business methods createAddressbook() and isAddressbookNameUsed() --- diff --git a/src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java b/src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java new file mode 100644 index 0000000..cb8f4d9 --- /dev/null +++ b/src/org/mxchange/addressbook/exceptions/AddressbookNameAlreadyUsedException.java @@ -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 . + */ +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. + *

+ * @author Roland Haeder + */ +public class AddressbookNameAlreadyUsedException extends Exception { + + /** + * Constructor with address book instance + *

+ * @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 + } + +} diff --git a/src/org/mxchange/addressbook/model/addressbook/AddressbookSessionBeanRemote.java b/src/org/mxchange/addressbook/model/addressbook/AddressbookSessionBeanRemote.java index b8f3c43..3ec1bcc 100644 --- a/src/org/mxchange/addressbook/model/addressbook/AddressbookSessionBeanRemote.java +++ b/src/org/mxchange/addressbook/model/addressbook/AddressbookSessionBeanRemote.java @@ -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 *

* @param loggedInUser Logged-in user + *

* @return List of all address books */ - public List getUsersList (final User loggedInUser); + public List getUsersList(final User loggedInUser); + + /** + * Creates given address book by persisting it. A User instance must be set, + * else an exception is thrown. + *

+ * @param addressbook Address book instance to create + *

+ * @return Updated address book instance + *

+ * @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. + *

+ * @param addressbook Address bok instance to check + *

+ * @return Whether the name has already been used by the user + */ + public boolean isAddressbookNameUsed(final Addressbook addressbook); } diff --git a/src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java b/src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java index 730e949..05dda5a 100644 --- a/src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java +++ b/src/org/mxchange/addressbook/model/addressbook/UserAddressbook.java @@ -94,6 +94,14 @@ public class UserAddressbook implements Addressbook, Comparable { @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.