--- /dev/null
+/*
+ * 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
+ }
+
+}
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;
/**
* 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);
}
@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.