You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2016/05/11 19:10:10 UTC

svn commit: r1743411 - in /ofbiz/trunk: applications/order/src/org/ofbiz/order/shoppingcart/ applications/order/webapp/ordermgr/WEB-INF/actions/entry/ framework/start/lib/ framework/start/src/org/ofbiz/base/start/

Author: jleroux
Date: Wed May 11 19:10:10 2016
New Revision: 1743411

URL: http://svn.apache.org/viewvc?rev=1743411&view=rev
Log:
A patch from Ravi Lodhi for "Order term description is not getting set on adding and updating new order term" https://issues.apache.org/jira/browse/OFBIZ-7053

Steps to regenerate (Create a new order) -
1) Go to Order Entry (in Order Manager) and add the necessary detail and continue.
2) Add Order items and click on Finalize Order.
3) Continue with Order Entry Ship-To Settings.
4) Add any shipment method and continue.
5) On Order Terms Page add a term with description. Term description is not getting saved. Same case with the update term functionality.

As said Florian Montalbano:
I looked into the issue and found the root of the problem :
There are multiple functions prototype to add a term to an order and the one used wasn't using the "description" field.

Added:
    ofbiz/trunk/framework/start/lib/
    ofbiz/trunk/framework/start/lib/commons-cli-1.3.1.jar   (with props)
    ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java   (with props)
    ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java   (with props)
Modified:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=1743411&r1=1743410&r2=1743411&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Wed May 11 19:10:10 2016
@@ -1305,6 +1305,7 @@ public class ShoppingCartEvents {
         String termValueStr = request.getParameter("termValue");
         String termDaysStr = request.getParameter("termDays");
         String textValue = request.getParameter("textValue");
+        String description = request.getParameter("description");
 
         GenericValue termType = null;
         Delegator delegator = (Delegator) request.getAttribute("delegator");
@@ -1349,7 +1350,7 @@ public class ShoppingCartEvents {
 
         removeOrderTerm(request, response);
 
-        cart.addOrderTerm(termTypeId, termValue, termDays, textValue);
+        cart.addOrderTerm(termTypeId, null, termValue, termDays, textValue, description);
 
         return "success";
     }

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy?rev=1743411&r1=1743410&r2=1743411&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/OrderTerms.groovy Wed May 11 19:10:10 2016
@@ -41,6 +41,7 @@ if (request.getParameter('createNew') ==
                context.termValue = orderTerm.termValue;
                context.termDays = orderTerm.termDays;
                context.textValue = orderTerm.textValue;
+               context.description = orderTerm.description;
 
                context.termIndex = termIndexStr;
             }

Added: ofbiz/trunk/framework/start/lib/commons-cli-1.3.1.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/lib/commons-cli-1.3.1.jar?rev=1743411&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ofbiz/trunk/framework/start/lib/commons-cli-1.3.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java?rev=1743411&view=auto
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java (added)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java Wed May 11 19:10:10 2016
@@ -0,0 +1,49 @@
+package org.ofbiz.base.start;
+
+import java.util.Map;
+
+/**
+ * A command line argument passed to ofbiz
+ * 
+ * <p>
+ * A <tt>StartupCommand</tt> represents a processed command line argument passed 
+ * to ofbiz such that it is no longer a raw string but an instance of this class.
+ * For example: <code>java -jar ofbiz.jar --status</code> where status is a command.
+ * </p>
+ */
+public class StartupCommand {
+    private String name;
+    private Map<String,String> properties;
+
+    public String getName() {
+        return name;
+    }
+    public Map<String,String> getProperties() {
+        return properties;
+    }
+
+    private StartupCommand(Builder builder) {
+        this.name = builder.name;
+        this.properties = builder.properties;
+    }
+
+    public static class Builder {
+        //required parameters
+        private final String name;
+
+        //optional parameters       
+        private Map<String,String> properties;
+
+        public Builder(String name) {
+            this.name = name;
+        }
+        public Builder properties(Map<String,String> properties) {
+            this.properties = properties;
+            return this;
+        }
+
+        public StartupCommand build() {
+            return new StartupCommand(this);
+        }
+    }
+}

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java?rev=1743411&view=auto
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java (added)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java Wed May 11 19:10:10 2016
@@ -0,0 +1,220 @@
+package org.ofbiz.base.start;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+/**
+ * A utility class for processing OFBiz command line arguments
+ * 
+ * <p>
+ * Defines OFBiz startup options called through main e.g. --load-data or --help
+ * in addition to utility methods for parsing and handling these options
+ * </p> 
+ */
+public final class StartupCommandUtil {
+
+    /* 
+     * Make sure of defining the same set of values in:
+     * 
+     * - The StartupOptions defined below
+     * - The commons-cli options defined below
+     * - The getOfbizStartupOptions method defined below
+     * 
+     * Keeping these items in sync means that OFBiz behaves correctly
+     * while being decoupled from the commons-cli library and the only
+     * place where commons-cli is used is in this class
+     */
+
+    public enum StartupOption {
+        BOTH("both"),
+        HELP("help"),
+        LOAD_DATA("load-data"),
+        PORTOFFSET("portoffset"),
+        POS("pos"),
+        SHUTDOWN("shutdown"),
+        START("start"),
+        START_BATCH("batch"),
+        START_DEBUG("debug"),
+        STATUS("status"),
+        TEST("test"),
+        TEST_LIST("testlist");
+        
+        private String name;
+        private StartupOption(String name) {
+            this.name = name;
+        }
+        public String getName() {
+            return name;
+        }
+    }
+
+    private static final Option BOTH = Option.builder("b")
+            .longOpt(StartupOption.BOTH.getName())
+            .desc("Runs simultaneously both the POS (Point of Sales) application and OFBiz server")
+            .hasArg(false)
+            .build();
+    private static final Option HELP = Option.builder("?")
+            .longOpt(StartupOption.HELP.getName())
+            .desc("Prints this help screen to the user")
+            .hasArg(false)
+            .build();
+    private static final Option LOAD_DATA = Option.builder("l")
+            .longOpt(StartupOption.LOAD_DATA.getName())
+            .desc("Creates tables/load data e.g:"
+                    + System.lineSeparator()
+                    + "-l readers=seed,demo,ext"
+                    + System.lineSeparator()
+                    + "-l timeout=7200"
+                    + System.lineSeparator()
+                    + "-l delegator=default"
+                    + System.lineSeparator()
+                    + "-l group=org.ofbiz"
+                    + System.lineSeparator()
+                    + "-l dir=directory/of/files"
+                    + System.lineSeparator()
+                    + "-l file=/tmp/dataload.xml")
+            .numberOfArgs(2)
+            .valueSeparator('=')
+            .optionalArg(true)
+            .argName("key=value")
+            .build();
+    private static final Option PORTOFFSET = Option.builder("o")
+            .longOpt(StartupOption.PORTOFFSET.getName())
+            .desc("Offsets the default network port for OFBiz")
+            .hasArg()
+            .argName("offset")
+            .optionalArg(false)
+            .build();
+    private static final Option POS = Option.builder("p")
+            .longOpt(StartupOption.POS.getName())
+            .desc("Runs the POS (Point of Sales) application")
+            .hasArg(false)
+            .build();
+    private static final Option SHUTDOWN = Option.builder("d")
+            .longOpt(StartupOption.SHUTDOWN.getName())
+            .desc("Shutdown OFBiz")
+            .hasArg(false)
+            .build();
+    private static final Option START = Option.builder("u")
+            .longOpt(StartupOption.START.getName())
+            .desc("Start OFBiz")
+            .hasArg(false)
+            .build();
+    private static final Option START_BATCH = Option.builder("c")
+            .longOpt(StartupOption.START_BATCH.getName())
+            .desc("Start OFBiz in batch mode")
+            .hasArg(false)
+            .build();
+    private static final Option START_DEBUG = Option.builder("g")
+            .longOpt(StartupOption.START_DEBUG.getName())
+            .desc("Start OFBiz in debug mode")
+            .hasArg(false)
+            .build();
+    private static final Option STATUS = Option.builder("s")
+            .longOpt(StartupOption.STATUS.getName())
+            .desc("Gives the status of OFBiz")
+            .hasArg(false)
+            .build();
+    private static final Option TEST = Option.builder("t")
+            .longOpt(StartupOption.TEST.getName())
+            .desc("Runs the selected test or all if none selected e.g.: "
+                    + System.lineSeparator()
+                    + "--test component=base --test case=somecase"
+                    + System.lineSeparator()
+                    + "--test component=base --test suitename=somesuite")
+            .numberOfArgs(2)
+            .valueSeparator('=')
+            .optionalArg(true)
+            .argName("key=value")
+            .build();
+    private static final Option TEST_LIST = Option.builder("x")
+            .longOpt(StartupOption.TEST_LIST.getName())
+            .desc("run the tests configured through testtools e.g.: "
+                    + System.lineSeparator()
+                    + "--testlist file=runtime/test-list-build.xml"
+                    + System.lineSeparator()
+                    + "--testlist mode=ant or --testlist mode=text")
+            .numberOfArgs(2)
+            .valueSeparator('=')
+            .optionalArg(true)
+            .argName("key=value")
+            .build();
+
+    static final List<StartupCommand> parseOfbizCommands(final String[] args) throws StartupException {
+        CommandLine commandLine = null;
+        CommandLineParser parser = new DefaultParser();
+        try {
+            commandLine = parser.parse(StartupCommandUtil.getOfbizStartupOptions(), args);
+        } catch (ParseException e) {
+            throw new StartupException(e.getMessage());
+        }
+        if(!commandLine.getArgList().isEmpty()) {
+            throw new StartupException("unrecognized options / properties: " + commandLine.getArgList());
+        }
+        //TODO add validation logic for each command's options
+        return mapCommonsCliOptionsToStartupCommands(commandLine);
+    }
+
+    static final void printOfbizStartupHelp(final PrintStream printStream) {
+        HelpFormatter formatter = new HelpFormatter();
+        formatter.printHelp(
+                new PrintWriter(printStream, true),
+                HelpFormatter.DEFAULT_WIDTH,
+                "java -jar ofbiz.jar",
+                System.lineSeparator() + "Executes OFBiz command e.g. start, shutdown, check status, etc",
+                getOfbizStartupOptions(),
+                HelpFormatter.DEFAULT_LEFT_PAD,
+                HelpFormatter.DEFAULT_DESC_PAD,
+                "note: Only one command can execute at a time. Portoffset may be appended",
+                true);
+    }
+
+    private static final List<StartupCommand> mapCommonsCliOptionsToStartupCommands(final CommandLine commandLine) {
+        List<Option> optionList = Arrays.asList(commandLine.getOptions()); 
+        return optionList.stream()
+                .map(option -> new StartupCommand.Builder(option.getLongOpt())
+                    .properties(populateMapFromProperties(commandLine.getOptionProperties(option.getLongOpt())))
+                    .build())
+                .collect(Collectors.toList());
+    }
+
+    private static final Map<String,String> populateMapFromProperties(Properties properties) {
+        return properties.entrySet().stream().collect(Collectors.toMap(
+                entry -> String.valueOf(entry.getKey()),
+                entry -> String.valueOf(entry.getValue())));
+    }
+
+    private static final Options getOfbizStartupOptions() {
+        OptionGroup ofbizCommandOptions = new OptionGroup();
+        ofbizCommandOptions.addOption(BOTH);
+        ofbizCommandOptions.addOption(HELP);
+        ofbizCommandOptions.addOption(LOAD_DATA);
+        ofbizCommandOptions.addOption(POS);
+        ofbizCommandOptions.addOption(SHUTDOWN);
+        ofbizCommandOptions.addOption(START);
+        ofbizCommandOptions.addOption(START_BATCH);
+        ofbizCommandOptions.addOption(START_DEBUG);
+        ofbizCommandOptions.addOption(STATUS);
+        ofbizCommandOptions.addOption(TEST);
+        ofbizCommandOptions.addOption(TEST_LIST);
+
+        Options options = new Options();
+        options.addOptionGroup(ofbizCommandOptions);
+        options.addOption(PORTOFFSET);
+        return options;
+    }
+}

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/StartupCommandUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain