+ /**
+ * Default constructor for entity manager
+ */
+ protected AddressbookShare () {
+ }
+
+ /**
+ * Constructor with address book and sharee instance. Both parameters must
+ * not be null, their id numbers must be set and the adress book's user
+ * instance must be set and have a valid id set.
+ * <p>
+ * @param addressbook Address book instance
+ * @param sharee User sharee instance
+ */
+ public AddressbookShare (final Addressbook addressbook, final User sharee) {
+ // Call protected constructor
+ this();
+
+ // 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
+ }
+
+ // Set all instances
+ this.shareAddressbook = addressbook;
+ this.shareUserOwner = addressbook.getAddressbookUser();
+ this.shareUserSharee = sharee;
+ }
+