mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
uniqueness validation is now also supported by the validation rules editor
This commit is contained in:
@@ -107,6 +107,9 @@ public class ValidationEditorController extends FXMLController {
|
||||
@FXML
|
||||
private CheckBox alphanumericRuleCheckBox;
|
||||
|
||||
@FXML
|
||||
private CheckBox uniqueRuleCheckBox;
|
||||
|
||||
@FXML
|
||||
private Spinner<Integer> minLengthSpinner;
|
||||
|
||||
@@ -155,6 +158,9 @@ public class ValidationEditorController extends FXMLController {
|
||||
@FXML
|
||||
private CheckBox enableGroovyRule;
|
||||
|
||||
@FXML
|
||||
private CheckBox enableUniqueRule;
|
||||
|
||||
|
||||
@Value("${fxml.smartcvs.validation.editor.view}")
|
||||
@Override
|
||||
@@ -172,6 +178,7 @@ public class ValidationEditorController extends FXMLController {
|
||||
initCheckBox(integerRuleCheckBox, enableIntegerRule);
|
||||
initCheckBox(doublerRuleCheckBox, enableDoubleRule);
|
||||
initCheckBox(alphanumericRuleCheckBox, enableAlphanumericRule);
|
||||
initCheckBox(uniqueRuleCheckBox, enableUniqueRule);
|
||||
initSpinner(minLengthSpinner, enableMinLengthRule);
|
||||
initSpinner(maxLengthSpinner, enableMaxLengthRule);
|
||||
initTextInputControl(dateformatRuleTextField, enableDateRule);
|
||||
@@ -214,6 +221,12 @@ public class ValidationEditorController extends FXMLController {
|
||||
validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), null);
|
||||
}
|
||||
|
||||
if (enableUniqueRule.isSelected()) {
|
||||
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), uniqueRuleCheckBox.isSelected());
|
||||
} else {
|
||||
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), null);
|
||||
}
|
||||
|
||||
if (enableDoubleRule.isSelected()) {
|
||||
validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), doublerRuleCheckBox.isSelected());
|
||||
} else {
|
||||
@@ -289,6 +302,12 @@ public class ValidationEditorController extends FXMLController {
|
||||
enableAlphanumericRule
|
||||
);
|
||||
|
||||
updateCheckBox(
|
||||
uniqueRuleCheckBox,
|
||||
validationConfiguration.getUniqueRuleFor(getSelectedColumn()),
|
||||
enableUniqueRule
|
||||
);
|
||||
|
||||
updateSpinner(
|
||||
minLengthSpinner,
|
||||
validationConfiguration.getMinLengthRuleFor(getSelectedColumn()),
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ValidationConfiguration {
|
||||
headerConfiguration.setNames(headerNames);
|
||||
}
|
||||
|
||||
public Boolean getUniquenessRuleFor(String column) {
|
||||
public Boolean getUniqueRuleFor(String column) {
|
||||
return (Boolean)getValue(column, "unique");
|
||||
}
|
||||
|
||||
@@ -114,6 +114,11 @@ public class ValidationConfiguration {
|
||||
setValue(column, value, "not empty");
|
||||
}
|
||||
|
||||
public void setUniqueRuleFor(String column, Boolean value) {
|
||||
setValue(column, value, "unique");
|
||||
}
|
||||
|
||||
|
||||
public void setMinLengthRuleFor(String column, Integer value) {
|
||||
setValue(column, value == null ? null : value.doubleValue(), "minlength");
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import groovy.lang.Script;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -112,7 +111,7 @@ public class Validator {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void checkUniqueness(String column, String value, Integer lineNumber, ValidationError error) {
|
||||
if (validationConfig.getUniquenessRuleFor(column) != null && validationConfig.getUniquenessRuleFor(column)) {
|
||||
if (validationConfig.getUniqueRuleFor(column) != null && validationConfig.getUniqueRuleFor(column)) {
|
||||
HashMap<String, Integer> columnValueMap = uniquenessLookupTable.get(column);
|
||||
columnValueMap = getColumnValueMap(column, columnValueMap);
|
||||
Integer valueInLineNumber = columnValueMap.get(value);
|
||||
|
||||
Reference in New Issue
Block a user