Revize 15c7afbe
Přidáno uživatelem Vojtěch Danišík před více než 4 roky(ů)
src/main/java/vldc/aswi/domain/Assembly.java | ||
---|---|---|
39 | 39 |
private List<Configuration> configurations; |
40 | 40 |
|
41 | 41 |
/** List of parameters, which using this assembly. */ |
42 |
@OneToMany(mappedBy = "assembly", fetch = FetchType.EAGER, orphanRemoval = true)
|
|
42 |
@OneToMany(mappedBy = "assembly", fetch = FetchType.EAGER) |
|
43 | 43 |
private List<Parameter> parameters; |
44 | 44 |
|
45 | 45 |
/** |
src/main/java/vldc/aswi/service/parameter/ParameterInConfigurationManager.java | ||
---|---|---|
1 | 1 |
package vldc.aswi.service.parameter; |
2 | 2 |
|
3 |
import vldc.aswi.domain.parameter.Parameter; |
|
3 | 4 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
4 | 5 |
|
6 |
import java.util.ArrayList; |
|
5 | 7 |
import java.util.List; |
6 | 8 |
|
7 | 9 |
/** |
... | ... | |
21 | 23 |
* @return List of deleted parameters in configuration. |
22 | 24 |
*/ |
23 | 25 |
boolean deleteParametersInConfiguration(Long id, boolean configurationUsed); |
26 |
|
|
27 |
/** |
|
28 |
* Add newly created parameters to all configurations, which are created from current assembly |
|
29 |
* @param assemblyId - ID of current assembly. |
|
30 |
*/ |
|
31 |
void addParameterIntoConfigurations(Long assemblyId, ArrayList<Parameter> parameters); |
|
32 |
|
|
33 |
/** |
|
34 |
* Update all parameter in configurations orders. |
|
35 |
* @param parameters - list of parameters for current assembly. |
|
36 |
*/ |
|
37 |
void updateParameterInConfigurationsOrder(List<Parameter> parameters); |
|
24 | 38 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterInConfigurationManagerImpl.java | ||
---|---|---|
7 | 7 |
import org.springframework.core.annotation.Order; |
8 | 8 |
import org.springframework.dao.InvalidDataAccessResourceUsageException; |
9 | 9 |
import org.springframework.stereotype.Service; |
10 |
import vldc.aswi.dao.AssemblyRepository; |
|
10 | 11 |
import vldc.aswi.dao.parameter.ParameterInConfigurationRepository; |
12 |
import vldc.aswi.domain.Assembly; |
|
13 |
import vldc.aswi.domain.Configuration; |
|
11 | 14 |
import vldc.aswi.domain.Function; |
15 |
import vldc.aswi.domain.parameter.Parameter; |
|
12 | 16 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
13 | 17 |
|
14 | 18 |
import javax.transaction.Transactional; |
... | ... | |
27 | 31 |
@Autowired |
28 | 32 |
private ParameterInConfigurationRepository parameterInConfigurationRepository; |
29 | 33 |
|
34 |
/** Autowired assembly repository. */ |
|
35 |
@Autowired |
|
36 |
private AssemblyRepository assemblyRepository; |
|
37 |
|
|
30 | 38 |
/** |
31 | 39 |
* Initialization setup for parameter in configuration manager. |
32 | 40 |
* Check if table "Parametr_konfigurace" exists. |
... | ... | |
59 | 67 |
return retVal; |
60 | 68 |
} |
61 | 69 |
|
70 |
/** |
|
71 |
* Add newly created parameters to all configurations, which are created from current assembly |
|
72 |
* @param assemblyId - ID of current assembly. |
|
73 |
*/ |
|
74 |
@Override |
|
75 |
public void addParameterIntoConfigurations(Long assemblyId, ArrayList<Parameter> parameters) { |
|
76 |
|
|
77 |
Assembly assembly = this.assemblyRepository.getById(assemblyId); |
|
78 |
List<Configuration> configurations = assembly.getConfigurations(); |
|
79 |
|
|
80 |
for (Parameter parameter : parameters) { |
|
81 |
|
|
82 |
for (Configuration configuration : configurations) { |
|
83 |
ParameterInConfiguration parameterInConfiguration = new ParameterInConfiguration(); |
|
84 |
|
|
85 |
parameterInConfiguration.setParameter(parameter); |
|
86 |
parameterInConfiguration.setConfiguration(configuration); |
|
87 |
parameterInConfiguration.setColumnName(parameter.getName()); |
|
88 |
// Set temporary parameter order. |
|
89 |
parameterInConfiguration.setParameterOrder(0); |
|
90 |
|
|
91 |
this.parameterInConfigurationRepository.save(parameterInConfiguration); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
62 | 96 |
/** |
63 | 97 |
* Delete all parameters in configuration by configuration id. |
64 | 98 |
* @param id - ID of parameter / configuration. |
... | ... | |
106 | 140 |
return false; |
107 | 141 |
} |
108 | 142 |
} |
143 |
|
|
144 |
/** |
|
145 |
* Update all parameter in configurations orders. |
|
146 |
* @param parameters - list of parameters for current assembly. |
|
147 |
*/ |
|
148 |
@Override |
|
149 |
public void updateParameterInConfigurationsOrder(List<Parameter> parameters) { |
|
150 |
|
|
151 |
// Update all parameters in configuration order. |
|
152 |
for (Parameter parameter : parameters) { |
|
153 |
|
|
154 |
for (ParameterInConfiguration parameterInConfiguration : this.parameterInConfigurationRepository.getAllByParameterId(parameter.getId())) { |
|
155 |
|
|
156 |
parameterInConfiguration.setParameterOrder(parameter.getParameterOrder()); |
|
157 |
this.parameterInConfigurationRepository.save(parameterInConfiguration); |
|
158 |
} |
|
159 |
} |
|
160 |
} |
|
109 | 161 |
} |
src/main/java/vldc/aswi/service/parameter/ParameterManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import vldc.aswi.domain.parameter.Parameter; |
4 | 4 |
|
5 |
import java.util.ArrayList; |
|
5 | 6 |
import java.util.List; |
6 | 7 |
|
7 | 8 |
/** |
... | ... | |
20 | 21 |
* @param assemblyId - Assembly in which parameter is presented. |
21 | 22 |
* @param parameterValuesList - Parameter values. |
22 | 23 |
*/ |
23 |
void addParameters(Long assemblyId, List<Parameter> parameterValuesList);
|
|
24 |
ArrayList<Parameter> addParameters(Long assemblyId, List<Parameter> parameterValuesList);
|
|
24 | 25 |
|
25 | 26 |
/** |
26 | 27 |
* Update parameter with given values. |
src/main/java/vldc/aswi/service/parameter/ParameterManagerImpl.java | ||
---|---|---|
102 | 102 |
* @param parameterValuesList - Parameter values. |
103 | 103 |
*/ |
104 | 104 |
@Override |
105 |
public void addParameters(Long assemblyId, List<Parameter> parameterValuesList) {
|
|
105 |
public ArrayList<Parameter> addParameters(Long assemblyId, List<Parameter> parameterValuesList) {
|
|
106 | 106 |
Assembly assembly = this.assemblyRepository.getById(assemblyId); |
107 |
if (parameterValuesList == null) return;
|
|
107 |
ArrayList<Parameter> newParameters = new ArrayList<>();
|
|
108 | 108 |
|
109 | 109 |
for (Parameter parameterValues : parameterValuesList) { |
110 | 110 |
// Create new parameter and assign him all values. |
... | ... | |
159 | 159 |
parameter.setOperators(operatorList); |
160 | 160 |
|
161 | 161 |
// Insert parameter into database. |
162 |
this.parameterRepository.save(parameter); |
|
162 |
Parameter newParameter = this.parameterRepository.save(parameter); |
|
163 |
newParameters.add(newParameter); |
|
163 | 164 |
} |
165 |
return newParameters; |
|
164 | 166 |
} |
165 | 167 |
|
166 | 168 |
/** |
... | ... | |
193 | 195 |
newAssemblyParametersUpdated.retainAll(currentAssemblyParametersUpdated); |
194 | 196 |
|
195 | 197 |
// If no parameter has been deleted or added, then updating is unnecessary. |
196 |
if (newAssemblyParametersNew.size() == 0 && currentAssemblyParametersDeleted.size() == 0 && newAssemblyParametersUpdated.size() == 0) |
|
198 |
if (newAssemblyParametersNew.size() == 0 && currentAssemblyParametersDeleted.size() == 0 && newAssemblyParametersUpdated.size() == 0) {
|
|
197 | 199 |
return; |
200 |
} |
|
198 | 201 |
|
199 |
// Remove deleted parameters. |
|
200 |
for (Parameter parameterWithValues : currentAssemblyParametersDeleted) { |
|
201 |
deleteParameter(parameterWithValues.getId()); |
|
202 |
if (currentAssemblyParametersDeleted.size() > 0) { |
|
203 |
// Remove deleted parameters. |
|
204 |
for (Parameter parameterWithValues : currentAssemblyParametersDeleted) { |
|
205 |
deleteParameter(parameterWithValues.getId()); |
|
206 |
} |
|
202 | 207 |
} |
203 | 208 |
|
204 |
// Update rest parameters. |
|
205 |
updateParameters(newAssemblyParametersUpdated); |
|
209 |
if (newAssemblyParametersUpdated.size() > 0) { |
|
210 |
// Update rest parameters. |
|
211 |
updateParameters(newAssemblyParametersUpdated); |
|
212 |
} |
|
213 |
|
|
214 |
if (newAssemblyParametersNew.size() > 0) { |
|
215 |
// Add new parameters. |
|
216 |
ArrayList<Parameter> newParameters = addParameters(assemblyId, newAssemblyParametersNew); |
|
217 |
|
|
218 |
// Create new parameters in configuration in all configurations, which are created from current assembly. |
|
219 |
this.parameterInConfigurationManager.addParameterIntoConfigurations(assemblyId, newParameters); |
|
220 |
} |
|
206 | 221 |
|
207 |
// Add new parameters
|
|
208 |
addParameters(assemblyId, newAssemblyParametersNew);
|
|
222 |
List<Parameter> newParameters = this.parameterRepository.getByAssemblyId(assemblyId);
|
|
223 |
assembly.setParameters(newParameters);
|
|
209 | 224 |
|
210 |
assembly.setParameters(this.parameterRepository.getByAssemblyId(assemblyId));
|
|
225 |
this.parameterInConfigurationManager.updateParameterInConfigurationsOrder(newParameters);
|
|
211 | 226 |
} |
212 | 227 |
} |
213 | 228 |
|
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
175 | 175 |
|
176 | 176 |
if (generateTable != null) |
177 | 177 |
{ |
178 |
Assembly assembly = this.assemblyManager.getAssemblyById(Long.parseLong(id)); |
|
179 |
newConfiguration.setAssembly(assembly); |
|
180 |
newConfiguration.setTableName(assembly.getName()); |
|
181 |
|
|
182 |
// If configuration name is empty, then replace it by assembly name. |
|
183 |
if (newConfiguration.getName().equals("")) { |
|
184 |
newConfiguration.setName(assembly.getName()); |
|
185 |
} |
|
186 |
|
|
178 | 187 |
System.out.println("Generuj tabulku"); |
179 | 188 |
prepareForTable(newConfiguration); |
180 | 189 |
System.out.println("Generuj tabulku"); |
... | ... | |
183 | 192 |
modelMap.addAttribute("contingencyTableRows", this.sqlQueryManager.getContingencyTableRow(newConfiguration)); |
184 | 193 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
185 | 194 |
initializeFields(newConfiguration); |
195 |
|
|
186 | 196 |
modelMap.addAttribute("configuration", newConfiguration); |
187 | 197 |
modelMap.addAttribute("comparator", comparator); |
188 | 198 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
... | ... | |
310 | 320 |
|
311 | 321 |
// TODO: chybí defaultValue. |
312 | 322 |
Long assemblyID = this.assemblyManager.updateAssembly(assembly); |
323 |
|
|
313 | 324 |
this.parameterManager.updateParameters(assemblyID, assembly.getParameters()); |
314 | 325 |
Assembly updatedAssembly = this.assemblyManager.getAssemblyById(assemblyID); |
315 | 326 |
|
Také k dispozici: Unified diff
re #8153 Assembly -> Configuration synchronization