Revize c08ea26b
Přidáno uživatelem Michal Linha před více než 4 roky(ů)
src/main/java/vldc/aswi/domain/parameter/ParameterInConfiguration.java | ||
---|---|---|
16 | 16 |
@Data |
17 | 17 |
@EqualsAndHashCode(callSuper = true) |
18 | 18 |
@NoArgsConstructor |
19 |
@OperatorValueConstraint |
|
20 | 19 |
public class ParameterInConfiguration extends EntityParent implements Comparable<ParameterInConfiguration> { |
21 | 20 |
|
22 | 21 |
/** Specific configuration in which is this parameterConfiguration presented. */ |
src/main/java/vldc/aswi/model/table/Node.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
private boolean isUsable; |
28 | 28 |
|
29 |
private boolean isFilledTotalValue = false; |
|
30 |
|
|
29 | 31 |
/** |
30 | 32 |
* Values of the nodes on a path the the node. |
31 | 33 |
*/ |
... | ... | |
139 | 141 |
public void setUsable(boolean usable) { |
140 | 142 |
isUsable = usable; |
141 | 143 |
} |
144 |
|
|
145 |
public boolean isFilledTotalValue() { |
|
146 |
return isFilledTotalValue; |
|
147 |
} |
|
148 |
|
|
149 |
public void setFilledTotalValue(boolean filledTotalValue) { |
|
150 |
isFilledTotalValue = filledTotalValue; |
|
151 |
} |
|
142 | 152 |
} |
src/main/java/vldc/aswi/model/table/ValueFunction.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
private boolean isFirstMax = true; |
24 | 24 |
|
25 |
private boolean isFilledTotalValue = false; |
|
26 |
|
|
25 | 27 |
/** |
26 | 28 |
* Value |
27 | 29 |
*/ |
... | ... | |
159 | 161 |
public void setFirstMax(boolean firstMax) { |
160 | 162 |
isFirstMax = firstMax; |
161 | 163 |
} |
164 |
|
|
165 |
public boolean isFilledTotalValue() { |
|
166 |
return isFilledTotalValue; |
|
167 |
} |
|
168 |
|
|
169 |
public void setFilledTotalValue(boolean filledTotalValue) { |
|
170 |
isFilledTotalValue = filledTotalValue; |
|
171 |
} |
|
162 | 172 |
} |
src/main/java/vldc/aswi/service/SqlQueryManagerImpl.java | ||
---|---|---|
116 | 116 |
boolean isWhereDefined = false; |
117 | 117 |
|
118 | 118 |
for (ParameterInConfiguration parameterInConfiguration : parametersInConfiguration) { |
119 |
if (parameterInConfiguration.getOperator() != null && !parameterInConfiguration.getOperator().getName().equals("zadny") && |
|
119 |
if (parameterInConfiguration.getParameter().getParameterType().getName().equals("Výčet") && false) { |
|
120 |
isWhereDefined = processListing(parameterInConfiguration, finalSQLQuery, isWhereDefined); |
|
121 |
} |
|
122 |
else if (parameterInConfiguration.getOperator() != null && !parameterInConfiguration.getOperator().getName().equals("zadny") && |
|
120 | 123 |
parameterInConfiguration.getOperatorValue() != null && !parameterInConfiguration.getOperatorValue().equals("")) { |
121 |
String[] values = parameterInConfiguration.getOperatorValue().split(";"); |
|
122 |
if (!isWhereDefined) { |
|
123 |
finalSQLQuery.append(" WHERE "); |
|
124 |
isWhereDefined = true; |
|
125 |
} else { |
|
126 |
finalSQLQuery.append(" AND "); |
|
127 |
} |
|
128 |
|
|
129 |
finalSQLQuery.append(parameterInConfiguration.getParameter().getNameOfSelect()); |
|
130 |
finalSQLQuery.append(" "); |
|
131 |
finalSQLQuery.append(parameterInConfiguration.getOperator().getName()); |
|
132 |
finalSQLQuery.append(" "); |
|
133 |
switch (parameterInConfiguration.getOperator().getName()) { |
|
134 |
case "BETWEEN": |
|
135 |
case "NOT BETWEEN": |
|
136 |
finalSQLQuery.append(betweenNotBetween(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
137 |
break; |
|
138 |
case "IN": |
|
139 |
case "NOT IN": |
|
140 |
finalSQLQuery.append(inNotIn(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
141 |
break; |
|
142 |
case "LIKE": |
|
143 |
case "NOT LIKE": |
|
144 |
finalSQLQuery.append(likeNotLike(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
145 |
break; |
|
146 |
default: |
|
147 |
finalSQLQuery.append(otherOperators(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
148 |
break; |
|
149 |
} |
|
124 |
isWhereDefined = processFilter(parameterInConfiguration, finalSQLQuery, isWhereDefined); |
|
150 | 125 |
} |
151 | 126 |
} |
152 | 127 |
|
153 | 128 |
return finalSQLQuery.toString(); |
154 | 129 |
} |
155 | 130 |
|
131 |
private boolean processListing(ParameterInConfiguration parameterInConfiguration, StringBuilder finalSQLQuery, boolean isWhereDefined) { |
|
132 |
if (!isWhereDefined) { |
|
133 |
finalSQLQuery.append(" WHERE "); |
|
134 |
} else { |
|
135 |
finalSQLQuery.append(" AND "); |
|
136 |
} |
|
137 |
|
|
138 |
finalSQLQuery.append(parameterInConfiguration.getParameter().getNameOfSelect()); |
|
139 |
finalSQLQuery.append(" IN "); |
|
140 |
inNotIn(null, "Text"); |
|
141 |
|
|
142 |
return true; |
|
143 |
} |
|
144 |
|
|
145 |
private boolean processFilter(ParameterInConfiguration parameterInConfiguration, StringBuilder finalSQLQuery, boolean isWhereDefined) { |
|
146 |
String[] values = parameterInConfiguration.getOperatorValue().split(";"); |
|
147 |
if (!isWhereDefined) { |
|
148 |
finalSQLQuery.append(" WHERE "); |
|
149 |
} else { |
|
150 |
finalSQLQuery.append(" AND "); |
|
151 |
} |
|
152 |
|
|
153 |
finalSQLQuery.append(parameterInConfiguration.getParameter().getNameOfSelect()); |
|
154 |
finalSQLQuery.append(" "); |
|
155 |
finalSQLQuery.append(parameterInConfiguration.getOperator().getName()); |
|
156 |
if (parameterInConfiguration.getOperator().getName().equals("IS NULL") || |
|
157 |
parameterInConfiguration.getOperator().getName().equals("IS NOT NULL")) { |
|
158 |
return true; |
|
159 |
} |
|
160 |
finalSQLQuery.append(" "); |
|
161 |
switch (parameterInConfiguration.getOperator().getName()) { |
|
162 |
case "BETWEEN": |
|
163 |
case "NOT BETWEEN": |
|
164 |
finalSQLQuery.append(betweenNotBetween(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
165 |
break; |
|
166 |
case "IN": |
|
167 |
case "NOT IN": |
|
168 |
finalSQLQuery.append(inNotIn(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
169 |
break; |
|
170 |
case "LIKE": |
|
171 |
case "NOT LIKE": |
|
172 |
finalSQLQuery.append(likeNotLike(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
173 |
break; |
|
174 |
default: |
|
175 |
finalSQLQuery.append(otherOperators(values, parameterInConfiguration.getParameter().getParameterType().getName())); |
|
176 |
break; |
|
177 |
} |
|
178 |
|
|
179 |
return true; |
|
180 |
} |
|
181 |
|
|
156 | 182 |
private String likeNotLike(String[] values, String type) { |
157 | 183 |
StringBuilder SQLQueryPart = new StringBuilder(); |
158 | 184 |
addQuotes(type, SQLQueryPart); |
src/main/java/vldc/aswi/utils/Converter.java | ||
---|---|---|
15 | 15 |
*/ |
16 | 16 |
public class Converter { |
17 | 17 |
|
18 |
private final boolean isNotRemoveEmpty; |
|
19 |
|
|
18 | 20 |
private final Map<String, TableColumn> tableColumns; |
19 | 21 |
private final List<NameUserName> rowNames; |
20 | 22 |
private final List<NameUserName> columnNames; |
... | ... | |
24 | 26 |
private final DecimalFormat decimalFormat = new DecimalFormat("0.###"); |
25 | 27 |
|
26 | 28 |
public Converter(Map<String, TableColumn> tableColumns, List<NameUserName> rowNames, List<NameUserName> columnNames, |
27 |
List<ValueFunction> valueFunctions) { |
|
29 |
List<ValueFunction> valueFunctions, boolean isNotRemoveEmpty) {
|
|
28 | 30 |
this.tableColumns = tableColumns; |
29 | 31 |
this.rowNames = rowNames; |
30 | 32 |
this.columnNames = columnNames; |
31 | 33 |
this.valueFunctions = valueFunctions; |
34 |
this.isNotRemoveEmpty = isNotRemoveEmpty; |
|
32 | 35 |
} |
33 | 36 |
|
34 | 37 |
/** |
... | ... | |
59 | 62 |
long stopTime2 = System.nanoTime(); |
60 | 63 |
System.out.println("Rows:" + TimeUnit.MILLISECONDS.convert((stopTime2 - startTime2), TimeUnit.NANOSECONDS)); |
61 | 64 |
|
62 |
long startTime3 = System.nanoTime(); |
|
63 |
for (ContingencyTableRow dataRow : dataRows) { |
|
64 |
for (int i = 0; i < columnNodes.size(); i++) { |
|
65 |
if (!columnNodes.get(i).isUsable()) { |
|
66 |
dataRow.getCells().remove(i + 1); |
|
65 |
if (isNotRemoveEmpty) { |
|
66 |
long startTime3 = System.nanoTime(); |
|
67 |
for (ContingencyTableRow dataRow : dataRows) { |
|
68 |
for (int i = 0; i < columnNodes.size(); i++) { |
|
69 |
if (!columnNodes.get(i).isUsable()) { |
|
70 |
dataRow.getCells().remove(i + 1); |
|
71 |
} |
|
67 | 72 |
} |
68 | 73 |
} |
69 |
} |
|
70 | 74 |
|
71 |
columnNodes.removeIf(node -> !node.isUsable()); |
|
72 |
long stopTime3 = System.nanoTime(); |
|
73 |
System.out.println("Columns remove:" + TimeUnit.MILLISECONDS.convert((stopTime3 - startTime3), TimeUnit.NANOSECONDS)); |
|
75 |
columnNodes.removeIf(node -> !node.isUsable()); |
|
76 |
long stopTime3 = System.nanoTime(); |
|
77 |
System.out.println("Columns remove:" + TimeUnit.MILLISECONDS.convert((stopTime3 - startTime3), TimeUnit.NANOSECONDS)); |
|
78 |
} |
|
74 | 79 |
|
75 | 80 |
long startTime4 = System.nanoTime(); |
76 | 81 |
List<ContingencyTableRow> headerRows = createHeaderOnlyRows(); |
... | ... | |
127 | 132 |
String value = columnNode.getValues().get(i); |
128 | 133 |
if (!prevValues.contains(value)) { |
129 | 134 |
prevValues.add(value); |
130 |
headerRows.get(i + 1).addTableRowCell(new ContingencyTableRowCell(value, 1)); |
|
135 |
headerRows.get(i + 1).addTableRowCell(new ContingencyTableRowCell(columnNames.get(i).getUserName() + " - " + value, 1));
|
|
131 | 136 |
headerRows.get(0).getCells().get(headerRows.get(0).getCells().size() - 1).setColSpan(headerRows.get(0).getCells().get(headerRows.get(0).getCells().size() - 1).getColSpan() + 1); |
132 | 137 |
} else if (columnNode.getValues().size() >= prevSize) { |
133 | 138 |
headerRows.get(i + 1).getCells().get(headerRows.get(i + 1).getCells().size() - 1).setColSpan(headerRows.get(i + 1).getCells().get(headerRows.get(i + 1).getCells().size() - 1).getColSpan() + 1); |
... | ... | |
233 | 238 |
for (int i = 0; i < index; i++) { |
234 | 239 |
levelString.append(" "); |
235 | 240 |
} |
236 |
levelString.append(s); |
|
241 |
levelString.append(rowNames.get(index).getUserName()).append(" - ").append(s);
|
|
237 | 242 |
ContingencyTableRow row = new ContingencyTableRow(false, index); |
238 | 243 |
row.addTableRowCell(new ContingencyTableRowCell(levelString.toString(), 1)); |
239 | 244 |
rows.add(row); |
... | ... | |
259 | 264 |
for (String s : list) { |
260 | 265 |
Node node = new Node(prevNode); |
261 | 266 |
node.getValues().add(s); |
262 |
if (checkIfColumnIsUsable(node.getValues())) { |
|
267 |
if (isNotRemoveEmpty) { |
|
268 |
int newIndex = index + 1; |
|
269 |
generateColumns(newIndex, values, columnNodes, node); |
|
270 |
columnNodes.add(node); |
|
271 |
} |
|
272 |
else if (checkIfColumnIsUsable(node.getValues())) { |
|
263 | 273 |
int newIndex = index + 1; |
264 | 274 |
generateColumns(newIndex, values, columnNodes, node); |
265 | 275 |
columnNodes.add(node); |
... | ... | |
285 | 295 |
} |
286 | 296 |
|
287 | 297 |
boolean isRowUsable = false; |
298 |
if (isNotRemoveEmpty) { |
|
299 |
isRowUsable = true; |
|
300 |
} |
|
301 |
|
|
288 | 302 |
if (columnNodes.size() == 0) { |
289 | 303 |
columnNodes.add(new Node()); |
290 | 304 |
} |
... | ... | |
295 | 309 |
!usableIDs.isEmpty()) { |
296 | 310 |
return true; |
297 | 311 |
} |
312 |
else if (valueFunctions.get(0).getFunction() != null && valueFunctions.get(0).getFunction().equals("NIC") && |
|
313 |
usableIDs.isEmpty()) { |
|
314 |
return isRowUsable; |
|
315 |
} |
|
298 | 316 |
|
299 | 317 |
DoubleWrapper[] totals = new DoubleWrapper[valueFunctions.size()]; |
300 | 318 |
initializeWrapperField(totals); |
... | ... | |
354 | 372 |
row.addTableRowCell(new ContingencyTableRowCell("", 0)); |
355 | 373 |
} |
356 | 374 |
else { |
375 |
columnNode.setFilledTotalValue(true); |
|
357 | 376 |
row.addTableRowCell(generateFilledCell(valueFunction.getFunction(), result.getValue(), result.getValue(), result.getValue(), |
358 | 377 |
result.getValue(), resultAvgSum.getValue(), result.getValue())); |
359 | 378 |
} |
... | ... | |
367 | 386 |
row.addTableRowCell(new ContingencyTableRowCell("", 0)); |
368 | 387 |
} |
369 | 388 |
else { |
389 |
valueFunctions.get(i).setFilledTotalValue(true); |
|
370 | 390 |
row.addTableRowCell(generateFilledCell(valueFunctions.get(i).getFunction(), totals[i].getValue(), totals[i].getValue(), |
371 | 391 |
totals[i].getValue(), totals[i].getValue(), totalsAvgSum[i].getValue(), totals[i].getValue())); |
372 | 392 |
} |
... | ... | |
582 | 602 |
List<ContingencyTableRowCell> valueCells = new ArrayList<>(); |
583 | 603 |
for (ValueFunction valueFunction : valueFunctions) { |
584 | 604 |
for (Node columnNode : columnNodes) { |
605 |
if (columnNode.isFilledTotalValue()) { |
|
585 | 606 |
finalRow.addTableRowCell(generateFilledCell(valueFunction.getFunction(), columnNode.getTotalResult(), columnNode.getTotalResultSum(), |
586 | 607 |
columnNode.getTotalMin(), columnNode.getTotalMax(), columnNode.getTotalResultAvgSum(), |
587 | 608 |
columnNode.getTotalResultAvg())); |
609 |
} |
|
610 |
else { |
|
611 |
finalRow.addTableRowCell(new ContingencyTableRowCell("", 0)); |
|
612 |
} |
|
613 |
} |
|
614 |
if (valueFunction.isFilledTotalValue()) { |
|
615 |
valueCells.add(generateFilledCell(valueFunction.getFunction(), valueFunction.getTotalResult(), valueFunction.getTotalResultSum(), |
|
616 |
valueFunction.getTotalMin(), valueFunction.getTotalMax(), valueFunction.getTotalResultAvgSum(), |
|
617 |
valueFunction.getTotalResultAvg())); |
|
618 |
} |
|
619 |
else { |
|
620 |
valueCells.add(new ContingencyTableRowCell("", 0)); |
|
588 | 621 |
} |
589 |
valueCells.add(generateFilledCell(valueFunction.getFunction(), valueFunction.getTotalResult(), valueFunction.getTotalResultSum(), |
|
590 |
valueFunction.getTotalMin(), valueFunction.getTotalMax(), valueFunction.getTotalResultAvgSum(), |
|
591 |
valueFunction.getTotalResultAvg())); |
|
592 | 622 |
} |
593 | 623 |
|
594 | 624 |
finalRow.addTableRowCells(valueCells); |
src/main/java/vldc/aswi/validators/ConfigurationValidator.java | ||
---|---|---|
1 |
package vldc.aswi.validators; |
|
2 |
|
|
3 |
import org.springframework.beans.factory.annotation.Autowired; |
|
4 |
import org.springframework.stereotype.Component; |
|
5 |
import org.springframework.util.NumberUtils; |
|
6 |
import org.springframework.validation.Errors; |
|
7 |
import org.springframework.validation.Validator; |
|
8 |
import vldc.aswi.domain.Assembly; |
|
9 |
import vldc.aswi.domain.Configuration; |
|
10 |
import vldc.aswi.domain.parameter.Parameter; |
|
11 |
import vldc.aswi.domain.parameter.ParameterInConfiguration; |
|
12 |
import vldc.aswi.service.SqlQueryManager; |
|
13 |
|
|
14 |
import java.text.ParseException; |
|
15 |
import java.text.SimpleDateFormat; |
|
16 |
import java.util.Date; |
|
17 |
import java.util.List; |
|
18 |
|
|
19 |
@Component |
|
20 |
public class ConfigurationValidator implements Validator { |
|
21 |
|
|
22 |
/** |
|
23 |
* Validator for supporting this class. |
|
24 |
* @param aClass - Class. |
|
25 |
* @return true if sent class match Configuration class. |
|
26 |
*/ |
|
27 |
@Override |
|
28 |
public boolean supports(Class<?> aClass) { |
|
29 |
return Configuration.class.isAssignableFrom(aClass); |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public void validate(Object obj, Errors errors) { |
|
34 |
Configuration configuration = (Configuration) obj; |
|
35 |
|
|
36 |
List<ParameterInConfiguration> parametersInConfiguration = configuration.getParametersInConfiguration(); |
|
37 |
for (int i = 0; i < parametersInConfiguration.size(); i++) { |
|
38 |
ParameterInConfiguration parameterInConfiguration = parametersInConfiguration.get(i); |
|
39 |
if (parameterInConfiguration.getOperator() == null || parameterInConfiguration.getOperatorValue() == null || |
|
40 |
parameterInConfiguration.getOperatorValue().equals("")) { |
|
41 |
continue; |
|
42 |
} |
|
43 |
if (parameterInConfiguration.getOperator().getName().equals("BETWEEN") || |
|
44 |
parameterInConfiguration.getOperator().getName().equals("NOT BETWEEN")) { |
|
45 |
validateBETWEEN(parameterInConfiguration, errors, i, parameterInConfiguration.getOperator().getName()); |
|
46 |
} |
|
47 |
else if (parameterInConfiguration.getOperator().getName().equals("IN") || |
|
48 |
parameterInConfiguration.getOperator().getName().equals("NOT IN")) { |
|
49 |
validateIN(parameterInConfiguration, errors, i, parameterInConfiguration.getOperator().getName()); |
|
50 |
} |
|
51 |
else if (!parameterInConfiguration.getOperator().getName().equals("LIKE") || |
|
52 |
parameterInConfiguration.getOperator().getName().equals("NOT LIKE")) { |
|
53 |
validateOthersExceptLIKE(parameterInConfiguration, errors, i, parameterInConfiguration.getOperator().getName()); |
|
54 |
} |
|
55 |
} |
|
56 |
|
|
57 |
} |
|
58 |
|
|
59 |
private void validateBETWEEN(ParameterInConfiguration parameterInConfiguration, Errors errors, int i, String operator) { |
|
60 |
if (!parameterInConfiguration.getOperatorValue().matches("\\w+;\\w+")) { |
|
61 |
errors.rejectValue("parametersInConfiguration[" + i + "].operatorValue", "Nesprávně oddělené hodnoty" + |
|
62 |
" filtru " + operator +"! Použijte ';' pro oddělení hodnot!"); |
|
63 |
} |
|
64 |
else { |
|
65 |
validateValuesInList(parameterInConfiguration, errors, i, operator); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
private void validateValuesInList(ParameterInConfiguration parameterInConfiguration, Errors errors, int i, String operator) { |
|
70 |
String[] values = parameterInConfiguration.getOperatorValue().split(";"); |
|
71 |
for (String value : values) { |
|
72 |
if (parameterInConfiguration.getParameter().getParameterType().getName().equals("Datum")) { |
|
73 |
validateDate(value, errors, i, operator); |
|
74 |
} |
|
75 |
if (parameterInConfiguration.getParameter().getParameterType().getName().equals("Číslo")) { |
|
76 |
validateNumber(value, errors, i, operator); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
private void validateIN(ParameterInConfiguration parameterInConfiguration, Errors errors, int i, String operator) { |
|
82 |
if (!parameterInConfiguration.getOperatorValue().matches("\\w+(;\\w+)*$")) { |
|
83 |
errors.rejectValue("parametersInConfiguration[" + i + "].operatorValue", "Špatně zadaná hodnota" + |
|
84 |
" filtru " + operator + "! Použijte ';' pro oddělení hodnot!"); |
|
85 |
} |
|
86 |
else { |
|
87 |
validateValuesInList(parameterInConfiguration, errors, i, operator); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
private void validateOthersExceptLIKE(ParameterInConfiguration parameterInConfiguration, Errors errors, int i, String operator) { |
|
92 |
if (parameterInConfiguration.getParameter().getParameterType().getName().equals("Datum")) { |
|
93 |
validateDate(parameterInConfiguration.getOperatorValue(), errors, i, operator); |
|
94 |
} |
|
95 |
if (parameterInConfiguration.getParameter().getParameterType().getName().equals("Číslo")) { |
|
96 |
validateNumber(parameterInConfiguration.getOperatorValue(), errors, i, operator); |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
private void validateNumber(String value, Errors errors, int i, String operator) { |
|
101 |
if (!value.matches("-?\\d+(\\.\\d+)?")) { |
|
102 |
errors.rejectValue("parametersInConfiguration[" + i + "].operatorValue", "Špatně zadaná hodnota" + |
|
103 |
" filtru " + operator + "! Očekává se číslo!"); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
private void validateDate(String value, Errors errors, int i, String operator) { |
|
108 |
try { |
|
109 |
new SimpleDateFormat("yyyy-MM-dd").parse(value); |
|
110 |
} catch (ParseException nfe) { |
|
111 |
errors.rejectValue("parametersInConfiguration[" + i + "].operatorValue", "Špatně zadaná hodnota" + |
|
112 |
" filtru " + operator + "! Očekává se datum!"); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
src/main/java/vldc/aswi/web/controller/AssemblyController.java | ||
---|---|---|
3 | 3 |
import org.springframework.beans.factory.annotation.Autowired; |
4 | 4 |
import org.springframework.stereotype.Controller; |
5 | 5 |
import org.springframework.ui.ModelMap; |
6 |
import org.springframework.validation.BeanPropertyBindingResult; |
|
6 | 7 |
import org.springframework.validation.BindingResult; |
7 | 8 |
import org.springframework.web.bind.WebDataBinder; |
8 | 9 |
import org.springframework.web.bind.annotation.GetMapping; |
... | ... | |
22 | 23 |
import vldc.aswi.utils.AuthControl; |
23 | 24 |
import vldc.aswi.validators.AssemblyValidator; |
24 | 25 |
import vldc.aswi.utils.Utils; |
26 |
import vldc.aswi.validators.ConfigurationValidator; |
|
25 | 27 |
|
26 | 28 |
import javax.validation.Valid; |
27 | 29 |
import java.util.ArrayList; |
... | ... | |
76 | 78 |
@Autowired |
77 | 79 |
private AssemblyValidator assemblyValidator; |
78 | 80 |
|
81 |
/** Autowired configuration validator */ |
|
82 |
@Autowired |
|
83 |
private ConfigurationValidator configurationValidator; |
|
84 |
|
|
79 | 85 |
/** Name of thymeleaf parameter, which will contain text in assembly form. */ |
80 | 86 |
private String assemblyTitleName = "title"; |
81 | 87 |
|
... | ... | |
85 | 91 |
/** Title text for new assembly form. */ |
86 | 92 |
private String assemblyNewTitleText = "Vytvoření nové sestavy"; |
87 | 93 |
|
94 |
/** Title text for table generation form. */ |
|
95 |
private String generateTableTitleText = "Generování tabulky - "; |
|
96 |
|
|
88 | 97 |
/** |
89 | 98 |
* Bind assembly validator. |
90 | 99 |
* @param binder Binder. |
... | ... | |
167 | 176 |
{ |
168 | 177 |
|
169 | 178 |
ModelAndView modelAndView = new ModelAndView(); |
179 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
170 | 180 |
|
171 | 181 |
if (bindingResult.hasErrors()) { |
172 | 182 |
// TODO: 04.05.2020 Error message |
... | ... | |
188 | 198 |
|
189 | 199 |
System.out.println("Generuj tabulku"); |
190 | 200 |
prepareForTable(newConfiguration); |
201 |
BindingResult errors = new BeanPropertyBindingResult(newConfiguration, newConfiguration.getClass().getName()); |
|
202 |
configurationValidator.validate(newConfiguration, errors); |
|
203 |
if (errors.hasErrors()) { |
|
204 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
191 | 205 |
|
192 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration.getAssembly().getSQLQuery(), |
|
193 |
newConfiguration.getParametersInConfiguration()); |
|
206 |
modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(errors)); |
|
207 |
modelMap.addAttribute(assemblyTitleName, generateTableTitleText + " " + newConfiguration.getName()); |
|
208 |
} |
|
209 |
else { |
|
210 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration); |
|
194 | 211 |
|
195 |
System.out.println("Generuj tabulku"); |
|
196 |
ModelMap modelMap = modelAndView.getModelMap(); |
|
197 |
modelMap.addAttribute("configurationID", id); |
|
198 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
199 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
200 |
initializeFields(newConfiguration); |
|
201 |
|
|
202 |
modelMap.addAttribute("configuration", newConfiguration); |
|
203 |
modelMap.addAttribute("comparator", comparator); |
|
204 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
|
205 |
modelAndView.setViewName("assembly"); |
|
212 |
System.out.println("Generuj tabulku"); |
|
213 |
modelMap.addAttribute("configurationID", id); |
|
214 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
215 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
216 |
} |
|
206 | 217 |
} |
207 | 218 |
else if (exportXls != null) |
208 | 219 |
{ |
... | ... | |
243 | 254 |
*/ |
244 | 255 |
} |
245 | 256 |
|
257 |
private void addConfigurationDataIntoModelAndView(Configuration newConfiguration, ModelAndView modelAndView, ModelMap modelMap) { |
|
258 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
259 |
initializeFields(newConfiguration); |
|
260 |
modelMap.addAttribute("configuration", newConfiguration); |
|
261 |
modelMap.addAttribute("comparator", comparator); |
|
262 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
|
263 |
modelAndView.setViewName("assembly"); |
|
264 |
} |
|
265 |
|
|
246 | 266 |
/** |
247 | 267 |
* Get method for assembly delete. |
248 | 268 |
* @param id - ID of assembly. |
src/main/java/vldc/aswi/web/controller/ConfigurationController.java | ||
---|---|---|
3 | 3 |
import org.springframework.beans.factory.annotation.Autowired; |
4 | 4 |
import org.springframework.stereotype.Controller; |
5 | 5 |
import org.springframework.ui.ModelMap; |
6 |
import org.springframework.validation.BeanPropertyBindingResult; |
|
6 | 7 |
import org.springframework.validation.BindingResult; |
8 |
import org.springframework.web.bind.WebDataBinder; |
|
7 | 9 |
import org.springframework.web.bind.annotation.*; |
8 | 10 |
import org.springframework.web.servlet.ModelAndView; |
9 | 11 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
... | ... | |
19 | 21 |
import vldc.aswi.service.SqlQueryManager; |
20 | 22 |
import vldc.aswi.utils.AuthControl; |
21 | 23 |
import vldc.aswi.utils.Utils; |
24 |
import vldc.aswi.validators.AssemblyValidator; |
|
25 |
import vldc.aswi.validators.ConfigurationValidator; |
|
26 |
|
|
27 |
import javax.validation.Valid; |
|
22 | 28 |
import java.util.ArrayList; |
23 | 29 |
import java.util.Comparator; |
24 | 30 |
import java.util.List; |
... | ... | |
45 | 51 |
@Autowired |
46 | 52 |
private ConfigurationManager configurationManager; |
47 | 53 |
|
54 |
/** Autowired configuration validator */ |
|
55 |
@Autowired |
|
56 |
private ConfigurationValidator configurationValidator; |
|
57 |
|
|
58 |
/** Name of thymeleaf parameter, which will contain text in assembly form. */ |
|
59 |
private String assemblyTitleName = "title"; |
|
60 |
|
|
61 |
/** Title text for table generation form. */ |
|
62 |
private String generateTableTitleText = "Generování tabulky - "; |
|
63 |
|
|
48 | 64 |
/** |
49 | 65 |
* Opens an configuration page after configuration name was clicked |
50 | 66 |
* @param id ID of configuration |
... | ... | |
96 | 112 |
* @return modelAndView with redirection |
97 | 113 |
*/ |
98 | 114 |
@PostMapping("/configuration") |
99 |
public ModelAndView configurationPost(Configuration newConfiguration, |
|
115 |
public ModelAndView configurationPost(@Valid Configuration newConfiguration,
|
|
100 | 116 |
BindingResult bindingResult, |
101 | 117 |
@RequestParam("configurationID") String id, |
102 | 118 |
@RequestParam(required=false, value="generateTable") String generateTable, |
... | ... | |
119 | 135 |
if (generateTable != null) |
120 | 136 |
{ |
121 | 137 |
prepareForTable(newConfiguration); |
122 |
System.out.println("Generuj tabulku"); |
|
123 |
|
|
124 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration.getAssembly().getSQLQuery(), |
|
125 |
newConfiguration.getParametersInConfiguration()); |
|
126 |
|
|
127 |
modelMap.addAttribute("configurationID", id); |
|
128 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
129 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
130 |
initializeFields(newConfiguration); |
|
131 |
modelMap.addAttribute("configuration", newConfiguration); |
|
132 |
modelMap.addAttribute("comparator", comparator); |
|
133 |
modelMap.addAttribute("formAction", "/configuration?configurationID=" + id); |
|
134 |
modelAndView.setViewName("assembly"); |
|
138 |
BindingResult errors = new BeanPropertyBindingResult(newConfiguration, newConfiguration.getClass().getName()); |
|
139 |
configurationValidator.validate(newConfiguration, errors); |
|
140 |
if (errors.hasErrors()) { |
|
141 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
142 |
|
|
143 |
modelMap.addAttribute(assemblyErrorName, getFullErrorMessage(errors)); |
|
144 |
modelMap.addAttribute(assemblyTitleName, generateTableTitleText + " " + newConfiguration.getName()); |
|
145 |
} |
|
146 |
else { |
|
147 |
List<ContingencyTableRow> rows = this.sqlQueryManager.getContingencyTableRow(newConfiguration); |
|
148 |
System.out.println("Generuj tabulku"); |
|
149 |
modelMap.addAttribute("configurationID", id); |
|
150 |
modelMap.addAttribute("contingencyTableRows", rows); |
|
151 |
addConfigurationDataIntoModelAndView(newConfiguration, modelAndView, modelMap); |
|
152 |
} |
|
135 | 153 |
} |
136 | 154 |
else if (exportXls != null) |
137 | 155 |
{ |
... | ... | |
220 | 238 |
} |
221 | 239 |
} |
222 | 240 |
} |
241 |
|
|
242 |
private void addConfigurationDataIntoModelAndView(Configuration newConfiguration, ModelAndView modelAndView, ModelMap modelMap) { |
|
243 |
Comparator<ParameterInConfiguration> comparator = Comparator.comparingInt(o -> o.getParameter().getParameterOrder()); |
|
244 |
initializeFields(newConfiguration); |
|
245 |
modelMap.addAttribute("configuration", newConfiguration); |
|
246 |
modelMap.addAttribute("comparator", comparator); |
|
247 |
modelMap.addAttribute("formAction", "/assembly?assemblyID=" + newConfiguration.getAssembly().getId()); |
|
248 |
modelAndView.setViewName("assembly"); |
|
249 |
} |
|
223 | 250 |
} |
Také k dispozici: Unified diff
re #7885 added option to show empty rows and columns, bug fixes re #8134 nothing; re #8154 added validator; re #8136 added column names no comments