Related issue 27542: Added refactor to improve readability of the code.
authorInigo Sanchez <inigo.sanchez@openbravo.com>
Fri, 28 Nov 2014 17:38:27 +0100
changeset 25519 a8bd0fc47456
parent 25518 5da17f50c4b0
child 25520 d695301d91b6
Related issue 27542: Added refactor to improve readability of the code.

For each "case" in the main "switch" has been created a method that implements
the functionality associated with the case.

It has also been created a general method that could replace the functionality
of two of the previous methods. This method is called changeAllOptionsDatabase().
build.xml
src/org/openbravo/configuration/ConfigurationApp.java
--- a/build.xml	Fri Dec 05 08:51:10 2014 +0100
+++ b/build.xml	Fri Nov 28 17:38:27 2014 +0100
@@ -996,19 +996,18 @@
   </target>
   
   <target name="setup.compile">
-          <echo message="Compiling application configuration classes..." />
-	   <mkdir dir="build/classes" />
-          <javac srcdir="src/org/openbravo/configuration" destdir="build/classes" includeantruntime="false">
-             <classpath refid="project.class.path"/>  
-          </javac>
+	<mkdir dir="build/classes" />
+    <javac srcdir="src/org/openbravo/configuration" destdir="build/classes" includeantruntime="false">
+      <classpath refid="project.class.path"/>  
+    </javac>
   </target>
 
   <target name="setup" depends="setup.compile">    
-      <echo message="Launching configuration application..."/>
-      <taskdef name="configurationApp" classname="org.openbravo.configuration.ConfigurationApp">
-        <classpath refid="project.class.path" />
-      </taskdef>
-      <configurationApp/>
+    <echo message="Launching configuration application..."/>
+    <taskdef name="configurationApp" classname="org.openbravo.configuration.ConfigurationApp">
+      <classpath refid="project.class.path" />
+    </taskdef>
+    <configurationApp/>
     </target>
   
   <target name="package.core" depends="init, set.version.number">
--- a/src/org/openbravo/configuration/ConfigurationApp.java	Fri Dec 05 08:51:10 2014 +0100
+++ b/src/org/openbravo/configuration/ConfigurationApp.java	Fri Nov 28 17:38:27 2014 +0100
@@ -70,24 +70,20 @@
   private final static String CLASSPATH = ".classpath";
 
   private final static String OPENBRAVO_LICENSE = BASEDIR + "/legal/Licensing.txt";
-  private static final int LINES_SHOWING_LICENSE = 50;
+  private final static int LINES_SHOWING_LICENSE = 50;
 
+  private int optionMod = 0, numOptionsDDBB = 0, mainOption = 0;
+  private Scanner licenseIn = new Scanner(System.in);
+  private Scanner inp = new Scanner(System.in);
+
+  /**
+   * This is the main method that is invoke by ant setup task.
+   * 
+   */
   public void execute() {
-    Scanner licenseIn = new Scanner(System.in);
-    Scanner inp = new Scanner(System.in);
-    int option, menuOption = 0, optionMod = 0, numOptionsDDBB = 0, mainOption = 0, optionConfigure = 0;
-    String optionString = "", optionS, input, menuOptionS;
-    boolean numberOk, isChange, isChangeO, isChangeL, menuOptionOk;
     Project p = getProject();
-
     // Copy templates and rename files
-    fileCopyTemplate(FORMAT_XML_TEMPLATE, FORMAT_XML, p);
-    fileCopyTemplate(LOG4J_LCF_TAMPLATE, LOG4J_LCF, p);
-    fileCopyTemplate(USERCONFIG_XML_TEMPLATE, USERCONFIG_XML, p);
-    fileCopyTemplate(OPENBRAVO_PROPERTIES_TEMPLATE, OPENBRAVO_PROPERTIES, p);
-    fileCopyTemplate(COMMON_COMPONENT_TEMPLATE, COMMON_COMPONENT, p);
-    fileCopyTemplate(CLASSPATH_TEMPLATE, CLASSPATH, p);
-
+    fileCopySomeTemplates(p);
     while (mainOption != -1) {
       switch (mainOption) {
       case 0:
@@ -97,101 +93,254 @@
         } catch (IOException e) {
           e.printStackTrace();
         }
-        p.log("Do you accept this license? [y/n]: ");
-        input = licenseIn.nextLine();
-        while (!("Y".equalsIgnoreCase(input) || "N".equalsIgnoreCase(input))) {
-          p.log("Please, introduce a correct option. Do you accept this license? [y/n]: ");
-          input = licenseIn.nextLine();
-        }
-        if ("Y".equalsIgnoreCase(input)) {
-          mainOption++;
-        } else if ("N".equalsIgnoreCase(input)) {
-          p.log("---------------------------------------------------------------------------- \n You have not successfully completed the configuration process.");
-          mainOption = -1;
-        }
+        acceptLicense(p);
         break;
       case 1:
-        p.log("---------------------------------------------------------------------------- \n Please choose one option. \n----------------------------------------------------------------------------");
-        p.log("[1]. Step-by-step configuration.");
-        p.log("[2]. Default configuration.");
-        p.log("[3]. Exit without saving.");
-        p.log("Choose an option: ");
-        mainOption++;
+        showMainMenu(p);
         break;
       case 2:
-        menuOptionOk = false;
-        do {
-          menuOptionS = inp.nextLine();
-          try {
-            menuOption = Integer.parseInt(menuOptionS);
-            menuOptionOk = true;
-          } catch (NumberFormatException e) {
-            p.log("Please, introduce a correct option: ");
-          }
-        } while (!menuOptionOk);
-        // Create options one-by-one
-        if (menuOption == 1) {
-          if (optionFirst.isEmpty()) {
-            optionFirst = createOP(p);
-          }
-          // Create optionsDDBB
-          // Oracle or Postgresql options
-          String keyValueS = "";
-          Iterator<Integer> optionBBDD = optionFirst.keySet().iterator();
-          do {
-            keyValueS = optionFirst.get(optionBBDD.next()).getChooseString();
-          } while (!(keyValueS.equals("PostgreSQL") || keyValueS.equals("Oracle")));
-          if (keyValueS.equals("Oracle")) {
-            optionOracle = createOPOracle(p);
-            numOptionsDDBB = optionOracle.size();
-          } else if (keyValueS.equals("PostgreSQL")) {
-            optionPostgreSQL = createOPPostgreSQL(p);
-            numOptionsDDBB = optionPostgreSQL.size();
-          }
-          mainOption = 3;
-          // Create all options by default.
-        } else if (menuOption == 2) {
-          if (optionFirst.isEmpty()) {
-            optionFirst = createOP(p);
-          }
-          // Oracle or Postgresql options
-          String keyValue = "";
-          Iterator<Integer> optionBBDD = optionFirst.keySet().iterator();
-          do {
-            keyValue = optionFirst.get(optionBBDD.next()).getChooseString();
-          } while (!(keyValue.equals("PostgreSQL") || keyValue.equals("Oracle")));
-          if (keyValue.equals("Oracle")) {
-            optionOracle = createOPOracle(p);
-            numOptionsDDBB = optionOracle.size();
-          } else if (keyValue.equals("PostgreSQL")) {
-            optionPostgreSQL = createOPPostgreSQL(p);
-            numOptionsDDBB = optionPostgreSQL.size();
-          }
-          if (optionLast.isEmpty()) {
-            optionLast = createOP2(p);
-          }
-          // Go to preview options configurate by default
-          mainOption = 4;
-        } else if (menuOption == 3) {
-          mainOption = 22;
-        } else {
-          p.log("Please, introduce a correct option: ");
-        }
+        selectOptionMainMenu(p);
         break;
       case 3:
-        String typeDDBB = "";
-        Map<Integer, ConfigureOption> treeMap = new TreeMap<Integer, ConfigureOption>(optionFirst);
-        for (Map.Entry<Integer, ConfigureOption> entry : treeMap.entrySet()) {
-          if (entry.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-            p.log("Please select " + entry.getValue().getAskInfo());
-            entry.getValue().getOptions(p);
-            numberOk = false;
+        configureStepByStep(p);
+        break;
+      case 4:
+        previewConfigurationOptions(p);
+        break;
+      case 5:
+        askForChangeAnOption(p);
+        break;
+      case 6:
+        changeOptionFirst(p);
+        break;
+      case 7:
+        changeAllOptionsDatabase(p, optionOracle);
+        break;
+      case 8:
+        changeAllOptionsDatabase(p, optionPostgreSQL);
+        break;
+      case 9:
+        changeAllOptionsLast(p);
+        break;
+      case 10:
+        showFinalMenu(p);
+        break;
+      case 11:
+        changeOptionDatabase(p);
+        break;
+      case 12:
+        changeOptionLast(p);
+        break;
+      case 20:
+        // All options have been selected... configure Openbravo.properties file.
+        setValuesInOpenbravoProperties(p);
+        break;
+      case 21:
+        finishConfigurationProcess(p);
+        break;
+      case 22:
+        reConfirmExit(p);
+      }
+    }
+    closeExitProgram(p);
+  }
+
+  /**
+   * This method shows message "Configuration complete".
+   * 
+   * @param p
+   */
+  private void finishConfigurationProcess(Project p) {
+    // TODO Auto-generated method stub
+    p.log("---------------------------------------------------------------------------- \n Configuration complete. \n----------------------------------------------------------------------------");
+    mainOption = -1;
+  }
+
+  /**
+   * This method changes all options in database: Oracle or PostgreSQL.
+   * 
+   * @param p
+   * @param optionDatabase
+   */
+  private void changeAllOptionsDatabase(Project p, HashMap<Integer, ConfigureOption> optionDatabase) {
+    Map<Integer, ConfigureOption> treeMapP = new TreeMap<Integer, ConfigureOption>(optionDatabase);
+    for (Map.Entry<Integer, ConfigureOption> entryP : treeMapP.entrySet()) {
+      if (entryP.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+        p.log("Please select " + entryP.getValue().getAskInfo());
+        entryP.getValue().getOptions(p);
+        boolean numberOk = false;
+        do {
+          String optionS = inp.nextLine();
+          try {
+            int option = Integer.parseInt(optionS);
+            if (option >= 0 && option < entryP.getValue().getMax()) {
+              entryP.getValue().setChoose(option);
+              entryP.getValue().setChooseString(entryP.getValue().getOptionChoose());
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
+            }
+          } catch (NumberFormatException e) {
+            if (optionS.equals("")) {
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
+            }
+          }
+        } while (!numberOk);
+      } else if (entryP.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
+        p.log("\nPlease introduce " + entryP.getValue().getAskInfo());
+        entryP.getValue().getOptions(p);
+        String optionString = inp.nextLine();
+        if (!optionString.equals("")) {
+          entryP.getValue().setChooseString(optionString);
+        }
+      }
+      optionDatabase.put(entryP.getKey(), entryP.getValue());
+      p.log("\n-------------------------\nYour choice " + entryP.getValue().getOptionChoose()
+          + "\n-------------------------\n\n");
+    }
+    // All information are introduced. Configure now last options
+    if (optionLast.isEmpty()) {
+      optionLast = createOP2(p);
+    }
+    mainOption = 9;
+  }
+
+  /**
+   * This method closes scanners and say goodbye.
+   * 
+   * @param p
+   */
+  private void closeExitProgram(Project p) {
+    inp.close();
+    licenseIn.close();
+    p.log("---------------------------------------------------------------------------- \n Thanks for use Openbravo ERP Setup. \n----------------------------------------------------------------------------");
+  }
+
+  /**
+   * This method checks that user wants to leave the program.
+   * 
+   * @param p
+   */
+  private void reConfirmExit(Project p) {
+    p.log("Do you want to exit this program? [y/n]: ");
+    String input = licenseIn.nextLine();
+    while (!("Y".equalsIgnoreCase(input) || "N".equalsIgnoreCase(input))) {
+      p.log("Please, introduce a correct option. Do you want to exit this program? [y/n]: ");
+      input = licenseIn.nextLine();
+    }
+    if ("Y".equalsIgnoreCase(input)) {
+      p.log("---------------------------------------------------------------------------- \n You have not successfully completed the configuration process.");
+      mainOption = -1;
+    } else if ("N".equalsIgnoreCase(input)) {
+      if (optionFirst.isEmpty()) {
+        mainOption = 1;
+      } else {
+        mainOption = 10;
+      }
+    }
+  }
+
+  /**
+   * This method replaces old values in Openbravo.properties by the new requested values.
+   * 
+   * @param p
+   */
+  private void setValuesInOpenbravoProperties(Project p) {
+    setValuesProperties();
+    Iterator<String> keySetIterator = replaceProperties.keySet().iterator();
+    while (keySetIterator.hasNext()) {
+      String keyForFile = keySetIterator.next();
+      replaceOptionsProperties(keyForFile + "=", replaceProperties.get(keyForFile), p);
+    }
+    mainOption = 21;
+  }
+
+  /**
+   * This method changes an option in "optionLast" like authentication class, Tomcat manager URL,
+   * ...
+   * 
+   * @param p
+   */
+  private void changeOptionLast(Project p) {
+    int keyLast = 0;
+    boolean isChangeL = false;
+    Iterator<Integer> optionBBDDlast = optionLast.keySet().iterator();
+    optionMod = optionMod - optionFirst.size() - numOptionsDDBB;
+    while ((optionBBDDlast.hasNext() && !isChangeL)) {
+      keyLast = optionBBDDlast.next();
+      if (keyLast == optionMod - 1) {
+        ConfigureOption optionChange = optionLast.get(keyLast);
+        if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+          p.log("Please select " + optionChange.getAskInfo());
+          optionChange.getOptions(p);
+          boolean numberOk = false;
+          do {
+            String optionS = inp.nextLine();
+            try {
+              int option = Integer.parseInt(optionS);
+              if (option >= 0 && option < optionChange.getMax()) {
+                optionChange.setChoose(option);
+                optionChange.setChooseString(optionChange.getOptionChoose());
+                numberOk = true;
+              } else {
+                p.log("Please, introduce a correct option: ");
+              }
+            } catch (NumberFormatException e) {
+              if (optionS.equals("")) {
+                numberOk = true;
+              } else {
+                p.log("Please, introduce a correct option: ");
+              }
+            }
+          } while (!numberOk);
+        } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
+          p.log("\nPlease introduce " + optionChange.getAskInfo());
+          optionChange.getOptions(p);
+          String optionString = inp.nextLine();
+          if (!optionString.equals("")) {
+            optionChange.setChooseString(optionString);
+          }
+        }
+        optionLast.put(optionMod - 1, optionChange);
+        p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
+            + "\n-------------------------\n\n");
+        isChangeL = true;
+      }
+    }
+    mainOption = 4;
+  }
+
+  /**
+   * This method changes an option in database [optionOracle or optionPostgreSQL] like SID, DB port,
+   * ...
+   * 
+   * @param p
+   */
+  private void changeOptionDatabase(Project p) {
+    String optionS, optionString;
+    int option;
+    if (!optionOracle.isEmpty()) {
+      int keyOracle = 0;
+      boolean isChangeO = false;
+      Iterator<Integer> optionBBDDoracle = optionOracle.keySet().iterator();
+      optionMod = optionMod - optionFirst.size();
+      while ((optionBBDDoracle.hasNext() && !isChangeO)) {
+        keyOracle = optionBBDDoracle.next();
+        if (keyOracle == optionMod - 1) {
+          ConfigureOption optionChange = optionOracle.get(keyOracle);
+          if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+            p.log("Please select " + optionChange.getAskInfo());
+            optionChange.getOptions(p);
+            boolean numberOk = false;
             do {
               optionS = inp.nextLine();
               try {
                 option = Integer.parseInt(optionS);
-                if (option >= 0 && option < entry.getValue().getMax()) {
-                  entry.getValue().setChoose(option);
+                if (option >= 0 && option < optionChange.getMax()) {
+                  optionChange.setChoose(option);
+                  optionChange.setChooseString(optionChange.getOptionChoose());
                   numberOk = true;
                 } else {
                   p.log("Please, introduce a correct option: ");
@@ -204,196 +353,40 @@
                 }
               }
             } while (!numberOk);
-          } else if (entry.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
-            p.log("\nPlease introduce " + entry.getValue().getAskInfo());
-            entry.getValue().getOptions(p);
+          } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
+            p.log("\nPlease introduce " + optionChange.getAskInfo());
+            optionChange.getOptions(p);
             optionString = inp.nextLine();
             if (!optionString.equals("")) {
-              entry.getValue().setChooseString(optionString);
+              optionChange.setChooseString(optionString);
             }
           }
-          // review
-          optionFirst.put(entry.getKey(), entry.getValue());
-          typeDDBB = entry.getValue().getOptionChoose();
-          p.log("\n-------------------------\nYour choice " + typeDDBB
+          optionOracle.put(optionMod - 1, optionChange);
+          p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
               + "\n-------------------------\n\n");
+          isChangeO = true;
         }
-        // Select Oracle or PostgreSQL
-        if (typeDDBB.equals("Oracle")) {
-          if (optionOracle.isEmpty()) {
-            optionOracle = createOPOracle(p);
-            numOptionsDDBB = optionOracle.size();
-          }
-          if (!optionPostgreSQL.isEmpty()) {
-            optionPostgreSQL.clear();
-          }
-          mainOption = 7;
-        } else if (typeDDBB.equals("PostgreSQL")) {
-          if (optionPostgreSQL.isEmpty()) {
-            optionPostgreSQL = createOPPostgreSQL(p);
-            numOptionsDDBB = optionPostgreSQL.size();
-          }
-
-          if (!optionOracle.isEmpty()) {
-            optionOracle.clear();
-          }
-          mainOption = 8;
-        }
-        break;
-      // Preview openBravo options
-      case 4:
-        p.log("---------------------------------------------------------------------------- \n Preview Openbravo ERP configuration \n----------------------------------------------------------------------------");
-        // TreeMap for show questions in order for get user parameters.
-        int numberOption = 1;
-        Map<Integer, ConfigureOption> previewOptions1 = new TreeMap<Integer, ConfigureOption>(
-            optionFirst);
-        Map<Integer, ConfigureOption> previewOptions2;
-        Map<Integer, ConfigureOption> previewOptions3 = new TreeMap<Integer, ConfigureOption>(
-            optionLast);
-        if (optionPostgreSQL.isEmpty()) {
-          previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionOracle);
-        } else if (optionOracle.isEmpty()) {
-          previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionPostgreSQL);
-        } else {
-          previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionPostgreSQL);
-        }
-        // Show all options by order asc
-        for (Map.Entry<Integer, ConfigureOption> entry : previewOptions1.entrySet()) {
-          p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
-              + entry.getValue().getOptionChoose());
-          numberOption = numberOption + 1;
-        }
-        for (Map.Entry<Integer, ConfigureOption> entry : previewOptions2.entrySet()) {
-          p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
-              + entry.getValue().getOptionChoose());
-          numberOption = numberOption + 1;
-        }
-        for (Map.Entry<Integer, ConfigureOption> entry : previewOptions3.entrySet()) {
-          p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
-              + entry.getValue().getOptionChoose());
-          numberOption = numberOption + 1;
-        }
-        mainOption = 5;
-        break;
-      // It can be changed an option...
-      case 5:
-        p.log("---------------------------------------------------------------------------- \n Do you change any option? \n----------------------------------------------------------------------------");
-        p.log("Choose [0] for continue with configuration or a number option for modify: ");
-        menuOptionOk = false;
-        do {
-          menuOptionS = inp.nextLine();
-          try {
-            optionMod = Integer.parseInt(menuOptionS);
-            if (optionMod >= 0
-                && optionMod <= optionFirst.size() + optionLast.size() + numOptionsDDBB) {
-              menuOptionOk = true;
-            } else {
-              p.log("Choose a real option: ");
-            }
-          } catch (NumberFormatException e) {
-            p.log("Choose a real option: ");
-          }
-        } while (!menuOptionOk);
-        // Accept all configuration
-        if (optionMod == 0) {
-          mainOption = 10;
-          // Options 0 to numberLastOptions + NUM_OPTIONS_LAST, change a particular option
-        } else if (optionMod > 0 && optionMod <= optionFirst.size()) {
-          mainOption = 6;
-        } else if (optionMod > optionFirst.size()
-            && optionMod <= optionFirst.size() + numOptionsDDBB) {
-          mainOption = 11;
-        } else if (optionMod > optionFirst.size() + numOptionsDDBB
-            && optionMod <= optionFirst.size() + optionLast.size() + numOptionsDDBB) {
-          mainOption = 12;
-        }
-        break;
-      // Change a option in optionFirst[]...
-      case 6:
-        int keyOpt = 0;
-        isChange = false;
-        Iterator<Integer> optionBBDD1 = optionFirst.keySet().iterator();
-        while ((optionBBDD1.hasNext() && !isChange)) {
-          keyOpt = optionBBDD1.next();
-          if (keyOpt == optionMod - 1) {
-            ConfigureOption optionChange = optionFirst.get(keyOpt);
-            if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-              p.log("Please select " + optionChange.getAskInfo());
-              optionChange.getOptions(p);
-              numberOk = false;
-              do {
-                optionS = inp.nextLine();
-                try {
-                  option = Integer.parseInt(optionS);
-                  if (option >= 0 && option < optionChange.getMax()) {
-                    optionChange.setChoose(option);
-                    optionChange.setChooseString(optionChange.getOptionChoose());
-                    numberOk = true;
-                  } else {
-                    p.log("Please, introduce a correct option: ");
-                  }
-                } catch (NumberFormatException e) {
-                  if (optionS.equals("")) {
-                    numberOk = true;
-                  } else {
-                    p.log("Please, introduce a correct option: ");
-                  }
-                }
-              } while (!numberOk);
-            } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
-              p.log("\nPlease introduce " + optionChange.getAskInfo());
-              optionChange.getOptions(p);
-              optionString = inp.nextLine();
-              if (!optionString.equals("")) {
-                optionChange.setChooseString(optionString);
-              }
-            }
-            optionFirst.put(optionMod - 1, optionChange);
-            p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
-                + "\n-------------------------\n\n");
-            isChange = true;
-            // Check a change in type of database
-            File fileO = new File(OPENBRAVO_PROPERTIES);
-            if (optionChange.getOptionChoose().equals("Oracle")) {
-              if (searchOptionsProperties(fileO, "bbdd.rdbms", p).equals("POSTGRE")) {
-                if (optionOracle.isEmpty()) {
-                  optionOracle = createOPOracle(p);
-                  numOptionsDDBB = optionOracle.size();
-                }
-                if (!optionPostgreSQL.isEmpty()) {
-                  optionPostgreSQL.clear();
-                }
-              }
-            } else if (optionChange.getOptionChoose().equals("PostgreSQL")) {
-              if (searchOptionsProperties(fileO, "bbdd.rdbms", p).equals("ORACLE")) {
-                if (optionPostgreSQL.isEmpty()) {
-                  optionPostgreSQL = createOPPostgreSQL(p);
-                  numOptionsDDBB = optionPostgreSQL.size();
-                }
-                if (!optionOracle.isEmpty()) {
-                  optionOracle.clear();
-                }
-              }
-            }
-          }
-        }
-        mainOption = 4;
-        break;
-      // Change ALL options in optionesOracle[]...
-      case 7:
-        Map<Integer, ConfigureOption> treeMapO = new TreeMap<Integer, ConfigureOption>(optionOracle);
-        for (Map.Entry<Integer, ConfigureOption> entryO : treeMapO.entrySet()) {
-          if (entryO.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-            p.log("Please select " + entryO.getValue().getAskInfo());
-            entryO.getValue().getOptions(p);
-            numberOk = false;
+      }
+    } else if (!optionPostgreSQL.isEmpty()) {
+      int keyPostgre = 0;
+      boolean isChangeP = false;
+      Iterator<Integer> optionBBDDpostgre = optionPostgreSQL.keySet().iterator();
+      optionMod = optionMod - optionFirst.size();
+      while ((optionBBDDpostgre.hasNext() && !isChangeP)) {
+        keyPostgre = optionBBDDpostgre.next();
+        if (keyPostgre == optionMod - 1) {
+          ConfigureOption optionChange = optionPostgreSQL.get(keyPostgre);
+          if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+            p.log("Please select " + optionChange.getAskInfo());
+            optionChange.getOptions(p);
+            boolean numberOk = false;
             do {
               optionS = inp.nextLine();
               try {
                 option = Integer.parseInt(optionS);
-                if (option >= 0 && option < entryO.getValue().getMax()) {
-                  entryO.getValue().setChoose(option);
-                  entryO.getValue().setChooseString(entryO.getValue().getOptionChoose());
+                if (option >= 0 && option < optionChange.getMax()) {
+                  optionChange.setChoose(option);
+                  optionChange.setChooseString(optionChange.getOptionChoose());
                   numberOk = true;
                 } else {
                   p.log("Please, introduce a correct option: ");
@@ -406,328 +399,447 @@
                 }
               }
             } while (!numberOk);
-          } else if (entryO.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
-            p.log("\nPlease introduce " + entryO.getValue().getAskInfo());
-            entryO.getValue().getOptions(p);
+          } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
+            p.log("\nPlease introduce " + optionChange.getAskInfo());
+            optionChange.getOptions(p);
             optionString = inp.nextLine();
             if (!optionString.equals("")) {
-              entryO.getValue().setChooseString(optionString);
+              optionChange.setChooseString(optionString);
             }
           }
-          optionPostgreSQL.put(entryO.getKey(), entryO.getValue());
-          p.log("\n-------------------------\nYour choice " + entryO.getValue().getOptionChoose()
+          optionPostgreSQL.put(optionMod - 1, optionChange);
+          p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
               + "\n-------------------------\n\n");
+          isChangeP = true;
         }
-        // All information are introduced. Configure now last options
-        if (optionLast.isEmpty()) {
-          optionLast = createOP2(p);
-        }
-        mainOption = 9;
-        break;
-      // Change ALL optionS in optionesPostgreSQL[]...
-      case 8:
-        Map<Integer, ConfigureOption> treeMapP = new TreeMap<Integer, ConfigureOption>(
-            optionPostgreSQL);
-        for (Map.Entry<Integer, ConfigureOption> entryP : treeMapP.entrySet()) {
-          if (entryP.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-            p.log("Please select " + entryP.getValue().getAskInfo());
-            entryP.getValue().getOptions(p);
-            numberOk = false;
-            do {
-              optionS = inp.nextLine();
-              try {
-                option = Integer.parseInt(optionS);
-                if (option >= 0 && option < entryP.getValue().getMax()) {
-                  entryP.getValue().setChoose(option);
-                  entryP.getValue().setChooseString(entryP.getValue().getOptionChoose());
-                  numberOk = true;
-                } else {
-                  p.log("Please, introduce a correct option: ");
-                }
-              } catch (NumberFormatException e) {
-                if (optionS.equals("")) {
-                  numberOk = true;
-                } else {
-                  p.log("Please, introduce a correct option: ");
-                }
-              }
-            } while (!numberOk);
-          } else if (entryP.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
-            p.log("\nPlease introduce " + entryP.getValue().getAskInfo());
-            entryP.getValue().getOptions(p);
-            optionString = inp.nextLine();
-            if (!optionString.equals("")) {
-              entryP.getValue().setChooseString(optionString);
+      }
+    }
+    mainOption = 4;
+  }
+
+  /**
+   * This method shows the final menu in where user can select accept o return to configure.
+   * 
+   * @param p
+   */
+  private void showFinalMenu(Project p) {
+    p.log("---------------------------------------------------------------------------- \n Are you agree with all options that you configure? \n----------------------------------------------------------------------------");
+    p.log("[1]. Accept.");
+    p.log("[2]. Back to preview configuration.");
+    p.log("[3]. Exit without saving.");
+    p.log("Choose an option: ");
+    boolean menuOptionOk = false;
+    int optionConfigure = 0;
+    do {
+      String menuOptionS = inp.nextLine();
+      try {
+        optionConfigure = Integer.parseInt(menuOptionS);
+        menuOptionOk = true;
+      } catch (NumberFormatException e) {
+        p.log("Choose a real option: ");
+      }
+    } while (!menuOptionOk);
+    switch (optionConfigure) {
+    case 1:
+      // Accept
+      mainOption = 20;
+      break;
+    case 2:
+      // Preview configuration
+      mainOption = 4;
+      break;
+    case 3:
+      // Reconfirm exit
+      mainOption = 22;
+      break;
+    default:
+      p.log("Choose a real option: ");
+    }
+  }
+
+  /**
+   * This method changes all options in "optionLast".
+   * 
+   * @param p
+   */
+  private void changeAllOptionsLast(Project p) {
+    Map<Integer, ConfigureOption> treeMapL = new TreeMap<Integer, ConfigureOption>(optionLast);
+    for (Map.Entry<Integer, ConfigureOption> entryL : treeMapL.entrySet()) {
+      if (entryL.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+        p.log("Please select " + entryL.getValue().getAskInfo());
+        entryL.getValue().getOptions(p);
+        boolean numberOk = false;
+        do {
+          String optionS = inp.nextLine();
+          try {
+            int option = Integer.parseInt(optionS);
+            if (option >= 0 && option < entryL.getValue().getMax()) {
+              entryL.getValue().setChoose(option);
+              entryL.getValue().setChooseString(entryL.getValue().getOptionChoose());
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
+            }
+          } catch (NumberFormatException e) {
+            if (optionS.equals("")) {
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
             }
           }
-          optionPostgreSQL.put(entryP.getKey(), entryP.getValue());
-          p.log("\n-------------------------\nYour choice " + entryP.getValue().getOptionChoose()
-              + "\n-------------------------\n\n");
+        } while (!numberOk);
+      } else if (entryL.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
+        p.log("\nPlease introduce " + entryL.getValue().getAskInfo());
+        entryL.getValue().getOptions(p);
+        String optionString = inp.nextLine();
+        if (!optionString.equals("")) {
+          entryL.getValue().setChooseString(optionString);
         }
-        // All information are introduced. Configure now last options
-        if (optionLast.isEmpty()) {
-          optionLast = createOP2(p);
+      }
+      optionLast.put(entryL.getKey(), entryL.getValue());
+      p.log("\n-------------------------\nYour choice " + entryL.getValue().getOptionChoose()
+          + "\n-------------------------\n\n");
+    }
+    mainOption = 10;
+  }
+
+  /**
+   * This method changes an option in "optionFirst" like date format, time format, ...
+   * 
+   * @param p
+   */
+  private void changeOptionFirst(Project p) {
+    int keyOpt = 0;
+    boolean isChange = false;
+    Iterator<Integer> optionBBDD1 = optionFirst.keySet().iterator();
+    while ((optionBBDD1.hasNext() && !isChange)) {
+      keyOpt = optionBBDD1.next();
+      if (keyOpt == optionMod - 1) {
+        ConfigureOption optionChange = optionFirst.get(keyOpt);
+        if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+          p.log("Please select " + optionChange.getAskInfo());
+          optionChange.getOptions(p);
+          boolean numberOk = false;
+          do {
+            String optionS = inp.nextLine();
+            try {
+              int option = Integer.parseInt(optionS);
+              if (option >= 0 && option < optionChange.getMax()) {
+                optionChange.setChoose(option);
+                optionChange.setChooseString(optionChange.getOptionChoose());
+                numberOk = true;
+              } else {
+                p.log("Please, introduce a correct option: ");
+              }
+            } catch (NumberFormatException e) {
+              if (optionS.equals("")) {
+                numberOk = true;
+              } else {
+                p.log("Please, introduce a correct option: ");
+              }
+            }
+          } while (!numberOk);
+        } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
+          p.log("\nPlease introduce " + optionChange.getAskInfo());
+          optionChange.getOptions(p);
+          String optionString = inp.nextLine();
+          if (!optionString.equals("")) {
+            optionChange.setChooseString(optionString);
+          }
         }
-        mainOption = 9;
-        break;
-      case 9:
-        Map<Integer, ConfigureOption> treeMapL = new TreeMap<Integer, ConfigureOption>(optionLast);
-        for (Map.Entry<Integer, ConfigureOption> entryL : treeMapL.entrySet()) {
-          if (entryL.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-            p.log("Please select " + entryL.getValue().getAskInfo());
-            entryL.getValue().getOptions(p);
-            numberOk = false;
-            do {
-              optionS = inp.nextLine();
-              try {
-                option = Integer.parseInt(optionS);
-                if (option >= 0 && option < entryL.getValue().getMax()) {
-                  entryL.getValue().setChoose(option);
-                  entryL.getValue().setChooseString(entryL.getValue().getOptionChoose());
-                  numberOk = true;
-                } else {
-                  p.log("Please, introduce a correct option: ");
-                }
-              } catch (NumberFormatException e) {
-                if (optionS.equals("")) {
-                  numberOk = true;
-                } else {
-                  p.log("Please, introduce a correct option: ");
-                }
-              }
-            } while (!numberOk);
-          } else if (entryL.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
-            p.log("\nPlease introduce " + entryL.getValue().getAskInfo());
-            entryL.getValue().getOptions(p);
-            optionString = inp.nextLine();
-            if (!optionString.equals("")) {
-              entryL.getValue().setChooseString(optionString);
+        optionFirst.put(optionMod - 1, optionChange);
+        p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
+            + "\n-------------------------\n\n");
+        isChange = true;
+        // Check a change in type of database
+        File fileO = new File(OPENBRAVO_PROPERTIES);
+        if (optionChange.getOptionChoose().equals("Oracle")) {
+          if (searchOptionsProperties(fileO, "bbdd.rdbms", p).equals("POSTGRE")) {
+            if (optionOracle.isEmpty()) {
+              optionOracle = createOPOracle(p);
+              numOptionsDDBB = optionOracle.size();
+            }
+            if (!optionPostgreSQL.isEmpty()) {
+              optionPostgreSQL.clear();
             }
           }
-          optionLast.put(entryL.getKey(), entryL.getValue());
-          p.log("\n-------------------------\nYour choice " + entryL.getValue().getOptionChoose()
-              + "\n-------------------------\n\n");
-        }
-        mainOption = 10;
-        break;
-      case 10:
-        p.log("---------------------------------------------------------------------------- \n Are you agree with all options that you configure? \n----------------------------------------------------------------------------");
-        p.log("[1]. Accept.");
-        p.log("[2]. Back to preview configuration.");
-        p.log("[3]. Exit without saving.");
-        p.log("Choose an option: ");
-        menuOptionOk = false;
-        do {
-          menuOptionS = inp.nextLine();
-          try {
-            optionConfigure = Integer.parseInt(menuOptionS);
-            menuOptionOk = true;
-          } catch (NumberFormatException e) {
-            p.log("Choose a real option: ");
-          }
-        } while (!menuOptionOk);
-        switch (optionConfigure) {
-        case 1:
-          mainOption = 20;
-          break;
-        case 2:
-          mainOption = 4;
-          break;
-        case 3:
-          mainOption = 22;
-          break;
-        default:
-          p.log("Choose a real option: ");
-        }
-        break;
-      // Change a option in optionesOracle or optionesPostgreSQL...
-      case 11:
-        if (!optionOracle.isEmpty()) {
-          int keyOracle = 0;
-          isChangeO = false;
-          Iterator<Integer> optionBBDDoracle = optionOracle.keySet().iterator();
-          optionMod = optionMod - optionFirst.size();
-          while ((optionBBDDoracle.hasNext() && !isChangeO)) {
-            keyOracle = optionBBDDoracle.next();
-            if (keyOracle == optionMod - 1) {
-              ConfigureOption optionChange = optionOracle.get(keyOracle);
-              if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-                p.log("Please select " + optionChange.getAskInfo());
-                optionChange.getOptions(p);
-                numberOk = false;
-                do {
-                  optionS = inp.nextLine();
-                  try {
-                    option = Integer.parseInt(optionS);
-                    if (option >= 0 && option < optionChange.getMax()) {
-                      optionChange.setChoose(option);
-                      optionChange.setChooseString(optionChange.getOptionChoose());
-                      numberOk = true;
-                    } else {
-                      p.log("Please, introduce a correct option: ");
-                    }
-                  } catch (NumberFormatException e) {
-                    if (optionS.equals("")) {
-                      numberOk = true;
-                    } else {
-                      p.log("Please, introduce a correct option: ");
-                    }
-                  }
-                } while (!numberOk);
-              } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
-                p.log("\nPlease introduce " + optionChange.getAskInfo());
-                optionChange.getOptions(p);
-                optionString = inp.nextLine();
-                if (!optionString.equals("")) {
-                  optionChange.setChooseString(optionString);
-                }
-              }
-              optionOracle.put(optionMod - 1, optionChange);
-              p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
-                  + "\n-------------------------\n\n");
-              isChangeO = true;
+        } else if (optionChange.getOptionChoose().equals("PostgreSQL")) {
+          if (searchOptionsProperties(fileO, "bbdd.rdbms", p).equals("ORACLE")) {
+            if (optionPostgreSQL.isEmpty()) {
+              optionPostgreSQL = createOPPostgreSQL(p);
+              numOptionsDDBB = optionPostgreSQL.size();
             }
-          }
-        } else if (!optionPostgreSQL.isEmpty()) {
-          int keyPostgre = 0;
-          boolean isChangeP = false;
-          Iterator<Integer> optionBBDDpostgre = optionPostgreSQL.keySet().iterator();
-          optionMod = optionMod - optionFirst.size();
-          while ((optionBBDDpostgre.hasNext() && !isChangeP)) {
-            keyPostgre = optionBBDDpostgre.next();
-            if (keyPostgre == optionMod - 1) {
-              ConfigureOption optionChange = optionPostgreSQL.get(keyPostgre);
-              if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-                p.log("Please select " + optionChange.getAskInfo());
-                optionChange.getOptions(p);
-                numberOk = false;
-                do {
-                  optionS = inp.nextLine();
-                  try {
-                    option = Integer.parseInt(optionS);
-                    if (option >= 0 && option < optionChange.getMax()) {
-                      optionChange.setChoose(option);
-                      optionChange.setChooseString(optionChange.getOptionChoose());
-                      numberOk = true;
-                    } else {
-                      p.log("Please, introduce a correct option: ");
-                    }
-                  } catch (NumberFormatException e) {
-                    if (optionS.equals("")) {
-                      numberOk = true;
-                    } else {
-                      p.log("Please, introduce a correct option: ");
-                    }
-                  }
-                } while (!numberOk);
-              } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
-                p.log("\nPlease introduce " + optionChange.getAskInfo());
-                optionChange.getOptions(p);
-                optionString = inp.nextLine();
-                if (!optionString.equals("")) {
-                  optionChange.setChooseString(optionString);
-                }
-              }
-              optionPostgreSQL.put(optionMod - 1, optionChange);
-              p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
-                  + "\n-------------------------\n\n");
-              isChangeP = true;
+            if (!optionOracle.isEmpty()) {
+              optionOracle.clear();
             }
           }
         }
-        mainOption = 4;
-        break;
-      // Change a option in optionesLast[]...
-      case 12:
-        int keyLast = 0;
-        isChangeL = false;
-        Iterator<Integer> optionBBDDlast = optionLast.keySet().iterator();
-        optionMod = optionMod - optionFirst.size() - numOptionsDDBB;
-        while ((optionBBDDlast.hasNext() && !isChangeL)) {
-          keyLast = optionBBDDlast.next();
-          if (keyLast == optionMod - 1) {
-            ConfigureOption optionChange = optionLast.get(keyLast);
-            if (optionChange.getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
-              p.log("Please select " + optionChange.getAskInfo());
-              optionChange.getOptions(p);
-              numberOk = false;
-              do {
-                optionS = inp.nextLine();
-                try {
-                  option = Integer.parseInt(optionS);
-                  if (option >= 0 && option < optionChange.getMax()) {
-                    optionChange.setChoose(option);
-                    optionChange.setChooseString(optionChange.getOptionChoose());
-                    numberOk = true;
-                  } else {
-                    p.log("Please, introduce a correct option: ");
-                  }
-                } catch (NumberFormatException e) {
-                  if (optionS.equals("")) {
-                    numberOk = true;
-                  } else {
-                    p.log("Please, introduce a correct option: ");
-                  }
-                }
-              } while (!numberOk);
-            } else if (optionChange.getType() == ConfigureOption.TYPE_OPT_STRING) {
-              p.log("\nPlease introduce " + optionChange.getAskInfo());
-              optionChange.getOptions(p);
-              optionString = inp.nextLine();
-              if (!optionString.equals("")) {
-                optionChange.setChooseString(optionString);
-              }
-            }
-            optionLast.put(optionMod - 1, optionChange);
-            p.log("\n-------------------------\nYour choice " + optionChange.getOptionChoose()
-                + "\n-------------------------\n\n");
-            isChangeL = true;
-          }
-        }
-        mainOption = 4;
-        break;
-      // All options have been selected... configure Openbravo.properties file.
-      case 20:
-        setValuesProperties();
-        Iterator<String> keySetIterator = replaceProperties.keySet().iterator();
-        while (keySetIterator.hasNext()) {
-          String keyForFile = keySetIterator.next();
-          replaceOptionsProperties(keyForFile + "=", replaceProperties.get(keyForFile), p);
-        }
-        mainOption = 21;
-        break;
-      // configuration done
-      case 21:
-        p.log("---------------------------------------------------------------------------- \n Configuration complete. \n----------------------------------------------------------------------------");
-        mainOption = -1;
-        break;
-      // re-confirm exit
-      case 22:
-        p.log("Do you want to exit this program? [y/n]: ");
-        input = licenseIn.nextLine();
-        while (!("Y".equalsIgnoreCase(input) || "N".equalsIgnoreCase(input))) {
-          p.log("Please, introduce a correct option. Do you want to exit this program? [y/n]: ");
-          input = licenseIn.nextLine();
-        }
-        if ("Y".equalsIgnoreCase(input)) {
-          p.log("---------------------------------------------------------------------------- \n You have not successfully completed the configuration process.");
-          mainOption = -1;
-        } else if ("N".equalsIgnoreCase(input)) {
-          if (optionFirst.isEmpty()) {
-            mainOption = 1;
-          } else {
-            mainOption = 10;
-          }
-        }
       }
     }
-    inp.close();
-    licenseIn.close();
-    p.log("---------------------------------------------------------------------------- \n Thanks for use Openbravo ERP Setup. \n----------------------------------------------------------------------------");
+    mainOption = 4;
   }
 
   /**
-   * This function showWelcome() show a welcome to install application.
+   * This method asks for an option for changing. It can be optionFirst, option database or
+   * optionLast.
+   * 
+   * @param p
+   */
+  private void askForChangeAnOption(Project p) {
+    p.log("---------------------------------------------------------------------------- \n Do you change any option? \n----------------------------------------------------------------------------");
+    p.log("Choose [0] for continue with configuration or a number option for modify: ");
+    boolean menuOptionOk = false;
+    do {
+      String menuOptionS = inp.nextLine();
+      try {
+        optionMod = Integer.parseInt(menuOptionS);
+        if (optionMod >= 0 && optionMod <= optionFirst.size() + optionLast.size() + numOptionsDDBB) {
+          menuOptionOk = true;
+        } else {
+          p.log("Choose a real option: ");
+        }
+      } catch (NumberFormatException e) {
+        p.log("Choose a real option: ");
+      }
+    } while (!menuOptionOk);
+    // Accept all configuration
+    if (optionMod == 0) {
+      mainOption = 10;
+      // Options 0 to numberLastOptions + NUM_OPTIONS_LAST, change a particular option
+    } else if (optionMod > 0 && optionMod <= optionFirst.size()) {
+      mainOption = 6;
+    } else if (optionMod > optionFirst.size() && optionMod <= optionFirst.size() + numOptionsDDBB) {
+      mainOption = 11;
+    } else if (optionMod > optionFirst.size() + numOptionsDDBB
+        && optionMod <= optionFirst.size() + optionLast.size() + numOptionsDDBB) {
+      mainOption = 12;
+    }
+  }
+
+  /**
+   * This method shows all options with their values.
+   * 
+   * @param p
+   */
+  private void previewConfigurationOptions(Project p) {
+    p.log("---------------------------------------------------------------------------- \n Preview Openbravo ERP configuration \n----------------------------------------------------------------------------");
+    // TreeMap for show questions in order for get user parameters.
+    int numberOption = 1;
+    Map<Integer, ConfigureOption> previewOptions1 = new TreeMap<Integer, ConfigureOption>(
+        optionFirst);
+    Map<Integer, ConfigureOption> previewOptions2;
+    Map<Integer, ConfigureOption> previewOptions3 = new TreeMap<Integer, ConfigureOption>(
+        optionLast);
+    if (optionPostgreSQL.isEmpty()) {
+      previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionOracle);
+    } else if (optionOracle.isEmpty()) {
+      previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionPostgreSQL);
+    } else {
+      previewOptions2 = new TreeMap<Integer, ConfigureOption>(optionPostgreSQL);
+    }
+    // Show all options by order asc
+    for (Map.Entry<Integer, ConfigureOption> entry : previewOptions1.entrySet()) {
+      p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
+          + entry.getValue().getOptionChoose());
+      numberOption = numberOption + 1;
+    }
+    for (Map.Entry<Integer, ConfigureOption> entry : previewOptions2.entrySet()) {
+      p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
+          + entry.getValue().getOptionChoose());
+      numberOption = numberOption + 1;
+    }
+    for (Map.Entry<Integer, ConfigureOption> entry : previewOptions3.entrySet()) {
+      p.log("[" + numberOption + "] " + entry.getValue().getAskInfo() + " "
+          + entry.getValue().getOptionChoose());
+      numberOption = numberOption + 1;
+    }
+    mainOption = 5;
+  }
+
+  /**
+   * This method invokes all the options for configuration one by one.
+   * 
+   * @param p
+   */
+  private void configureStepByStep(Project p) {
+    String typeDDBB = "";
+    Map<Integer, ConfigureOption> treeMap = new TreeMap<Integer, ConfigureOption>(optionFirst);
+    for (Map.Entry<Integer, ConfigureOption> entry : treeMap.entrySet()) {
+      if (entry.getValue().getType() == ConfigureOption.TYPE_OPT_CHOOSE) {
+        p.log("Please select " + entry.getValue().getAskInfo());
+        entry.getValue().getOptions(p);
+        boolean numberOk = false;
+        do {
+          String optionS = inp.nextLine();
+          try {
+            int option = Integer.parseInt(optionS);
+            if (option >= 0 && option < entry.getValue().getMax()) {
+              entry.getValue().setChoose(option);
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
+            }
+          } catch (NumberFormatException e) {
+            if (optionS.equals("")) {
+              numberOk = true;
+            } else {
+              p.log("Please, introduce a correct option: ");
+            }
+          }
+        } while (!numberOk);
+      } else if (entry.getValue().getType() == ConfigureOption.TYPE_OPT_STRING) {
+        p.log("\nPlease introduce " + entry.getValue().getAskInfo());
+        entry.getValue().getOptions(p);
+        String optionString = inp.nextLine();
+        if (!optionString.equals("")) {
+          entry.getValue().setChooseString(optionString);
+        }
+      }
+      // review
+      optionFirst.put(entry.getKey(), entry.getValue());
+      typeDDBB = entry.getValue().getOptionChoose();
+      p.log("\n-------------------------\nYour choice " + typeDDBB
+          + "\n-------------------------\n\n");
+    }
+    // Select Oracle or PostgreSQL
+    if (typeDDBB.equals("Oracle")) {
+      if (optionOracle.isEmpty()) {
+        optionOracle = createOPOracle(p);
+        numOptionsDDBB = optionOracle.size();
+      }
+      if (!optionPostgreSQL.isEmpty()) {
+        optionPostgreSQL.clear();
+      }
+      mainOption = 7;
+    } else if (typeDDBB.equals("PostgreSQL")) {
+      if (optionPostgreSQL.isEmpty()) {
+        optionPostgreSQL = createOPPostgreSQL(p);
+        numOptionsDDBB = optionPostgreSQL.size();
+      }
+      if (!optionOracle.isEmpty()) {
+        optionOracle.clear();
+      }
+      mainOption = 8;
+    }
+  }
+
+  /**
+   * This method asks selected option in main menu.
+   * 
+   * @param p
+   */
+  private void selectOptionMainMenu(Project p) {
+    boolean menuOptionOk = false;
+    int menuOption = 3;
+    do {
+      String menuOptionS = inp.nextLine();
+      try {
+        menuOption = Integer.parseInt(menuOptionS);
+        menuOptionOk = true;
+      } catch (NumberFormatException e) {
+        p.log("Please, introduce a correct option: ");
+      }
+    } while (!menuOptionOk);
+    // Create options one-by-one
+    if (menuOption == 1) {
+      if (optionFirst.isEmpty()) {
+        optionFirst = createOP(p);
+      }
+      // Create optionsDDBB
+      // Oracle or Postgresql options
+      String keyValueS = "";
+      Iterator<Integer> optionBBDD = optionFirst.keySet().iterator();
+      do {
+        keyValueS = optionFirst.get(optionBBDD.next()).getChooseString();
+      } while (!(keyValueS.equals("PostgreSQL") || keyValueS.equals("Oracle")));
+      if (keyValueS.equals("Oracle")) {
+        optionOracle = createOPOracle(p);
+        numOptionsDDBB = optionOracle.size();
+      } else if (keyValueS.equals("PostgreSQL")) {
+        optionPostgreSQL = createOPPostgreSQL(p);
+        numOptionsDDBB = optionPostgreSQL.size();
+      }
+      mainOption = 3;
+      // Create all options by default.
+    } else if (menuOption == 2) {
+      if (optionFirst.isEmpty()) {
+        optionFirst = createOP(p);
+      }
+      // Oracle or Postgresql options
+      String keyValue = "";
+      Iterator<Integer> optionBBDD = optionFirst.keySet().iterator();
+      do {
+        keyValue = optionFirst.get(optionBBDD.next()).getChooseString();
+      } while (!(keyValue.equals("PostgreSQL") || keyValue.equals("Oracle")));
+      if (keyValue.equals("Oracle")) {
+        optionOracle = createOPOracle(p);
+        numOptionsDDBB = optionOracle.size();
+      } else if (keyValue.equals("PostgreSQL")) {
+        optionPostgreSQL = createOPPostgreSQL(p);
+        numOptionsDDBB = optionPostgreSQL.size();
+      }
+      if (optionLast.isEmpty()) {
+        optionLast = createOP2(p);
+      }
+      // Go to preview options configurate by default
+      mainOption = 4;
+    } else if (menuOption == 3) {
+      mainOption = 22;
+    } else {
+      p.log("Please, introduce a correct option: ");
+    }
+  }
+
+  /**
+   * This method shows main menu of application.
+   * 
+   * @param p
+   */
+  private void showMainMenu(Project p) {
+    p.log("---------------------------------------------------------------------------- \n Please choose one option. \n----------------------------------------------------------------------------");
+    p.log("[1]. Step-by-step configuration.");
+    p.log("[2]. Default configuration.");
+    p.log("[3]. Exit without saving.");
+    p.log("Choose an option: ");
+    mainOption++;
+  }
+
+  /**
+   * This method asks for users that accept the license of Openbravo installation.
+   * 
+   * @param p
+   */
+  private void acceptLicense(Project p) {
+    p.log("Do you accept this license? [y/n]: ");
+    String input = licenseIn.nextLine();
+    while (!("Y".equalsIgnoreCase(input) || "N".equalsIgnoreCase(input))) {
+      p.log("Please, introduce a correct option. Do you accept this license? [y/n]: ");
+      input = licenseIn.nextLine();
+    }
+    if ("Y".equalsIgnoreCase(input)) {
+      mainOption++;
+    } else if ("N".equalsIgnoreCase(input)) {
+      p.log("---------------------------------------------------------------------------- \n You have not successfully completed the configuration process.");
+      mainOption = -1;
+    }
+  }
+
+  /**
+   * This method copies some important files.
+   * 
+   * @param p
+   */
+  private static void fileCopySomeTemplates(Project p) {
+    fileCopyTemplate(FORMAT_XML_TEMPLATE, FORMAT_XML, p);
+    fileCopyTemplate(LOG4J_LCF_TAMPLATE, LOG4J_LCF, p);
+    fileCopyTemplate(USERCONFIG_XML_TEMPLATE, USERCONFIG_XML, p);
+    fileCopyTemplate(OPENBRAVO_PROPERTIES_TEMPLATE, OPENBRAVO_PROPERTIES, p);
+    fileCopyTemplate(COMMON_COMPONENT_TEMPLATE, COMMON_COMPONENT, p);
+    fileCopyTemplate(CLASSPATH_TEMPLATE, CLASSPATH, p);
+  }
+
+  /**
+   * This function shows a welcome to install application.
    * 
    * @param p1
    *          : Project
@@ -741,8 +853,7 @@
   }
 
   /**
-   * This function setValuesProperties() use all information asking to user for configurate
-   * Openbravo.properties file.
+   * This function uses all information asking to user for configurate Openbravo.properties file.
    */
   private static void setValuesProperties() {
 
@@ -917,7 +1028,7 @@
   }
 
   /**
-   * This function replace in Openbravo.properties the value of option searchOption with value
+   * This function replaces in Openbravo.properties the value of option searchOption with value
    * changeOption. Concatenated searchOption+changeOption. For example: "bbdd.user=" + "admin".
    * 
    * @param searchOption
@@ -966,8 +1077,7 @@
   }
 
   /**
-   * This function SearchOptionsProperties() search an option in fileO file and returns the value of
-   * searchOption.
+   * This function searches an option in fileO file and returns the value of searchOption.
    * 
    * @param fileO
    * @param searchOption
@@ -994,7 +1104,7 @@
   }
 
   /**
-   * This function createOP() create first options for configuration. Information is collected from
+   * This function creates first options for configuration. Information is collected from
    * Openbravo.properties file.
    * 
    * @return HashMap<Integer,Option>
@@ -1142,7 +1252,7 @@
 
   /**
    * 
-   * This function createOP2() create last options for configuration.Information is collected from
+   * This function creates last options for configuration.Information is collected from
    * Openbravo.properties file.
    * 
    * @return HashMap<Integer, Option>
@@ -1199,8 +1309,8 @@
   }
 
   /**
-   * This function createOPOracle() create options of Oracle configuration. Information is collected
-   * from Openbravo.properties file.
+   * This function creates options of Oracle configuration. Information is collected from
+   * Openbravo.properties file.
    * 
    * @return HashMap<Integer, Option>
    */
@@ -1289,8 +1399,8 @@
   }
 
   /**
-   * This function createOPPostgreSQL() create options of PostgreSQL configuration.Information is
-   * collected from Openbravo.properties file.
+   * This function creates options of PostgreSQL configuration.Information is collected from
+   * Openbravo.properties file.
    * 
    * @return HashMap<Integer, Option>
    */
@@ -1353,8 +1463,8 @@
   }
 
   /**
-   * This function changeOraclePostgresql() disabling options Oracle or PostgreSQL, using the [#] at
-   * the beginning of the options to disable them.
+   * This function disables options Oracle or PostgreSQL, using the [#] at the beginning of the
+   * options to disable them.
    * 
    */
   private static void changeOraclePostgresql(Project p) {
@@ -1398,7 +1508,7 @@
   }
 
   /**
-   * This function FileCopyTemplate() copy a file if it is not exists.
+   * This function copies a file if it is not exists.
    * 
    * @param sourceFile
    * @param destinationFile
@@ -1416,7 +1526,7 @@
   }
 
   /**
-   * This function readLicense() show license terms for installing OpenBravo. License is located in
+   * This function shows license terms for installing OpenBravo. License is located in
    * OPENBRAVO_LICENSE.
    * 
    * @throws IOException