From: Roland Haeder Date: Thu, 15 Oct 2015 13:17:05 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3ea04dbb247bc6b57198b3268e183f815f1b86cf;p=jfinancials-war.git Continued: - added more fields, such as address book user (=owner), when it has been created - added event observer method for when an address book has been loaded and forward that data to the bean - added some (untested) output of the address book data Signed-off-by:Roland Häder --- diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData index cfb53da2..50c17165 100644 --- a/nbproject/faces-config.NavData +++ b/nbproject/faces-config.NavData @@ -31,8 +31,8 @@ - + diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java index b50a4189..d9c19638 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java @@ -18,11 +18,13 @@ package org.mxchange.addressbook.beans.addressbook; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; import javax.annotation.PostConstruct; import javax.enterprise.context.SessionScoped; +import javax.enterprise.event.Observes; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; @@ -30,6 +32,7 @@ import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.mxchange.addressbook.beans.login.UserLoginWebController; +import org.mxchange.addressbook.events.AddressbookLoadedEvent; import org.mxchange.addressbook.exceptions.AddressbookNameAlreadyUsedException; import org.mxchange.addressbook.model.addressbook.Addressbook; import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote; @@ -37,6 +40,7 @@ import org.mxchange.addressbook.model.addressbook.UserAddressbook; import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry; import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook; import org.mxchange.addressbook.model.addressbook.status.AddressbokStatus; +import org.mxchange.jusercore.model.user.User; /** * A user bean (controller) @@ -62,12 +66,20 @@ public class AddressbookWebBean implements AddressbookWebController { */ private Long addressbookId; - /** * Name of the address book */ private String addressbookName; + /** + * When this address book has been created + */ + private Calendar addressbookCreated; + + /** + * Who owns this address book + */ + private User addressbookUser; /** * Login controller @@ -80,7 +92,6 @@ public class AddressbookWebBean implements AddressbookWebController { */ private List sharedAddressbooks; - /////////////////////// Properties ///////////////////// /** * A list of all user's address books */ @@ -182,10 +193,20 @@ public class AddressbookWebBean implements AddressbookWebController { // Not logged in throw new FaceletException("This method can only be called as logged-in user."); //NOI18N } - + return Collections.unmodifiableList(this.sharedAddressbooks); } + @Override + public Calendar getAddressbookCreated () { + return this.addressbookCreated; + } + + @Override + public void setAddressbookCreated (final Calendar addressbookCreated) { + this.addressbookCreated = addressbookCreated; + } + @Override public Long getAddressbookId () { return this.addressbookId; @@ -206,6 +227,16 @@ public class AddressbookWebBean implements AddressbookWebController { this.addressbookName = addressbookName; } + @Override + public User getAddressbookUser () { + return this.addressbookUser; + } + + @Override + public void setAddressbookUser (final User addressbookUser) { + this.addressbookUser = addressbookUser; + } + @Override public boolean hasCreatedAddressbooks () { // Is the user logged in? @@ -257,4 +288,34 @@ public class AddressbookWebBean implements AddressbookWebController { // Return status return isFound; } + + @Override + public void afterAddressbookLoaded (final @Observes AddressbookLoadedEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); + } else if (event.getAddressbook() == null) { + // Throw NPE again + throw new NullPointerException("event.addressbook is null"); + } else if (event.getAddressbook().getAddressbookId() == null) { + // And again a NPE + throw new NullPointerException("event.addressbook.addressbookId is null"); + } else if (event.getAddressbook().getAddressbookId() < 1) { + // Invalid id number + throw new IllegalArgumentException("Address book instance " + event.getAddressbook() + " has invalid id number: " + event.getAddressbook().getAddressbookId()); + } else if (event.getAddressbook().getAddressbookUser() == null) { + // One more NPE ... + throw new NullPointerException("event.addressbook.addressbookUser is null"); + } + + // Get address book instance + Addressbook addressbook = event.getAddressbook(); + + // Set address book data + this.setAddressbookId(addressbook.getAddressbookId()); + this.setAddressbookName(addressbook.getAddressbookName()); + this.setAddressbookUser(addressbook.getAddressbookUser()); + this.setAddressbookCreated(addressbook.getAddressbookCreated()); + } } diff --git a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java index 38856559..463e1a07 100644 --- a/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java +++ b/src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java @@ -17,10 +17,13 @@ package org.mxchange.addressbook.beans.addressbook; import java.io.Serializable; +import java.util.Calendar; import java.util.List; +import org.mxchange.addressbook.events.AddressbookLoadedEvent; import org.mxchange.addressbook.model.addressbook.Addressbook; import org.mxchange.addressbook.model.addressbook.entry.AddressbookEntry; import org.mxchange.addressbook.model.addressbook.shared.ShareableAddressbook; +import org.mxchange.jusercore.model.user.User; /** * An interface for user beans @@ -114,4 +117,40 @@ public interface AddressbookWebController extends Serializable { * @param addressbookId Address book id number */ void setAddressbookId (final Long addressbookId); + + /** + * Getter for address book user (owner) + *

+ * @return Address book user (owner) + */ + User getAddressbookUser (); + + /** + * Setter for address book user (owner) + *

+ * @param addressbookUser Address book user (owner) + */ + void setAddressbookUser (final User addressbookUser); + + /** + * Getter for when the address book has been created + *

+ * @return When the address book has been created + */ + Calendar getAddressbookCreated (); + + /** + * Setter for when the address book has been created + *

+ * @param addressbookCreated When the address book has been created + */ + void setAddressbookCreated (final Calendar addressbookCreated); + + /** + * This method is called when an address book has been successfully loaded + * from JPA. + *

+ * @param event Event with address book instance + */ + public void afterAddressbookLoaded (final AddressbookLoadedEvent event); } diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index d795388b..5404747b 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -221,3 +221,6 @@ PARAMETER_USER_ID_MISSING=Benutzernummer nicht angegeben. PARAMETER_USER_ID_INVALID=Der angeklickte Link ist nicht mehr g\u00fcltig: Den Benutzer mit der Id-Nummer existiert nicht (mehr). PARAMETER_USER_ID_NOT_FOUND=Benutzeraccount mit der Id-Nummer nicht gefunden. TABLE_HEADER_ERROR_HANDLING_USER_ID=Fehler beim Verarbeiten der Benutzernummer: +TABLE_HEADER_SHOW_ADDRESSBOOK=Adressbuchdaten: +LINK_LOGIN_START_SHARING_ADDRESSBOOK=Mit jemandem dieses Adressbuch teilen +LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE=Dieses Adresssbuch k\u00f6nnen Sie mit einem anderen Benutzer teilen. Dadurch kann er Ihre Kontakte sehen. diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 12102b26..47d5265d 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -221,3 +221,6 @@ PARAMETER_USER_ID_MISSING=No user id number provided PARAMETER_USER_ID_INVALID=The clicked link is no longer valid: The user with provided id number does not exist (anymore). PARAMETER_USER_ID_NOT_FOUND=User account with given id number not found. TABLE_HEADER_ERROR_HANDLING_USER_ID=Error while handling user id: +TABLE_HEADER_SHOW_ADDRESSBOOK=Address book data: +LINK_LOGIN_START_SHARING_ADDRESSBOOK=Start sharing this address book with another user +LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE=You can start sharing this address book with anther user. Then he cann see your contacts. diff --git a/web/login/login_show_addressbook.xhtml b/web/login/login_show_addressbook.xhtml index 36aebb7f..0d2b78bd 100644 --- a/web/login/login_show_addressbook.xhtml +++ b/web/login/login_show_addressbook.xhtml @@ -21,9 +21,46 @@ - - ID: #{addressbookController.addressbookId} - +

+
+ #{msg.TABLE_HEADER_SHOW_ADDRESSBOOK} +
+ +
+ + + #{msg.ADDRESSBOOK_ID} + + + + + #{msg.ADDRESSBOOK_NAME} + + + + + #{msg.ADDRESSBOOK_OWNER} + + + + + #{msg.ADDRESSBOOK_CREATED} + + + + + +
+ + +