commit 26c4caa0d5f4753239ff730451d72617dd3b2709
Author: Vojtěch Danišík <32537562+danisik@users.noreply.github.com>
Date:   Sun Aug 9 16:37:27 2020 +0200

    re #8101 Bad saving changes for configuration.

diff --git a/src/main/java/vldc/aswi/service/SqlQueryManager.java b/src/main/java/vldc/aswi/service/SqlQueryManager.java
index 3efde122..896e16f1 100644
--- a/src/main/java/vldc/aswi/service/SqlQueryManager.java
+++ b/src/main/java/vldc/aswi/service/SqlQueryManager.java
@@ -1,7 +1,6 @@
 package vldc.aswi.service;
 
-import vldc.aswi.domain.Assembly;
-import vldc.aswi.domain.Configuration;
+import vldc.aswi.domain.parameter.ParameterInConfiguration;
 import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
 
 import java.util.List;
@@ -13,10 +12,11 @@ public interface SqlQueryManager {
 
     /**
      * Get list of  contingencyTableRow.
-     * @param configuration - configuration from which table will be created.
+     * @param sqlQuery
+     * @param parameterInConfigurations
      * @return List of contingencyTableRow.
      */
-    List<ContingencyTableRow> getContingencyTableRow(Configuration configuration);
+    List<ContingencyTableRow> getContingencyTableRow(String sqlQuery, List<ParameterInConfiguration> parameterInConfigurations);
 
     /**
      * Validate given SQL query.
diff --git a/src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java b/src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java
index 1160ae45..11d35a49 100644
--- a/src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java
@@ -28,29 +28,31 @@ public class SqlQueryManagerImpl implements SqlQueryManager{
     /** Autowired databaseInterface component. */
     @Autowired
     private DatabaseInterface databaseInterface;
-
+    
     /**
      * Get list of  contingencyTableRow.
-     * @param configuration - configuration from which table will be created.
+     * @param sqlQuery
+     * @param parameterInConfigurations
      * @return List of contingencyTableRow.
      */
     @Override
-    public List<ContingencyTableRow> getContingencyTableRow(Configuration configuration) {
+    public List<ContingencyTableRow> getContingencyTableRow(String sqlQuery, List<ParameterInConfiguration> parameterInConfigurations) {
         long startTime = System.nanoTime();
-        Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns(
-                configuration.getAssembly().getSQLQuery()
-        );
+        Map<String, TableColumn> tableColumns = this.databaseInterface.executeQueryAndReturnTableColumns(sqlQuery);
         long stopTime = System.nanoTime();
         System.out.println("Select:" + TimeUnit.MILLISECONDS.convert((stopTime - startTime), TimeUnit.NANOSECONDS));
         List<NameUserName> rowNames = new ArrayList<>();
         List<NameUserName> columnNames = new ArrayList<>();
         List<ValueFunction> valueFunctions = new ArrayList<>();
 
+        // Create a copy of list.
+        List<ParameterInConfiguration> copiedParametersInConfiguration = new ArrayList<>(parameterInConfigurations);
+
         // sort parameters in configuration to have them in order set by user
-        Collections.sort(configuration.getParametersInConfiguration());
+        Collections.sort(copiedParametersInConfiguration);
 
         // TODO: 28.05.2020 map would be better
-        for(ParameterInConfiguration parameterInConfiguration : configuration.getParametersInConfiguration()) {
+        for(ParameterInConfiguration parameterInConfiguration : copiedParametersInConfiguration) {
             if (parameterInConfiguration.getLocation() != null && parameterInConfiguration.getLocation().getName().equals("Řádek")) {
                 rowNames.add(new NameUserName(parameterInConfiguration.getParameter().getNameOfSelect().toUpperCase(),
                         parameterInConfiguration.getColumnName()));
diff --git a/src/main/java/vldc/aswi/web/controller/AssemblyController.java b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
index fa7c848c..2c4942e2 100644
--- a/src/main/java/vldc/aswi/web/controller/AssemblyController.java
+++ b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
@@ -15,6 +15,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import vldc.aswi.domain.*;
 import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.domain.parameter.ParameterInConfiguration;
+import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
 import vldc.aswi.service.*;
 import vldc.aswi.service.parameter.ParameterManager;
 import vldc.aswi.service.parameter.ParameterTypeManager;
@@ -25,6 +26,7 @@ import vldc.aswi.utils.Utils;
 import javax.validation.Valid;
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -186,10 +188,14 @@ public class AssemblyController extends BasicController {
 
             System.out.println("Generuj tabulku");
             prepareForTable(newConfiguration);
+
+            List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration.getAssembly().getSQLQuery(),
+                    newConfiguration.getParametersInConfiguration());
+
             System.out.println("Generuj tabulku");
             ModelMap modelMap = modelAndView.getModelMap();
             modelMap.addAttribute("configurationID", id);
-            modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration));
+            modelMap.addAttribute("contingencyTableRows", rows);
             Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder());
             initializeFields(newConfiguration);
 
diff --git a/src/main/java/vldc/aswi/web/controller/ConfigurationController.java b/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
index faaf4dff..6894a287 100644
--- a/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
+++ b/src/main/java/vldc/aswi/web/controller/ConfigurationController.java
@@ -12,6 +12,7 @@ import vldc.aswi.domain.Configuration;
 import vldc.aswi.domain.Location;
 import vldc.aswi.domain.Operator;
 import vldc.aswi.domain.parameter.ParameterInConfiguration;
+import vldc.aswi.model.table.contingencyTable.ContingencyTableRow;
 import vldc.aswi.service.AssemblyManager;
 import vldc.aswi.service.ConfigurationManager;
 import vldc.aswi.service.LocationManager;
@@ -119,8 +120,12 @@ public class ConfigurationController extends BasicController{
         {
             prepareForTable(newConfiguration);
             System.out.println("Generuj tabulku");
+
+            List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration.getAssembly().getSQLQuery(),
+                    newConfiguration.getParametersInConfiguration());
+
             modelMap.addAttribute("configurationID", id);
-            modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration));
+            modelMap.addAttribute("contingencyTableRows", rows);
             Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder());
             initializeFields(newConfiguration);
             modelMap.addAttribute("configuration", newConfiguration);
