]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued with project:
authorRoland Haeder <roland@mxchange.org>
Tue, 11 Aug 2015 12:06:41 +0000 (14:06 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 11 Aug 2015 12:06:41 +0000 (14:06 +0200)
- Moved call of markProductAsOrdered() to do_order.jsp
- Logged more data in some debug/trace messages
- If choose[product] is set in session, it can only be unset now, this saves some calls
- Added some trace messages
- Removed synchronized() check
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
web/finished.jsp
web/form_handler/do_order.jsp

index 5eb1ce187a7e348abb72d0ead286c6477d56834b..4ce28a5bb07bc264f30d5ee66d72973dc2a96df1 100644 (file)
@@ -402,7 +402,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                }
 
                // Get element
-               this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N
+               this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N
                String choosen = this.handleChooseFromRequestSession(product, request, session);
                this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
 
@@ -503,7 +503,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                }
 
                // Get choosen
-               this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N
+               this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N
                String choosen = this.handleChooseFromRequestSession(product, request, session);
                this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
 
@@ -625,14 +625,14 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                                this.getLogger().warn(ex);
                                return "0"; //NOI18N
                        }
-                       
+
                        // Then set it in session
                        this.setValueInSession(product, session, HTTP_PARAM_AMOUNT, object);
-                       
+
                        // And return it
                        return (String) object;
                }
-               
+
                // Trace message
                this.getLogger().trace("Calling getAmountFromSession() ..."); //NOI18N
 
@@ -664,15 +664,15 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                        // Not set
                        throw new NullPointerException("session is null"); //NOI18N
                }
-               
+
                // Get choosen
-               this.getLogger().debug("Calling handleChooseFromRequestSession() ..."); //NOI18N
+               this.getLogger().debug(MessageFormat.format("Calling handleChooseFromRequestSession({0},{1},{2}) ...", product.getName(), request, session)); //NOI18N
                String choosen = this.handleChooseFromRequestSession(product, request, session);
                this.getLogger().debug(MessageFormat.format("product={0},choosen={1}", product.getName(), choosen)); //NOI18N
-               
+
                // Must not be null
                assert(choosen instanceof String): "choosen is null"; //NOI18N
-               
+
                // Is it not choosen?
                if (choosen.isEmpty()) {
                        // Not choosen
@@ -681,10 +681,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
 
                // Get amount
                String amount = this.handleAmountFromRequestSession(product, request, session);
-               
+
                // Must not be null
                assert(amount instanceof String): "amount is not set"; //NOI18N
-               
+
                // Trace message
                this.getLogger().trace(MessageFormat.format("amount={0} - EXIT!", amount)); //NOI18N
 
@@ -904,7 +904,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                this.getLogger().trace(MessageFormat.format("product={0},session={1},attribute={2} - CALLED!", product, session, attribute)); //NOI18N
 
                // Init variable
-               Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, product.getName(), attribute));
+               Object value = this.getValueFromSession(session, String.format(HTTP_PARAM_MASK, attribute, product.getName()));
                
                this.getLogger().debug(MessageFormat.format("product={0},attribute={1},value={2}", product.getName(), attribute, value)); //NOI18N
 
@@ -924,7 +924,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         */
        private Object getValueFromSession (final HttpSession session, final String key) {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("session={043},key={1} - CALLED!", session, key)); //NOI18N
+               this.getLogger().trace(MessageFormat.format("session={0},key={1} - CALLED!", session, key)); //NOI18N
                
                // Init value
                Object value = null;
@@ -971,12 +971,18 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Check request method
                if (!"POST".equals(request.getMethod())) { //NOI18N
                        // Not POST, so get from session
+                       this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session));
                        return this.getChooseFromSession(product, session);
                } else if (this.isProductOrdered(product, session)) {
                        // Product is ordered
+                       this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session));
+                       return this.getChooseFromSession(product, session);
+               } else if (!this.getChooseFromSession(product, session).isEmpty()) {
+                       // Found in session
+                       this.getLogger().trace(MessageFormat.format("Calling this.getChooseFromSession({0},{1}) ... - EXIT!", product.getName(), session));
                        return this.getChooseFromSession(product, session);
                }
-               
+
                // Get reqzest element
                object = request.getParameter(String.format(HTTP_PARAM_MASK, HTTP_PARAM_CHOOSE, product.getName()));
                this.getLogger().debug(MessageFormat.format("product={0},object={1}", product.getName(), object)); //NOI18N
@@ -1044,13 +1050,11 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
        private void setValueInSession (final Product product, final HttpSession session, final String keyPart, final Object value) {
                // Trace message
                this.getLogger().trace(MessageFormat.format("product={0},session={1},keyPart={2},value={3} - CALLED!", product, session, keyPart, value)); //NOI18N
-               
-               synchronized(session) {
-                       // Set it synced
-                       this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N
-                       this.setValueInSession(session, String.format(HTTP_PARAM_MASK, product.getName(), keyPart), value);
-               }
-               
+
+               // Set it synced
+               this.getLogger().debug(MessageFormat.format("Setting value={0} for product={1},keyPart={2}", value, product.getName(), keyPart)); //NOI18N
+               this.setValueInSession(session, String.format(HTTP_PARAM_MASK, keyPart, product.getName()), value);
+
                // Trace message
                this.getLogger().trace("EXIT!"); //NOI18N
        }
index 3788ba18b2854b198f63291f4f70496ae27fd5a8..c2ca53b6a45f09b73115d08b294a29ec37b82ed3 100644 (file)
                                                <%
                                                // "Walk" over all products
                                                for (final Product product : app.getProducts()) {
-                                                       // Is it choosen?
-                                                       if (app.isProductChoosen(product, request, session)) {
-                                                               // Mark product as ordered
-                                                               app.markProductAsOrdered(product, session);
-                                                       }
                                                        %>
                                                        <tr>
                                                                <td>
index cdfe1c37724e66517a9c71183fd24ec1705079de..06c44225eecc71cf05cd4e3f93ad2b7df2cb48b6 100644 (file)
@@ -6,9 +6,10 @@
 
 <%--<%@page errorPage="errorHandler.jsp" %>--%>
 <%@page contentType="text/html" pageEncoding="UTF-8"%>
-<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %>
 <%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%>
 <%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%>
+<%@page import="org.mxchange.pizzaapplication.beans.CustomerBean" %>
+<%@page import="org.mxchange.pizzaapplication.product.Product"%>
 
 <%
        // Init application instance
        // Is it post?
        if ("POST".equals(request.getMethod())) { //NOI18N
                // Handle saving customer data and such things
+               
+               // "Walk" over all products
+               for (final Product product : app.getProducts()) {
+                       // Is it choosen?
+                       if (app.isProductChoosen(product, request, session)) {
+                               // Mark product as ordered
+                               app.markProductAsOrdered(product, session);
+                       }
+               }
+
                // Redirect to proper URL
                // @TODO Commented out for developing:
                //response.sendRedirect(request.getContextPath() + "/finished.jsp");