]> git.mxchange.org Git - addressbook-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 13:17:05 +0000 (15:17 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 15 Oct 2015 13:28:28 +0000 (15:28 +0200)
- 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 <roland@mxchange.org>

nbproject/faces-config.NavData
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebBean.java
src/java/org/mxchange/addressbook/beans/addressbook/AddressbookWebController.java
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
web/login/login_show_addressbook.xhtml

index cfb53da23519d5be52c7a546173925e588057e5c..50c17165c559ef9a5b30440957a95e0ed07dacb9 100644 (file)
@@ -31,8 +31,8 @@
         <Node id="login/login_edit_user_data.xhtml" x="1150" y="150" zoom="true"/>
         <Node id="user/lost_passwd.xhtml" x="900" y="300" zoom="true"/>
         <Node id="*" x="650" y="150" zoom="true"/>
-        <Node id="terms.xhtml" x="150" y="600" zoom="true"/>
         <Node id="login/login_own_addressbooks.xhtml" x="400" y="150" zoom="true"/>
+        <Node id="terms.xhtml" x="150" y="600" zoom="true"/>
         <Node id="user/register_done.xhtml" x="1150" y="300" zoom="true"/>
         <Node id="bye.xhtml" x="650" y="300" zoom="true"/>
         <Node id="login/login_shared_addressbooks.xhtml" x="1150" y="450" zoom="true"/>
index b50a418923c0b1f12380aa0bbdf3a02d341ada08..d9c19638433cfe0bde7310412f8eb928c8632fbb 100644 (file)
@@ -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<ShareableAddressbook> 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());
+       }
 }
index 388565595f12e5827ed304ff74c61fead4ff6be4..463e1a0771bb9be94beaba03e2715d622ff28e7e 100644 (file)
 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)
+        * <p>
+        * @return Address book user (owner)
+        */
+       User getAddressbookUser ();
+
+       /**
+        * Setter for address book user (owner)
+        * <p>
+        * @param addressbookUser Address book user (owner)
+        */
+       void setAddressbookUser (final User addressbookUser);
+
+       /**
+        * Getter for when the address book has been created
+        * <p>
+        * @return When the address book has been created
+        */
+       Calendar getAddressbookCreated ();
+
+       /**
+        * Setter for when the address book has been created
+        * <p>
+        * @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.
+        * <p>
+        * @param event Event with address book instance
+        */
+       public void afterAddressbookLoaded (final AddressbookLoadedEvent event);
 }
index d795388b8c8d7633690425f8d8eeb29a17ace9e1..5404747b3927fc610952229867a8ce8fbe8ab5f4 100644 (file)
@@ -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.
index 12102b26ba8e9c7a7d92cdd669c3f2c01c1a9062..47d5265d69dca13aa476fa6f624838c5d5e7675b 100644 (file)
@@ -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.
index 36aebb7f73930e4b93535295060ad15ac9a3883a..0d2b78bd72e756de9af55cf56bd62164bf5deb25 100644 (file)
                </ui:define>
 
                <ui:define name="content">
-                       <h:panelGrid headerClass="table_header" footerClass="table_footer" class="table" columns="3">
-                               ID: #{addressbookController.addressbookId}
-                       </h:panelGrid>
+                       <div class="table_big">
+                               <div class="table_header">
+                                       #{msg.TABLE_HEADER_SHOW_ADDRESSBOOK}
+                               </div>
+
+                               <div class="para">
+                                       <h:panelGrid headerClass="table_header" footerClass="table_footer" class="table" columns="3">
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.ADDRESSBOOK_ID}</f:facet>
+                                                       <h:outputText id="addressbookId" value="#{addressbookController.addressbookId}" />
+                                               </h:column>
+
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.ADDRESSBOOK_NAME}</f:facet>
+                                                       <h:outputText id="addressbookName" value="#{addressbookController.addressbookName}" />
+                                               </h:column>
+
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.ADDRESSBOOK_OWNER}</f:facet>
+                                                       <h:link id="addressbookUser" outcome="user_profile" value="#{addressbookController.addressbookUser.userName}" />
+                                               </h:column>
+
+                                               <h:column>
+                                                       <f:facet name="header">#{msg.ADDRESSBOOK_CREATED}</f:facet>
+                                                       <h:outputFormat id="addressbookCreated" value="#{addressbook.addressbookCreated.time}" title="#{msg.ADDRESSBOOK_CREATED_TITLE}">
+                                                               <f:convertDateTime for="addressbookCreated" type="both" timeStyle="short" dateStyle="medium" />
+                                                       </h:outputFormat>
+                                               </h:column>
+                                       </h:panelGrid>
+                               </div>
+
+                               <div class="table_footer">
+                                       <ui:fragment rendered="#{addressbookController.isOwnAddressbook()}">
+                                               <h:link id="startSharing" outcome="login_start_sharing_addressbook" value="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK}" title="#{msg.LINK_LOGIN_START_SHARING_ADDRESSBOOK_TITLE}" />
+                                       </ui:fragment>
+                                       <ui:fragment rendered="#{addressbookController.isOtherAddressbook()}">
+                                               Bla bla
+                                       </ui:fragment>
+                               </div>
+                       </div>
                </ui:define>
        </ui:composition>
 </html>