commit 93fff0905900d3a2047bc6a0c93b388bb85c9c48
Author: Vojtěch Danišík <32537562+danisik@users.noreply.github.com>
Date:   Thu Apr 23 18:06:22 2020 +0200

    re #7886 Adding + Editing parameters in assembly (only logic + pushing into database, which is not tested -> need JS implementation for adding new parameter).
    Updated hibernate dialect from oracle 10 to oracle 12c.
    Equals method comparing domain by id.

diff --git a/src/main/java/vldc/aswi/dao/AssemblyRepository.java b/src/main/java/vldc/aswi/dao/AssemblyRepository.java
index 05092c33..5ebe47f3 100644
--- a/src/main/java/vldc/aswi/dao/AssemblyRepository.java
+++ b/src/main/java/vldc/aswi/dao/AssemblyRepository.java
@@ -1,5 +1,6 @@
 package vldc.aswi.dao;
 
+import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.CrudRepository;
 import org.springframework.stereotype.Repository;
 import vldc.aswi.domain.Assembly;
@@ -16,4 +17,7 @@ public interface AssemblyRepository extends CrudRepository<Assembly, Long> {
      * @return Assembly if ID is present in database.
      */
     Assembly getById(Long Id);
+
+    // TODO
+    Assembly findFirst1ByOrderByAssemblyOrder();
 }
diff --git a/src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java b/src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java
index 819b2799..f490e7bc 100644
--- a/src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java
+++ b/src/main/java/vldc/aswi/dao/parameter/ParameterTypeRepository.java
@@ -16,4 +16,6 @@ public interface ParameterTypeRepository extends CrudRepository<ParameterType, L
      * @return ParameterType if ID is present in database.
      */
     ParameterType getById(Long Id);
+
+    ParameterType findByName(String name);
 }
diff --git a/src/main/java/vldc/aswi/domain/Assembly.java b/src/main/java/vldc/aswi/domain/Assembly.java
index 54c965f7..a23527bd 100644
--- a/src/main/java/vldc/aswi/domain/Assembly.java
+++ b/src/main/java/vldc/aswi/domain/Assembly.java
@@ -27,24 +27,24 @@ public class Assembly extends EntityParent {
 
     /** Specific order of assembly in list of assemblies. */
     @Column(name = "poradi")
-    private int order;
+    private int assemblyOrder;
 
     @Column(name = "verejny")
     private int isPublic;
 
     /** List of configurations, which using this assembly. */
-    @OneToMany(mappedBy = "assembly")
+    @OneToMany(mappedBy = "assembly", cascade = {CascadeType.ALL})
     private List<Configuration> configurations;
 
     /** List of parameters, which using this assembly. */
-    @OneToMany(mappedBy = "assembly")
+    @OneToMany(mappedBy = "assembly", cascade = {CascadeType.ALL})
     private List<Parameter> parameters;
 
     /**
      * Creating new table with M:N relationship between Assembly and Role.
      * Every assembly can be used by 0 - every role.
      */
-    @ManyToMany
+    @ManyToMany(cascade = {CascadeType.ALL})
     @JoinTable(
             name = "Sestava_ma_Role",
             joinColumns = @JoinColumn(name = "sestava_id"),
@@ -56,12 +56,17 @@ public class Assembly extends EntityParent {
      * Constructor.
      * @param name - Name of Assembly.
      * @param SQLQuery - SQL query which gets data from database.
-     * @param order - Specific order of assembly in list of assemblies.
+     * @param assemblyOrder - Specific order of assembly in list of assemblies.
      */
-    public Assembly(String name, String SQLQuery, int order, int isPublic) {
+    public Assembly(String name, String SQLQuery, int assemblyOrder, int isPublic) {
         this.setName(name);
         this.setSQLQuery(SQLQuery);
-        this.setOrder(order);
+        this.setAssemblyOrder(assemblyOrder);
         this.setIsPublic(isPublic);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/Configuration.java b/src/main/java/vldc/aswi/domain/Configuration.java
index 760c989b..db1b334d 100644
--- a/src/main/java/vldc/aswi/domain/Configuration.java
+++ b/src/main/java/vldc/aswi/domain/Configuration.java
@@ -26,17 +26,17 @@ public class Configuration extends EntityParent {
     private String tableName;
 
     /** Specific user, which created this configuration. */
-    @ManyToOne(fetch= FetchType.LAZY)
+    @ManyToOne(fetch= FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "uzivatel_id")
     private User user;
 
     /** Used assembly as template in configuration. */
-    @ManyToOne(fetch= FetchType.LAZY)
+    @ManyToOne(fetch= FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "sestava_id")
     private Assembly assembly;
 
     /** List of parametersInConfiguration, which is part of this configuration. */
-    @OneToMany(mappedBy = "configuration")
+    @OneToMany(mappedBy = "configuration", cascade = {CascadeType.ALL})
     private List<ParameterInConfiguration> parametersInConfiguration;
 
     /**
@@ -48,4 +48,9 @@ public class Configuration extends EntityParent {
         this.setName(name);
         this.setTableName(tableName);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/EntityParent.java b/src/main/java/vldc/aswi/domain/EntityParent.java
index 75da5bc9..75a10b41 100644
--- a/src/main/java/vldc/aswi/domain/EntityParent.java
+++ b/src/main/java/vldc/aswi/domain/EntityParent.java
@@ -1,11 +1,13 @@
 package vldc.aswi.domain;
 
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.MappedSuperclass;
+import javax.persistence.*;
 
 import lombok.Data;
+import org.apache.poi.ss.formula.functions.T;
+import vldc.aswi.domain.parameter.Parameter;
+
+import java.util.LinkedList;
+import java.util.List;
 
 /**
  * Class which is extended for all domain entities containing common attributes.
@@ -16,6 +18,28 @@ public class EntityParent {
 
     /** Specific identificator for every table. */
     @Id
-    @GeneratedValue(strategy = GenerationType.AUTO)
+    @Column(name="ID")
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
     private Long id;
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if(this == obj) {
+            return true;
+        }
+
+        if(obj == null || obj.getClass()!= this.getClass()) {
+            return false;
+        }
+
+        // type casting of the argument.
+        EntityParent parent = (EntityParent) obj;
+
+        if (parent.getId() == null) {
+            return false;
+        }
+
+        return (parent.getId() == this.getId());
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/Function.java b/src/main/java/vldc/aswi/domain/Function.java
index cf3f4544..0e065556 100644
--- a/src/main/java/vldc/aswi/domain/Function.java
+++ b/src/main/java/vldc/aswi/domain/Function.java
@@ -6,6 +6,7 @@ import lombok.NoArgsConstructor;
 import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.domain.parameter.ParameterInConfiguration;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.ManyToMany;
@@ -25,11 +26,11 @@ public class Function extends EntityParent {
     private String name;
 
     /** List of parameters, which defined that this function can be used. */
-    @ManyToMany(mappedBy = "functions")
+    @ManyToMany(mappedBy = "functions", cascade = {CascadeType.ALL})
     private List<Parameter> parameters;
 
     /** List of parametersInConfigurations, which using this function. */
-    @ManyToMany(mappedBy = "functions")
+    @ManyToMany(mappedBy = "functions", cascade = {CascadeType.ALL})
     private List<ParameterInConfiguration> parametersInConfigurations;
 
     /**
@@ -39,4 +40,9 @@ public class Function extends EntityParent {
     public Function(String name) {
         this.setName(name);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/Location.java b/src/main/java/vldc/aswi/domain/Location.java
index 3c59687c..f5f85e74 100644
--- a/src/main/java/vldc/aswi/domain/Location.java
+++ b/src/main/java/vldc/aswi/domain/Location.java
@@ -6,10 +6,7 @@ import lombok.NoArgsConstructor;
 import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.domain.parameter.ParameterInConfiguration;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToMany;
+import javax.persistence.*;
 import java.util.List;
 
 /**
@@ -26,11 +23,11 @@ public class Location extends EntityParent {
     private String name;
 
     /** List of parameters which allows this location. */
-    @ManyToMany(mappedBy = "locations")
+    @ManyToMany(mappedBy = "locations", cascade = {CascadeType.ALL})
     private List<Parameter> parameters;
 
     /** List of parametersInConfiguration which using this location. */
-    @OneToMany(mappedBy = "location")
+    @OneToMany(mappedBy = "location", cascade = {CascadeType.ALL})
     private List<ParameterInConfiguration> parametersInConfiguration;
 
     /**
@@ -40,4 +37,9 @@ public class Location extends EntityParent {
     public Location(String name) {
         this.setName(name);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/Operator.java b/src/main/java/vldc/aswi/domain/Operator.java
index 5320f5c5..1bdf2751 100644
--- a/src/main/java/vldc/aswi/domain/Operator.java
+++ b/src/main/java/vldc/aswi/domain/Operator.java
@@ -6,10 +6,7 @@ import lombok.NoArgsConstructor;
 import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.domain.parameter.ParameterInConfiguration;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToMany;
+import javax.persistence.*;
 import java.util.List;
 
 /**
@@ -26,11 +23,11 @@ public class Operator extends EntityParent {
     private String name;
 
     /** List of parameters which allowing this operator to be used. */
-    @ManyToMany(mappedBy = "operators")
+    @ManyToMany(mappedBy = "operators", cascade = {CascadeType.ALL})
     private List<Parameter> parameters;
 
     /** List of parametersInConfiguration using this operator. */
-    @OneToMany(mappedBy = "operator")
+    @OneToMany(mappedBy = "operator", cascade = {CascadeType.ALL})
     private List<ParameterInConfiguration> parametersInConfiguration;
 
     /**
@@ -40,4 +37,9 @@ public class Operator extends EntityParent {
     public Operator(String name) {
         this.setName(name);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/Role.java b/src/main/java/vldc/aswi/domain/Role.java
index 9c1e3fb4..98e1ded2 100644
--- a/src/main/java/vldc/aswi/domain/Role.java
+++ b/src/main/java/vldc/aswi/domain/Role.java
@@ -4,10 +4,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToMany;
+import javax.persistence.*;
 import java.util.List;
 
 /**
@@ -24,11 +21,11 @@ public class Role extends EntityParent {
     private String name;
 
     /** List of assemblies, which using this role. */
-    @ManyToMany(mappedBy = "roles")
+    @ManyToMany(mappedBy = "roles", cascade = {CascadeType.ALL})
     private List<Assembly> assemblies;
 
     /** List of users with this role. */
-    @OneToMany(mappedBy = "role")
+    @OneToMany(mappedBy = "role", cascade = {CascadeType.ALL})
     private List<User> users;
 
     /**
@@ -39,4 +36,8 @@ public class Role extends EntityParent {
         this.setName(name);
     }
 
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/User.java b/src/main/java/vldc/aswi/domain/User.java
index 15c191d9..5a29672d 100644
--- a/src/main/java/vldc/aswi/domain/User.java
+++ b/src/main/java/vldc/aswi/domain/User.java
@@ -27,12 +27,12 @@ public class User extends EntityParent {
     private String password;
 
     /** Role of user. */
-    @ManyToOne(fetch=FetchType.LAZY)
+    @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "role_id")
     private Role role;
 
     /** List of user configurations. */
-    @OneToMany(mappedBy = "user")
+    @OneToMany(mappedBy = "user", cascade = {CascadeType.ALL})
     private List<Configuration> configurations;
 
     /**
@@ -44,4 +44,9 @@ public class User extends EntityParent {
         this.setUsername(username);
         this.setPassword(password);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/vldc/aswi/domain/parameter/Parameter.java b/src/main/java/vldc/aswi/domain/parameter/Parameter.java
index 3edf49f1..79e3fda2 100644
--- a/src/main/java/vldc/aswi/domain/parameter/Parameter.java
+++ b/src/main/java/vldc/aswi/domain/parameter/Parameter.java
@@ -1,8 +1,13 @@
 package vldc.aswi.domain.parameter;
 
+import com.fasterxml.jackson.annotation.JsonBackReference;
+import com.fasterxml.jackson.annotation.JsonIdentityInfo;
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+import com.fasterxml.jackson.annotation.ObjectIdGenerators;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
+import lombok.ToString;
 import vldc.aswi.domain.*;
 import javax.persistence.*;
 import java.util.List;
@@ -25,32 +30,32 @@ public class Parameter extends EntityParent {
     private String nameOfSelect;
 
     /** Specific assembly, in which this parameter will be part of. */
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "sestava_id")
     private Assembly assembly;
 
+    /** Specific type of parameter, which represents type of entry. */
+    @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
+    @JoinColumn(name = "parametr_typ_id")
+    private ParameterType parameterType;
+
     /** Default value of this parameter. */
     @Column(name = "default_hodnota")
     private String defaultValue;
 
     /** List of parametersInConfiguration, which using this parameter. */
-    @OneToMany(mappedBy = "parameter")
+    @OneToMany(mappedBy = "parameter", cascade = {CascadeType.ALL})
     private List<ParameterInConfiguration> parametersInConfiguration;
 
     /** List of parametersInConfiguration, which using this parameter. */
-    @OneToMany(mappedBy = "parameter")
+    @OneToMany(mappedBy = "parameter", cascade = {CascadeType.ALL})
     private List<ParameterValue> parameterValues;
 
-    /** Specific type of parameter, which represents type of entry. */
-    @ManyToOne(fetch=FetchType.LAZY)
-    @JoinColumn(name = "parametr_typ_id")
-    private ParameterType parameterType;
-
     /**
      * Creating new table with M:N relationship between Parameter and Location.
      * Specify which locations can be used for parameter.
      */
-    @ManyToMany
+    @ManyToMany(cascade = {CascadeType.ALL})
     @JoinTable(
             name = "Parametr_ma_Umisteni",
             joinColumns = @JoinColumn(name = "parametr_id"),
@@ -62,7 +67,7 @@ public class Parameter extends EntityParent {
      * Creating new table with M:N relationship between Parameter and Function.
      * Specify which functions can be used for parameter.
      */
-    @ManyToMany
+    @ManyToMany(cascade = {CascadeType.ALL})
     @JoinTable(
             name = "Parametr_ma_Funkce",
             joinColumns = @JoinColumn(name = "parametr_id"),
@@ -74,7 +79,7 @@ public class Parameter extends EntityParent {
      * Creating new table with M:N relationship between Parameter and Operator.
      * Specify which operators can be used for parameter.
      */
-    @ManyToMany
+    @ManyToMany(cascade = {CascadeType.ALL})
     @JoinTable(
             name = "Parametr_ma_Operator",
             joinColumns = @JoinColumn(name = "parametr_id"),
@@ -93,4 +98,14 @@ public class Parameter extends EntityParent {
         this.setNameOfSelect(nameOfSelect);
         this.setDefaultValue(defaultValue);
     }
+
+    @Override
+    public String toString() {
+        return "Parameter[name=" + name + ", nameOfSelect=" + nameOfSelect + ", defaultHodnota=" + defaultValue + "]";
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java b/src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java
index 5fdaf491..ba3bf6d1 100644
--- a/src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java
+++ b/src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java
@@ -17,12 +17,12 @@ import java.util.List;
 public class ParameterInConfiguration extends EntityParent {
 
     /** Specific configuration in which is this parameterConfiguration presented. */
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "konfigurace_id")
     private Configuration configuration;
 
     /** Specific parameter of configuration, which is used as template. */
-    @ManyToOne(fetch=FetchType.LAZY)
+    @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "parametr_id")
     private Parameter parameter;
 
@@ -31,7 +31,7 @@ public class ParameterInConfiguration extends EntityParent {
     private String operatorValue;
 
     /** Specific location in which this parameterConfiguration will be used. */
-    @ManyToOne(fetch=FetchType.LAZY)
+    @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "umisteni_id")
     private Location location;
 
@@ -40,7 +40,7 @@ public class ParameterInConfiguration extends EntityParent {
     private String columnName;
 
     /** Specific operator which will be aplied onto data. */
-    @ManyToOne(fetch=FetchType.LAZY)
+    @ManyToOne(fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "operator_id")
     private Operator operator;
 
@@ -48,7 +48,7 @@ public class ParameterInConfiguration extends EntityParent {
      * Creating new table with M:N relationship between ParameterInConfiguration and Function.
      * On every ParameterInConfiguration can be applied 0 - every function.
      */
-    @ManyToMany
+    @ManyToMany(cascade = {CascadeType.ALL})
     @JoinTable(
             name = "Parametr_konfigurace_ma_Funkce",
             joinColumns = @JoinColumn(name = "parametr_konfigurace_id"),
@@ -65,4 +65,9 @@ public class ParameterInConfiguration extends EntityParent {
         this.setOperatorValue(operatorValue);
         this.setColumnName(columnName);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/parameter/ParameterType.java b/src/main/java/vldc/aswi/domain/parameter/ParameterType.java
index 947b2773..8b2f78f2 100644
--- a/src/main/java/vldc/aswi/domain/parameter/ParameterType.java
+++ b/src/main/java/vldc/aswi/domain/parameter/ParameterType.java
@@ -5,6 +5,7 @@ import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 import vldc.aswi.domain.EntityParent;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.OneToMany;
@@ -24,7 +25,7 @@ public class ParameterType extends EntityParent {
     private String name;
 
     /** List of parameterInConfigurations, which using this parameter type. */
-    @OneToMany(mappedBy = "parameterType")
+    @OneToMany(mappedBy = "parameterType", cascade = {CascadeType.ALL})
     private List<Parameter> parameters;
 
     /**
@@ -34,4 +35,9 @@ public class ParameterType extends EntityParent {
     public ParameterType(String name) {
         this.setName(name);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/domain/parameter/ParameterValue.java b/src/main/java/vldc/aswi/domain/parameter/ParameterValue.java
index 397b4736..51f7fe8c 100644
--- a/src/main/java/vldc/aswi/domain/parameter/ParameterValue.java
+++ b/src/main/java/vldc/aswi/domain/parameter/ParameterValue.java
@@ -18,7 +18,7 @@ import javax.persistence.*;
 public class ParameterValue extends EntityParent {
 
     /** Specific parameter which can use this value. */
-    @ManyToOne(fetch = FetchType.LAZY)
+    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
     @JoinColumn(name = "parametr_id")
     private Parameter parameter;
 
@@ -33,4 +33,9 @@ public class ParameterValue extends EntityParent {
     public ParameterValue(String value) {
         this.setValue(value);
     }
+
+    @Override
+    public boolean equals(Object obj) {
+        return super.equals(obj);
+    }
 }
diff --git a/src/main/java/vldc/aswi/service/AssemblyManager.java b/src/main/java/vldc/aswi/service/AssemblyManager.java
index 8f0dedd4..36ce28ed 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManager.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManager.java
@@ -1,6 +1,8 @@
 package vldc.aswi.service;
 
 import vldc.aswi.domain.Assembly;
+import vldc.aswi.domain.Role;
+import vldc.aswi.domain.parameter.Parameter;
 
 import java.util.List;
 
@@ -16,4 +18,10 @@ public interface AssemblyManager {
     List<Assembly> getAssemblies();
 
     Assembly getAssemblyById(Long id);
+
+    Long updateAssembly(Assembly updatedAssemblyValues);
+
+    void updateAssemblyOrder(Long id, int order);
+
+    Long createAssembly(Assembly assemblyValues);
 }
diff --git a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
index 4edeff6d..ba84578a 100644
--- a/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/AssemblyManagerImpl.java
@@ -7,7 +7,9 @@ import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
 import vldc.aswi.dao.AssemblyRepository;
+import vldc.aswi.dao.RoleRepository;
 import vldc.aswi.domain.Assembly;
+import vldc.aswi.domain.Role;
 
 import javax.transaction.Transactional;
 import java.util.LinkedList;
@@ -21,6 +23,9 @@ public class AssemblyManagerImpl implements AssemblyManager {
     @Autowired
     private AssemblyRepository assemblyRepository;
 
+    @Autowired
+    private RoleRepository roleRepository;
+
     /**
      * Initialization setup for assembly manager. Check if assembly repository contains
      * records and if not, initialize default values.
@@ -52,4 +57,76 @@ public class AssemblyManagerImpl implements AssemblyManager {
     public Assembly getAssemblyById(Long id) {
         return assemblyRepository.getById(id);
     }
+
+    @Override
+    public void updateAssemblyOrder(Long id, int order) {
+        Assembly assembly = getAssemblyById(id);
+        assembly.setAssemblyOrder(order);
+        this.assemblyRepository.save(assembly);
+    }
+
+    @Override
+    public Long updateAssembly(Assembly updatedAssemblyValues) {
+        // TODO: test it.
+        Assembly assembly = getAssemblyById(updatedAssemblyValues.getId());
+        assembly.setName(updatedAssemblyValues.getName());
+        assembly.setSQLQuery(updatedAssemblyValues.getSQLQuery());
+        assembly.setAssemblyOrder(updatedAssemblyValues.getAssemblyOrder());
+        assembly.setIsPublic(updatedAssemblyValues.getIsPublic());
+        this.assemblyRepository.save(assembly);
+
+        updateAssemblyRoles(updatedAssemblyValues.getId(), updatedAssemblyValues.getRoles());
+
+        return assembly.getId();
+    }
+
+    private void updateAssemblyRoles(Long id, List<Role> updatedRoles) {
+        // TODO: test it.
+        Assembly assembly = getAssemblyById(id);
+        List<Role> currentRoles = assembly.getRoles();
+
+        // Find new roles.
+        List<Role> currentRolesNew = new LinkedList<>(currentRoles);
+        List<Role> updatedRolesNew = new LinkedList<>(updatedRoles);
+        updatedRolesNew.removeAll(currentRolesNew);
+
+        // Find deleted roles.
+        List<Role> currentRolesDeleted = new LinkedList<>(currentRoles);
+        List<Role> updatedRolesDeleted = new LinkedList<>(updatedRoles);
+        currentRolesDeleted.removeAll(updatedRolesDeleted);
+
+        // If no role has been deleted or added, then updating is unnecessary.
+        if (updatedRolesNew.size() == 0 && currentRolesDeleted.size() == 0) return;
+
+        // Add new roles and remove deleted roles.
+        for (Role newRole : updatedRolesNew) {
+            currentRoles.add(this.roleRepository.getById(newRole.getId()));
+        }
+        currentRoles.removeAll(currentRolesDeleted);
+
+        // Save updates to database.
+        this.assemblyRepository.save(assembly);
+    }
+
+    @Override
+    public Long createAssembly(Assembly assemblyValues) {
+        // TODO: test it.
+        Assembly assembly = new Assembly();
+        assembly.setName(assemblyValues.getName());
+        assembly.setSQLQuery(assemblyValues.getSQLQuery());
+        assembly.setAssemblyOrder(this.assemblyRepository.findFirst1ByOrderByAssemblyOrder().getAssemblyOrder() + 1);
+        assembly.setIsPublic(assemblyValues.getIsPublic());
+        List<Role> roles = new LinkedList<>();
+
+        if (assemblyValues.getRoles() != null && assemblyValues.getRoles().size() > 0) {
+            for (Role newRole : assemblyValues.getRoles()) {
+                roles.add(this.roleRepository.getById(newRole.getId()));
+            }
+        }
+
+        assembly.setRoles(roles);
+        this.assemblyRepository.save(assembly);
+
+        return assembly.getId();
+    }
 }
diff --git a/src/main/java/vldc/aswi/service/parameter/ParameterManager.java b/src/main/java/vldc/aswi/service/parameter/ParameterManager.java
index 2eab6e2f..7a0c7820 100644
--- a/src/main/java/vldc/aswi/service/parameter/ParameterManager.java
+++ b/src/main/java/vldc/aswi/service/parameter/ParameterManager.java
@@ -14,4 +14,8 @@ public interface ParameterManager {
      * @return List of parameters.
      */
     List<Parameter> getParameters();
+
+    void addParameters(Long assemblyId, List<Parameter> parameterValuesList);
+
+    void updateParameters(Long assemblyId, List<Parameter> newAssemblyParameters);
 }
diff --git a/src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java b/src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java
index 4278bb27..89ad8398 100644
--- a/src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java
@@ -6,10 +6,23 @@ import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
+import vldc.aswi.dao.AssemblyRepository;
+import vldc.aswi.dao.FunctionRepository;
+import vldc.aswi.dao.LocationRepository;
+import vldc.aswi.dao.OperatorRepository;
 import vldc.aswi.dao.parameter.ParameterRepository;
+import vldc.aswi.dao.parameter.ParameterTypeRepository;
+import vldc.aswi.dao.parameter.ParameterValueRepository;
+import vldc.aswi.domain.*;
 import vldc.aswi.domain.parameter.Parameter;
+import vldc.aswi.domain.parameter.ParameterType;
+import vldc.aswi.domain.parameter.ParameterValue;
+import vldc.aswi.service.FunctionManager;
+import vldc.aswi.service.LocationManager;
+import vldc.aswi.service.OperatorManager;
 
 import javax.transaction.Transactional;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -21,6 +34,24 @@ public class ParameterManagerImpl implements ParameterManager {
     @Autowired
     private ParameterRepository parameterRepository;
 
+    @Autowired
+    private AssemblyRepository assemblyRepository;
+
+    @Autowired
+    private ParameterTypeRepository parameterTypeRepository;
+
+    @Autowired
+    private LocationRepository locationRepository;
+
+    @Autowired
+    private FunctionRepository functionRepository;
+
+    @Autowired
+    private OperatorRepository operatorRepository;
+
+    @Autowired
+    private ParameterValueRepository parameterValueRepository;
+
     /**
      * Initialization setup for parameter manager. Check if parameter repository contains
      * records and if not, initialize default values.
@@ -47,4 +78,226 @@ public class ParameterManagerImpl implements ParameterManager {
         this.parameterRepository.findAll().forEach(retVal::add);
         return retVal;
     }
+
+    @Override
+    public void addParameters(Long assemblyId, List<Parameter> parameterValuesList) {
+        Assembly assembly = this.assemblyRepository.getById(assemblyId);
+        // TODO: test it.
+        if (parameterValuesList == null) return;
+
+        for (Parameter parameterValues : parameterValuesList) {
+            Parameter parameter = new Parameter();
+            parameter.setName(parameterValues.getNameOfSelect());
+            parameter.setNameOfSelect(parameterValues.getNameOfSelect());
+            parameter.setAssembly(assembly);
+            parameter.setParameterType(this.parameterTypeRepository.findByName(parameterValues.getParameterType().getName()));
+            parameter.setDefaultValue(parameterValues.getDefaultValue());
+
+            List<Location> locationList = new LinkedList<>();
+            List<Function> functionList = new LinkedList<>();
+            List<Operator> operatorList = new LinkedList<>();
+
+            if (parameterValues.getLocations() != null && parameterValues.getLocations().size() > 0) {
+                for (Location location : parameterValues.getLocations()) {
+                    locationList.add(this.locationRepository.getById(location.getId()));
+                }
+            }
+
+            if (parameterValues.getFunctions() != null && parameterValues.getFunctions().size() > 0) {
+                for (Function function : parameterValues.getFunctions()) {
+                    functionList.add(this.functionRepository.getById(function.getId()));
+                }
+            }
+
+            if (parameterValues.getOperators() != null && parameterValues.getOperators().size() > 0) {
+                for (Operator operator : parameterValues.getOperators()) {
+                    operatorList.add(this.operatorRepository.getById(operator.getId()));
+                }
+            }
+
+            parameter.setLocations(locationList);
+            parameter.setFunctions(functionList);
+            parameter.setOperators(operatorList);
+
+            this.parameterRepository.save(parameter);
+        }
+    }
+
+    @Override
+    public void updateParameters(Long assemblyId, List<Parameter> newAssemblyParameters) {
+        // TODO: test it.
+        Assembly assembly = this.assemblyRepository.getById(assemblyId);
+        List<Parameter> currentAssemblyParameters = assembly.getParameters();
+
+        // Find new parameters;
+        List<Parameter> currentAssemblyParametersNew = new LinkedList<>(currentAssemblyParameters);
+        List<Parameter> newAssemblyParametersNew = new LinkedList<>(newAssemblyParameters);
+        newAssemblyParametersNew.removeAll(currentAssemblyParametersNew);
+
+        // Find deleted parameters
+        List<Parameter> currentAssemblyParametersDeleted = new LinkedList<>(currentAssemblyParameters);
+        List<Parameter> newAssemblyParametersDeleted = new LinkedList<>(newAssemblyParameters);
+        currentAssemblyParametersDeleted.removeAll(newAssemblyParametersDeleted);
+
+        // Find duplicate elements - for updating.
+        List<Parameter> currentAssemblyParametersUpdated = new LinkedList<>(currentAssemblyParameters);
+        List<Parameter> newAssemblyParametersUpdated = new LinkedList<>(newAssemblyParameters);
+        newAssemblyParametersUpdated.retainAll(currentAssemblyParametersUpdated);
+
+        // If no parameter has been deleted or added, then updating is unnecessary.
+        if (newAssemblyParametersNew.size() == 0 && currentAssemblyParametersDeleted.size() == 0 && newAssemblyParametersUpdated.size() == currentAssemblyParameters.size()) return;
+
+        // Remove deleted parameters.
+        for (Parameter parameter : currentAssemblyParametersDeleted) {
+            for (ParameterValue parameterValue : parameter.getParameterValues()) {
+                this.parameterValueRepository.delete(parameterValue);
+            }
+
+            this.parameterRepository.delete(parameter);
+        }
+
+        // Update rest parameters.
+        updateParameters(newAssemblyParametersUpdated);
+
+        // Add new parameters
+        addParameters(assemblyId, newAssemblyParametersNew);
+    }
+
+    private void updateParameters(List<Parameter> parameterValuesList) {
+        // TODO: test it.
+        for (Parameter parameterValues : parameterValuesList) {
+            Parameter parameter = this.parameterRepository.getById(parameterValues.getId());
+            parameter.setName(parameterValues.getName());
+            parameter.setNameOfSelect(parameterValues.getNameOfSelect());
+            parameter.setAssembly(this.assemblyRepository.getById(parameterValues.getAssembly().getId()));
+            parameter.setParameterType(this.parameterTypeRepository.getById(parameterValues.getParameterType().getId()));
+            parameter.setDefaultValue(parameterValues.getDefaultValue());
+            this.parameterRepository.save(parameter);
+
+            updateParameterValues(parameterValues.getId(), parameterValues.getParameterValues());
+            updateParameterLocations(parameterValues.getId(), parameterValues.getLocations());
+            updateParameterFunctions(parameterValues.getId(), parameterValues.getFunctions());
+            updateParameterOperators(parameterValues.getId(), parameterValues.getOperators());
+        }
+    }
+
+    private void updateParameterLocations(Long id, List<Location> updatedLocations) {
+        // TODO: test it.
+        Parameter parameter = this.parameterRepository.getById(id);
+        List<Location> currentLocations = parameter.getLocations();
+
+        List<Location> currentLocationsNew = new LinkedList<>(currentLocations);
+        List<Location> updatedLocationsNew = new LinkedList<>(updatedLocations);
+        updatedLocationsNew.removeAll(currentLocationsNew);
+
+        List<Location> currentLocationsDeleted = new LinkedList<>(currentLocations);
+        List<Location> updatedLocationsDeleted = new LinkedList<>(updatedLocations);
+        currentLocationsDeleted.removeAll(updatedLocationsDeleted);
+
+        if (updatedLocationsNew.size() == 0 && currentLocationsDeleted.size() == 0) return;
+
+        for (Location newLocation : updatedLocationsNew) {
+            currentLocations.add(this.locationRepository.getById(newLocation.getId()));
+        }
+        currentLocations.removeAll(currentLocationsDeleted);
+
+        this.parameterRepository.save(parameter);
+    }
+
+    private void updateParameterFunctions(Long id, List<Function> updatedFunctions) {
+        // TODO: test it.
+        Parameter parameter = this.parameterRepository.getById(id);
+        List<Function> currentFunctions = parameter.getFunctions();
+
+        List<Function> currentFunctionsNew = new LinkedList<>(currentFunctions);
+        List<Function> updatedFunctionsNew = new LinkedList<>(updatedFunctions);
+        updatedFunctionsNew.removeAll(currentFunctionsNew);
+
+        List<Function> currentFunctionsDeleted = new LinkedList<>(currentFunctions);
+        List<Function> updatedFunctionsDeleted = new LinkedList<>(updatedFunctions);
+        currentFunctionsDeleted.removeAll(updatedFunctionsDeleted);
+
+        if (updatedFunctionsNew.size() == 0 && currentFunctionsDeleted.size() == 0) return;
+
+        for (Function newFunction : updatedFunctionsNew) {
+            currentFunctions.add(this.functionRepository.getById(newFunction.getId()));
+        }
+        currentFunctions.removeAll(currentFunctionsDeleted);
+
+        this.parameterRepository.save(parameter);
+    }
+
+    private void updateParameterOperators(Long id, List<Operator> updatedOperators) {
+        // TODO: test it.
+        Parameter parameter = this.parameterRepository.getById(id);
+        List<Operator> currentOperators = parameter.getOperators();
+
+        List<Operator> currentOperatorsNew = new LinkedList<>(currentOperators);
+        List<Operator> updatedOperatorsNew = new LinkedList<>(updatedOperators);
+        updatedOperatorsNew.removeAll(currentOperatorsNew);
+
+        List<Operator> currentOperatorsDeleted = new LinkedList<>(currentOperators);
+        List<Operator> updatedOperatorsDeleted = new LinkedList<>(updatedOperators);
+        currentOperatorsDeleted.removeAll(updatedOperatorsDeleted);
+
+        if (updatedOperatorsNew.size() == 0 && currentOperatorsDeleted.size() == 0) return;
+
+        for (Operator newOperator : updatedOperatorsNew) {
+            currentOperators.add(this.operatorRepository.getById(newOperator.getId()));
+        }
+        currentOperators.removeAll(currentOperatorsDeleted);
+
+        this.parameterRepository.save(parameter);
+    }
+
+    private void updateParameterValues(Long parameterId, List<ParameterValue> newParameterValues) {
+        // TODO: test it.
+        Parameter parameter = this.parameterRepository.getById(parameterId);
+        List<ParameterValue> currentParameterValues = parameter.getParameterValues();
+
+        List<ParameterValue> currentParameterValuesNew = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesNew = new LinkedList<>(newParameterValues);
+        newParameterValuesNew.removeAll(currentParameterValuesNew);
+
+        List<ParameterValue> currentParameterValuesDeleted = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesDeleted = new LinkedList<>(newParameterValues);
+        currentParameterValuesDeleted.removeAll(newParameterValuesDeleted);
+
+        List<ParameterValue> currentParameterValuesUpdated = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesUpdated = new LinkedList<>(newParameterValues);
+        newParameterValuesUpdated.retainAll(currentParameterValuesUpdated);
+
+        if (newParameterValuesNew.size() == 0 && currentParameterValuesDeleted.size() == 0 && newParameterValuesUpdated.size() == currentParameterValues.size()) return;
+
+        for (ParameterValue parameterValue : currentParameterValuesDeleted) {
+            this.parameterValueRepository.delete(parameterValue);
+        }
+
+        updateParameterValueValues(newParameterValuesUpdated);
+
+        addParameterValueValues(parameterId, newParameterValuesNew);
+    }
+
+    private void updateParameterValueValues(List<ParameterValue> updatedParameterValuesList) {
+        // TODO: test it.
+        for (ParameterValue parameterValueValues : updatedParameterValuesList) {
+            ParameterValue parameterValue = this.parameterValueRepository.getById(parameterValueValues.getId());
+            parameterValue.setValue(parameterValueValues.getValue());
+
+            this.parameterValueRepository.save(parameterValue);
+        }
+    }
+
+    private void addParameterValueValues(Long parameterId, List<ParameterValue> newParameterValuesNew) {
+        // TODO: test it.
+        Parameter parameter = this.parameterRepository.getById(parameterId);
+
+        for (ParameterValue parameterValueValues : newParameterValuesNew) {
+            ParameterValue parameterValue = new ParameterValue();
+            parameterValue.setValue(parameterValueValues.getValue());
+            parameterValue.setParameter(parameter);
+
+            this.parameterValueRepository.save(parameterValue);
+        }
+    }
 }
diff --git a/src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java b/src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java
index 0fc7ca71..50f155ff 100644
--- a/src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java
+++ b/src/main/java/vldc/aswi/service/parameter/ParameterValueManager.java
@@ -14,4 +14,10 @@ public interface ParameterValueManager {
      * @return List of parameter values.
      */
     List<ParameterValue> getParameterValues();
+
+    void createParameterValues(Long parameterId, List<ParameterValue> parameterValues);
+
+    void updateParameterValues(Long parameterId, List<ParameterValue> parameterValues);
+
+    void addParameterValues(Long parameterId, List<ParameterValue> newParameterValuesNew);
 }
diff --git a/src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java b/src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java
index 6ed92723..4a01e912 100644
--- a/src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java
+++ b/src/main/java/vldc/aswi/service/parameter/ParameterValueManagerImpl.java
@@ -6,7 +6,9 @@ import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
+import vldc.aswi.dao.parameter.ParameterRepository;
 import vldc.aswi.dao.parameter.ParameterValueRepository;
+import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.domain.parameter.ParameterValue;
 
 import javax.transaction.Transactional;
@@ -21,6 +23,9 @@ public class ParameterValueManagerImpl implements ParameterValueManager {
     @Autowired
     private ParameterValueRepository parameterValueRepository;
 
+    @Autowired
+    private ParameterRepository parameterRepository;
+
     /**
      * Initialization setup for parameter value manager. Check if parameter value repository contains
      * records and if not, initialize default values.
@@ -47,4 +52,69 @@ public class ParameterValueManagerImpl implements ParameterValueManager {
         this.parameterValueRepository.findAll().forEach(retVal::add);
         return retVal;
     }
+
+
+    @Override
+    public void createParameterValues(Long parameterId, List<ParameterValue> parameterValues) {
+        Parameter parameter = this.parameterRepository.getById(parameterId);
+
+        for (ParameterValue newParameterValue : parameterValues) {
+            ParameterValue parameterValue = new ParameterValue();
+            parameterValue.setValue(newParameterValue.getValue());
+            parameterValue.setParameter(parameter);
+
+            this.parameterValueRepository.save(parameterValue);
+        }
+    }
+
+    @Override
+    public void updateParameterValues(Long parameterId, List<ParameterValue> newParameterValues) {
+        Parameter parameter = this.parameterRepository.getById(parameterId);
+        List<ParameterValue> currentParameterValues = parameter.getParameterValues();
+
+        List<ParameterValue> currentParameterValuesNew = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesNew = new LinkedList<>(newParameterValues);
+        newParameterValuesNew.removeAll(currentParameterValuesNew);
+
+        List<ParameterValue> currentParameterValuesDeleted = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesDeleted = new LinkedList<>(newParameterValues);
+        currentParameterValuesDeleted.removeAll(newParameterValuesDeleted);
+
+        List<ParameterValue> currentParameterValuesUpdated = new LinkedList<>(currentParameterValues);
+        List<ParameterValue> newParameterValuesUpdated = new LinkedList<>(newParameterValues);
+        newParameterValuesUpdated.retainAll(currentParameterValuesUpdated);
+
+        if (newParameterValuesNew.size() == 0 && currentParameterValuesDeleted.size() == 0 && newParameterValuesUpdated.size() == currentParameterValues.size()) return;
+
+        for (ParameterValue parameterValue : currentParameterValuesDeleted) {
+            this.parameterValueRepository.delete(parameterValue);
+        }
+
+        updateParameterValues(newParameterValuesUpdated);
+
+        addParameterValues(parameterId, newParameterValuesNew);
+    }
+
+    private void updateParameterValues(List<ParameterValue> updatedParameterValuesList) {
+        for (ParameterValue parameterValueValues : updatedParameterValuesList) {
+            ParameterValue parameterValue = this.parameterValueRepository.getById(parameterValueValues.getId());
+            parameterValue.setValue(parameterValueValues.getValue());
+
+            this.parameterValueRepository.save(parameterValue);
+        }
+    }
+
+    @Override
+    public void addParameterValues(Long parameterId, List<ParameterValue> newParameterValuesNew) {
+        Parameter parameter = this.parameterRepository.getById(parameterId);
+
+        for (ParameterValue parameterValueValues : newParameterValuesNew) {
+            ParameterValue parameterValue = new ParameterValue();
+            parameterValue.setValue(parameterValueValues.getValue());
+            parameterValue.setParameter(parameter);
+
+            this.parameterValueRepository.save(parameterValue);
+        }
+    }
+
 }
diff --git a/src/main/java/vldc/aswi/web/controller/AssemblyController.java b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
index e3b771bc..37435329 100644
--- a/src/main/java/vldc/aswi/web/controller/AssemblyController.java
+++ b/src/main/java/vldc/aswi/web/controller/AssemblyController.java
@@ -1,8 +1,8 @@
 package vldc.aswi.web.controller;
 
-import oracle.jdbc.proxy.annotation.Post;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.ui.ModelMap;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -11,12 +11,17 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.servlet.ModelAndView;
 import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import vldc.aswi.domain.Assembly;
-import vldc.aswi.domain.Role;
+import vldc.aswi.domain.Function;
+import vldc.aswi.domain.Location;
+import vldc.aswi.domain.parameter.Parameter;
 import vldc.aswi.service.*;
+import vldc.aswi.service.parameter.ParameterManager;
 import vldc.aswi.service.parameter.ParameterTypeManager;
+import vldc.aswi.service.parameter.ParameterValueManager;
 
 import javax.validation.Valid;
-import java.util.ArrayList;
+import java.beans.PropertyEditorSupport;
+import java.util.LinkedList;
 import java.util.List;
 
 @Controller
@@ -43,15 +48,21 @@ public class AssemblyController {
     @Autowired
     private LocationManager locationManager;
 
+    @Autowired
+    private ParameterManager parameterManager;
+
+    @Autowired
+    private ParameterValueManager parameterValueManager;
+
     @GetMapping("/assembly")
     public ModelAndView assemblyIndex(@Valid @ModelAttribute("assemblyID") String id) {
         ModelAndView modelAndView = new ModelAndView("assembly");
 
         ModelMap modelMap = modelAndView.getModelMap();
 
-        Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
+        Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id));
 
-        modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
+        modelMap.addAttribute("assemblies", this.assemblyManager.getAssemblies());
         modelMap.addAttribute("assembly", assembly);
 
         return modelAndView;
@@ -66,11 +77,11 @@ public class AssemblyController {
 
         long assemblyID = assembly.getId();
 
-        Assembly assembly2 = assemblyManager.getAssemblyById(assemblyID);
+        Assembly assembly2 = this.assemblyManager.getAssemblyById(assemblyID);
 
-        modelMap.addAttribute("assemblies", assemblyManager.getAssemblies());
+        modelMap.addAttribute("assemblies", this.assemblyManager.getAssemblies());
         modelMap.addAttribute("assembly", assembly2);
-        modelMap.addAttribute("contingencyTableRows", sqlQueryManager.getContingencyTableRow(assembly2.getSQLQuery()));
+        modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(assembly2.getSQLQuery()));
 
         return modelAndView;
     }
@@ -81,16 +92,41 @@ public class AssemblyController {
 
         ModelMap modelMap = modelAndView.getModelMap();
 
-        Assembly assembly = assemblyManager.getAssemblyById(Long.parseLong(id));
+        Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id));
 
         modelMap.addAttribute("assembly", assembly);
-        modelMap.addAttribute("roles", roleManager.getRoles());
-        modelMap.addAttribute("rolesWithAccess", assembly.getRoles());
-        modelMap.addAttribute("parameters", assembly.getParameters());
-        modelMap.addAttribute("parameterTypes", parameterTypeManager.getParameterTypes());
-        modelMap.addAttribute("functions", functionManager.getFunctions());
-        modelMap.addAttribute("operators", operatorManager.getOperators());
-        modelMap.addAttribute("locations", locationManager.getLocations());
+        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
+        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
+        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
+        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
+        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
+
+        return modelAndView;
+    }
+
+    @PostMapping("/assembly_edit")
+    public ModelAndView assemblyEditPostIndex(@Valid @ModelAttribute("assembly") Assembly assembly, @Valid @ModelAttribute("checkboxPublic") String assemblyIsPublic) {
+
+        ModelAndView modelAndView = new ModelAndView("assembly_manage");
+
+        ModelMap modelMap = modelAndView.getModelMap();
+        if (assemblyIsPublic.equals("on")) assembly.setIsPublic(1);
+        else assembly.setIsPublic(0);
+
+        Long assemblyID = this.assemblyManager.updateAssembly(assembly);
+        this.parameterManager.updateParameters(assemblyID, assembly.getParameters());
+        Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assembly.getId());
+
+        // TODO: vyzkoušet jestli se dobře vrací ID parameterType a zda se vypisuje název v selectboxu namísto ID !!
+        // TODO: chybí defaultValue.
+
+
+        modelMap.addAttribute("assembly", updatedAssembly);
+        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
+        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
+        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
+        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
+        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
 
         return modelAndView;
     }
@@ -102,20 +138,25 @@ public class AssemblyController {
         ModelMap modelMap = modelAndView.getModelMap();
 
         modelMap.addAttribute("assembly", new Assembly());
-        modelMap.addAttribute("roles", roleManager.getRoles());
+        modelMap.addAttribute("allRoles", this.roleManager.getRoles());
+        modelMap.addAttribute("allParameterTypes", this.parameterTypeManager.getParameterTypes());
+        modelMap.addAttribute("allFunctions", this.functionManager.getFunctions());
+        modelMap.addAttribute("allOperators", this.operatorManager.getOperators());
+        modelMap.addAttribute("allLocations", this.locationManager.getLocations());
 
         return modelAndView;
     }
 
     @PostMapping("/assembly_new")
-    public ModelAndView assemblyNewIndexPost() {
-        ModelAndView modelAndView = new ModelAndView("assembly_manage");
+    public ModelAndView assemblyNewIndexPost(@Valid @ModelAttribute("assembly") Assembly assembly) {
+        ModelAndView modelAndView = new ModelAndView();
 
         ModelMap modelMap = modelAndView.getModelMap();
 
-        modelMap.addAttribute("assembly", new Assembly());
-        modelMap.addAttribute("roles", roleManager.getRoles());
+        Long assemblyId = this.assemblyManager.createAssembly(assembly);
+        this.parameterManager.addParameters(assemblyId, assembly.getParameters());
 
+        modelAndView.setViewName("redirect:/assembly_edit?assemblyID=" + assembly.getId());
         return modelAndView;
     }
 }
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 6401b7ab..84938dbd 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,5 +1,5 @@
-# Tell hibernate to use oracle dialect.
-spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
+# Tell hibernate to use oracle 12c dialect (allowing to use IDENTITY for ID, ....).
+spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
 
 # TNS format of connection to ORACLE 12c database.
 oracle.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=atreus-v.zcu.cz)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DEMO_SERVICE)))
diff --git a/src/main/webapp/WEB-INF/templates/assembly.html b/src/main/webapp/WEB-INF/templates/assembly.html
index 68910f44..dc44d4d3 100644
--- a/src/main/webapp/WEB-INF/templates/assembly.html
+++ b/src/main/webapp/WEB-INF/templates/assembly.html
@@ -24,7 +24,7 @@
 <main role="main">
 
     <div class="container">
-        <input type=button onclick="history.back()" class="btn btn-success mb-2" value="Zpět">
+        <a href="/" class="btn btn-success mb-2">Zpět</a>
         <h1>
             Sestava - Studenti - studijní programy
         </h1>
diff --git a/src/main/webapp/WEB-INF/templates/assembly_manage.html b/src/main/webapp/WEB-INF/templates/assembly_manage.html
index a2a48007..2314d15e 100644
--- a/src/main/webapp/WEB-INF/templates/assembly_manage.html
+++ b/src/main/webapp/WEB-INF/templates/assembly_manage.html
@@ -24,32 +24,33 @@
 <main role="main">
 
   <div class="container">
-    <input type=button onclick="history.back()" class="btn btn-success mb-2" value="Zpět">
+    <a href="/" class="btn btn-success mb-2">Zpět</a>
     <h1>
       Editace - Studenti - studijní programy
     </h1>
   </div>
 
-<form>
+<form th:object="${assembly}" th:action="${assembly.id} != null ? @{/assembly_edit(assemblyID=${assembly.id})} : @{/assembly_new}" method="post">
+  <input type="hidden" th:field="*{id}" th:value="*{id}" />
   <div class="container box">
     <div class="col-md-12">
     <div class="form-group row">
       <label for="name" class="col-sm-2 col-form-label">Název sestavy:</label>
       <div class="col-sm-10">
-        <input type="text" class="form-control" id="name" th:value="${assembly.name}">
+        <input type="text" class="form-control" id="name" th:field="*{name}" th:value="*{name}">
       </div>
     </div>
     <div class="form-group row">
       <label for="sql_query" class="col-sm-2 col-form-label">SQL dotaz:</label>
       <div class="col-sm-10">
-        <textarea class="form-control" id="sql_query" rows="6" th:text="${assembly.SQLQuery}"></textarea>
+        <textarea class="form-control" id="sql_query" rows="6" th:field="*{SQLQuery}" th:text="*{SQLQuery}"></textarea>
       </div>
     </div>
     <div class="form-group row">
       <label class="form-check-label col-sm-2" for="checkboxPublic">Veřejný:</label>
       <div class="col-sm-10">
         <div class="form-check">
-          <input class="form-check-input" type="checkbox" value="" th:checked="${assembly.isPublic} == 1" id="checkboxPublic">
+          <input class="form-check-input" type="checkbox"  th:checked="*{isPublic} == 1" name="checkboxPublic" id="checkboxPublic">
         </div>
       </div>
     </div>
@@ -64,12 +65,13 @@
       <button type="button" class="btn btn-success"><i class="fas fa-plus"></i> Přidat parametr</button>
     </div>
 
-    <div th:each="parameter : ${parameters}" class="panel-group" id="accordion">
+    <div th:each="parameter, i : *{parameters}" class="panel-group" id="accordion">
+      <input type="hidden" th:field="*{parameters[__${i.index}__]}" th:value="*{parameters[__${i.index}__].id}" />
       <div class="panel panel-default">
         <div class="panel-heading">
           <span class="panel-title">
-            <a data-toggle="collapse" data-parent="#accordion" th:attr="href='#collapse' + ${parameter.id}">
-              <i class="fas fa-angle-right"></i> <span th:text="${parameter.name}"></span>
+            <a data-toggle="collapse" data-parent="#accordion" th:attr="href='#collapse' + *{parameters[__${i.index}__].id}">
+              <i class="fas fa-angle-right"></i> <span th:text="*{parameters[__${i.index}__].name}"></span>
             </a>
             <span class="align-right collapse-actions">
               <span class="action-padding input-action-margin-collapse sort-icon">
@@ -81,55 +83,34 @@
             </span>
           </span>
         </div>
-        <div th:id="'collapse' + ${parameter.id}" class="panel-collapse collapse">
+        <div th:id="'collapse' + *{parameters[__${i.index}__].id}" class="panel-collapse collapse">
           <div class="panel-body">
             <div class="form-group row">
               <label for="name" class="col-sm-2 col-form-label">Název:</label>
               <div class="col-sm-10">
-                <input type="text" class="form-control" id="name" th:value="${parameter.name}">
+                <input type="text" class="form-control" id="name" th:field="*{parameters[__${i.index}__].name}" th:value="*{parameters[__${i.index}__].name}">
               </div>
             </div>
             <div class="form-group row">
               <label for="name" class="col-sm-2 col-form-label">V&nbsp;SQL:</label>
               <div class="col-sm-10">
-                <input type="text" class="form-control" id="name" th:value="${parameter.nameOfSelect}">
+                <input type="text" class="form-control" id="name" th:field="*{parameters[__${i.index}__].nameOfSelect}" th:value="*{parameters[__${i.index}__].nameOfSelect}">
               </div>
             </div>
             <div class="form-group row">
               <label for="exampleFormControlSelect1" class="col-sm-2">Typ:</label>
               <div class="col-sm-10">
-                <select class="form-control" id="exampleFormControlSelect1">
-                  <option th:each="parameterType : ${parameterTypes}" th:value="newParameterType + ${parameterType.name}" th:text="${parameterType.name}"></option>
+                <select th:field="*{parameters[__${i.index}__].parameterType.name}" class="form-control" id="exampleFormControlSelect1">
+                  <option th:each="parameterType : ${allParameterTypes}" th:value="${parameterType.id}" th:text="${parameterType.name}"></option>
                 </select>
               </div>
             </div>
 
-            <div class="enum_box">
+            <div th:if="*{parameters[__${i.index}__].parameterType.name.equals('Výčet')}" class="enum_box">
               Hodnoty:
               <div class="enum_values col-md-8">
-                <div class="input-action-box input-border-bottom">
-                  <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="Doktorský">
-
-                  <span class="action-padding input-action-margin sort-icon">
-                    <i class="fas fa-sort"></i>
-                  </span>
-                  <span class="action-padding action-button input-action-margin">
-                    <a href=# class="action-link far fa-trash-alt"></a>
-                  </span>
-                </div>
-                <div class="input-action-box input-border-bottom">
-                  <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="Navazující">
-
-                  <span class="action-padding input-action-margin sort-icon">
-                    <i class="fas fa-sort"></i>
-                  </span>
-                  <span class="action-padding action-button input-action-margin">
-                    <a href=# class="action-link far fa-trash-alt"></a>
-                  </span>
-
-                </div>
-                <div class="input-action-box input-border-bottom">
-                  <input type="text" readonly class="form-control-plaintext" id="staticEmail" value="Bakalářský">
+                <div th:each="parameterValue, j : *{parameters[__${i.index}__].parameterValues}" class="input-action-box input-border-bottom">
+                  <input type="text" class="form-control-plaintext" th:field="*{parameters[__${i.index}__].parameterValues[__${j.index}__].value}" th:value="*{parameters[__${i.index}__].parameterValues[__${j.index}__].value}">
 
                   <span class="action-padding input-action-margin sort-icon">
                     <i class="fas fa-sort"></i>
@@ -151,25 +132,25 @@
             <div class="form-group row">
               <label for="exampleFormControlSelect1" class="col-sm-2">Umístění:</label>
               <div class="col-sm-10">
-                <div th:each="location : ${locations}" class="form-check form-check-inline">
-                  <input class="form-check-input" type="checkbox" th:id="'checkbox' + ${location.name}" th:value="${location.name}" th:checked="${parameter.locations.contains(location)}">
-                  <label class="form-check-label" th:for="checkbox + ${location.name}" th:text="${location.name}"></label>
+                <div th:each="location, j : ${allLocations}" class="form-check form-check-inline">
+                  <input class="form-check-input" th:field="*{parameters[__${i.index}__].locations}" type="checkbox" th:value="${location.id}" >
+                  <label class="form-check-label" th:for="${location.name}" th:text="${location.name}"></label>
                 </div>
               </div>
             </div>
             <div class="form-group row">
                 <label for="exampleFormControlSelect1" class="col-sm-2">Funkce:</label>
                 <div class="col-sm-10">
-                  <select class="mbSelect selectpicker" multiple data-live-search="true">
-                    <option th:each="function : ${functions}" th:value="'selectedFunction' + ${function.name}" th:text="${function.name}" th:selected="${parameter.functions.contains(function)}"></option>
+                  <select th:field="*{parameters[__${i.index}__].functions}" class="mbSelect selectpicker" multiple data-live-search="true">
+                    <option th:each="function : ${allFunctions}" th:value="${{function.id}}" th:text="${function.name}"></option>
                   </select>
                 </div>
             </div>
             <div class="form-group row">
                 <label for="exampleFormControlSelect1" class="col-sm-2">Operátory:</label>
                 <div class="col-sm-10">
-                  <select class="mbSelect selectpicker" multiple data-live-search="true">
-                    <option th:each="operator : ${operators}" th:value="'selectedOperator' + ${operator.name}" th:text="${operator.name}" th:selected="${parameter.operators.contains(operator)}"></option>
+                  <select th:field="*{parameters[__${i.index}__].operators}" class="mbSelect selectpicker" multiple data-live-search="true">
+                    <option th:each="operator : ${allOperators}" th:value="${{operator.id}}" th:text="${operator.name}"></option>
                   </select>
                 </div>
             </div>
@@ -185,9 +166,9 @@
     <div class="box-header">
       <h3 class="box-title">Oprávnění</h3>
     </div>
-
-    <div th:each="roleWithAccess : ${rolesWithAccess}" class="input-action-box input-border-bottom">
-      <input type="text" readonly class="form-control-plaintext" th:id="selectedRole + ${roleWithAccess.name}" th:value="${roleWithAccess.name}">
+    <div th:each="roleWithAccess, i : ${assembly.roles}" class="input-action-box input-border-bottom">
+      <input type="hidden" th:field="${assembly.roles[__${i.index}__].id}" th:value="${roleWithAccess.id}">
+      <input type="text" readonly class="form-control-plaintext" th:field="${assembly.roles[__${i.index}__].name}" th:id="selectedRole + ${roleWithAccess.name}" th:value="${roleWithAccess.name}">
 
       <span class="action-padding input-action-margin sort-icon">
       <i class="fas fa-sort"></i>
@@ -200,7 +181,7 @@
     <div class="form-group row form-add-item">
       <div class="col-md-9">
         <select class="form-control " id="selectNewRole">
-          <option th:each="role : ${roles}" th:value="newRole + ${role.name}" th:text="${role.name}"></option>
+          <option th:each="role : ${allRoles}" th:value="${role.id}" th:text="${role.name}"></option>
         </select>
       </div>
       <button type="submit" class="btn btn-primary mb-2">Přidat</button>
