mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
first quick implementation of to support json table schema
This commit is contained in:
@@ -228,71 +228,71 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
public void updateConfiguration() {
|
public void updateConfiguration() {
|
||||||
|
|
||||||
if (enableIntegerRule.isSelected()) {
|
// if (enableIntegerRule.isSelected()) {
|
||||||
validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), enableIntegerRule.isSelected());
|
// validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), enableIntegerRule.isSelected());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setIntegerRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableNotEmptyRule.isSelected()) {
|
// if (enableNotEmptyRule.isSelected()) {
|
||||||
validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), enableNotEmptyRule.isSelected());
|
// validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), enableNotEmptyRule.isSelected());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setNotEmptyRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableUniqueRule.isSelected()) {
|
// if (enableUniqueRule.isSelected()) {
|
||||||
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), enableUniqueRule.isSelected());
|
// validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), enableUniqueRule.isSelected());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setUniqueRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableDoubleRule.isSelected()) {
|
// if (enableDoubleRule.isSelected()) {
|
||||||
validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), enableDoubleRule.isSelected());
|
// validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), enableDoubleRule.isSelected());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setDoubleRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableAlphanumericRule.isSelected()) {
|
// if (enableAlphanumericRule.isSelected()) {
|
||||||
validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), enableAlphanumericRule.isSelected());
|
// validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), enableAlphanumericRule.isSelected());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setAlphanumericRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableDateRule.isSelected()) {
|
// if (enableDateRule.isSelected()) {
|
||||||
validationConfiguration.setDateRuleFor(selectedColumn.getValue(), dateformatRuleTextField.getText());
|
// validationConfiguration.setDateRuleFor(selectedColumn.getValue(), dateformatRuleTextField.getText());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setDateRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setDateRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableGroovyRule.isSelected()) {
|
// if (enableGroovyRule.isSelected()) {
|
||||||
validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), groovyRuleTextArea.getText());
|
// validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), groovyRuleTextArea.getText());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setGroovyRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableMinLengthRule.isSelected()) {
|
// if (enableMinLengthRule.isSelected()) {
|
||||||
validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), minLengthSpinner.getValue());
|
// validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), minLengthSpinner.getValue());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setMinLengthRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableMaxLengthRule.isSelected()) {
|
// if (enableMaxLengthRule.isSelected()) {
|
||||||
validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), maxLengthSpinner.getValue());
|
// validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), maxLengthSpinner.getValue());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setMaxLengthRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableRegexpRule.isSelected()) {
|
// if (enableRegexpRule.isSelected()) {
|
||||||
validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), regexpRuleTextField.getText());
|
// validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), regexpRuleTextField.getText());
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setRegexpRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (enableValueOfRule.isSelected()) {
|
// if (enableValueOfRule.isSelected()) {
|
||||||
validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), asList(valueOfRuleTextField.getText().split(", ")));
|
// validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), asList(valueOfRuleTextField.getText().split(", ")));
|
||||||
} else {
|
// } else {
|
||||||
validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), null);
|
// validationConfiguration.setValueOfRuleFor(selectedColumn.getValue(), null);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,66 +315,66 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
private void updateForm() {
|
private void updateForm() {
|
||||||
|
|
||||||
updateCheckBox(
|
// updateCheckBox(
|
||||||
validationConfiguration.getNotEmptyRuleFor(getSelectedColumn()),
|
// validationConfiguration.getNotEmptyRuleFor(getSelectedColumn()),
|
||||||
enableNotEmptyRule
|
// enableNotEmptyRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateCheckBox(
|
// updateCheckBox(
|
||||||
validationConfiguration.getIntegerRuleFor(getSelectedColumn()),
|
// validationConfiguration.getIntegerRuleFor(getSelectedColumn()),
|
||||||
enableIntegerRule
|
// enableIntegerRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateCheckBox(
|
// updateCheckBox(
|
||||||
validationConfiguration.getDoubleRuleFor(getSelectedColumn()),
|
// validationConfiguration.getDoubleRuleFor(getSelectedColumn()),
|
||||||
enableDoubleRule
|
// enableDoubleRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateCheckBox(
|
// updateCheckBox(
|
||||||
validationConfiguration.getAlphanumericRuleFor(getSelectedColumn()),
|
// validationConfiguration.getAlphanumericRuleFor(getSelectedColumn()),
|
||||||
enableAlphanumericRule
|
// enableAlphanumericRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateCheckBox(
|
// updateCheckBox(
|
||||||
validationConfiguration.getUniqueRuleFor(getSelectedColumn()),
|
// validationConfiguration.getUniqueRuleFor(getSelectedColumn()),
|
||||||
enableUniqueRule
|
// enableUniqueRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateSpinner(
|
// updateSpinner(
|
||||||
minLengthSpinner,
|
// minLengthSpinner,
|
||||||
validationConfiguration.getMinLengthRuleFor(getSelectedColumn()),
|
// validationConfiguration.getMinLengthRuleFor(getSelectedColumn()),
|
||||||
enableMinLengthRule
|
// enableMinLengthRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateSpinner(
|
// updateSpinner(
|
||||||
maxLengthSpinner,
|
// maxLengthSpinner,
|
||||||
validationConfiguration.getMaxLengthRuleFor(getSelectedColumn()),
|
// validationConfiguration.getMaxLengthRuleFor(getSelectedColumn()),
|
||||||
enableMaxLengthRule
|
// enableMaxLengthRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateTextInputControl(
|
// updateTextInputControl(
|
||||||
dateformatRuleTextField,
|
// dateformatRuleTextField,
|
||||||
validationConfiguration.getDateRuleFor(getSelectedColumn()),
|
// validationConfiguration.getDateRuleFor(getSelectedColumn()),
|
||||||
enableDateRule
|
// enableDateRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateTextInputControl(
|
// updateTextInputControl(
|
||||||
regexpRuleTextField,
|
// regexpRuleTextField,
|
||||||
validationConfiguration.getRegexpRuleFor(getSelectedColumn()),
|
// validationConfiguration.getRegexpRuleFor(getSelectedColumn()),
|
||||||
enableRegexpRule
|
// enableRegexpRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateTextInputControl(
|
// updateTextInputControl(
|
||||||
valueOfRuleTextField,
|
// valueOfRuleTextField,
|
||||||
validationConfiguration.getValueOfRuleFor(getSelectedColumn()),
|
// validationConfiguration.getValueOfRuleFor(getSelectedColumn()),
|
||||||
enableValueOfRule
|
// enableValueOfRule
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
updateCodeAreaControl(
|
// updateCodeAreaControl(
|
||||||
groovyRuleTextArea,
|
// groovyRuleTextArea,
|
||||||
validationConfiguration.getGroovyRuleFor(getSelectedColumn()),
|
// validationConfiguration.getGroovyRuleFor(getSelectedColumn()),
|
||||||
enableGroovyRule
|
// enableGroovyRule
|
||||||
);
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {
|
private void updateCheckBox(Boolean value, CheckBox ruleEnabled) {
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
package ninja.javafx.smartcsv.validation;
|
|
||||||
|
|
||||||
import static org.apache.commons.validator.GenericValidator.matchRegexp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the value is alpha numeric
|
|
||||||
*/
|
|
||||||
public class AlphaNumericValidation extends EmptyValueIsValid {
|
|
||||||
@Override
|
|
||||||
public void check(int row, String value, ValidationError error) {
|
|
||||||
if (!matchRegexp(value, "[0-9a-zA-Z]*")) {
|
|
||||||
error.add("validation.message.alphanumeric");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getType() {
|
|
||||||
return Type.ALPHANUMERIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package ninja.javafx.smartcsv.validation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abi
|
||||||
|
*/
|
||||||
|
public class DateFormatHelper {
|
||||||
|
|
||||||
|
|
||||||
|
public static String dateFormat(String format, String defaultFormat) {
|
||||||
|
|
||||||
|
if (format != null && !format.trim().isEmpty()) {
|
||||||
|
format = format.trim();
|
||||||
|
if (format.startsWith("fmt:")) {
|
||||||
|
format = format.substring(4);
|
||||||
|
format = format.replace("%Y", "yyyy");
|
||||||
|
format = format.replace("%y", "yy");
|
||||||
|
format = format.replace("%m", "MM");
|
||||||
|
format = format.replace("%d", "dd");
|
||||||
|
format = format.replace("%a", "E");
|
||||||
|
format = format.replace("%A", "EEEE");
|
||||||
|
format = format.replace("%w", "F");
|
||||||
|
format = format.replace("%b", "MMM");
|
||||||
|
format = format.replace("%B", "MMMMM");
|
||||||
|
format = format.replace("%H", "HH");
|
||||||
|
format = format.replace("%I", "hh");
|
||||||
|
format = format.replace("%p", "a");
|
||||||
|
format = format.replace("%M", "mm");
|
||||||
|
format = format.replace("%S", "ss");
|
||||||
|
format = format.replace("%z", "Z");
|
||||||
|
format = format.replace("%Z", "z");
|
||||||
|
format = format.replace("%j", "DDD");
|
||||||
|
format = format.replace("%U", "ww");
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package ninja.javafx.smartcsv.validation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author abi
|
||||||
|
*/
|
||||||
|
public class FieldConfiguration {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String title;
|
||||||
|
private String type;
|
||||||
|
private String description;
|
||||||
|
private String format;
|
||||||
|
private Object missingValue;
|
||||||
|
private Map<String, Object> constraints;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getMissingValue() {
|
||||||
|
return missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMissingValue(Object missingValue) {
|
||||||
|
this.missingValue = missingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstraints(Map<String, Object> constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
The MIT License (MIT)
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ninja.javafx.smartcsv.validation;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* header configuration for the validation
|
|
||||||
*/
|
|
||||||
public class HeaderConfiguration {
|
|
||||||
|
|
||||||
@SerializedName("list")
|
|
||||||
private String[] names ;
|
|
||||||
|
|
||||||
public String[] getNames() {
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNames(String[] names) {
|
|
||||||
this.names = names;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,149 +28,44 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validation configuration
|
* validation configuration
|
||||||
*/
|
*/
|
||||||
public class ValidationConfiguration {
|
public class ValidationConfiguration {
|
||||||
|
|
||||||
@SerializedName("headers")
|
@SerializedName("fields")
|
||||||
private HeaderConfiguration headerConfiguration = new HeaderConfiguration();
|
private FieldConfiguration[] fieldConfigurations;
|
||||||
|
|
||||||
@SerializedName("columns")
|
public FieldConfiguration[] getFieldConfigurations() {
|
||||||
private Map<String, Map<String, Object>> columnConfigurations = new HashMap<>();
|
return fieldConfigurations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFieldConfigurations(FieldConfiguration[] fieldConfigurations) {
|
||||||
|
this.fieldConfigurations = fieldConfigurations;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] headerNames() {
|
public String[] headerNames() {
|
||||||
if (noHeader()) return null;
|
if (fieldConfigurations != null) {
|
||||||
return headerConfiguration.getNames();
|
List<String> headerNames = new ArrayList<>();
|
||||||
}
|
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
|
||||||
|
headerNames.add(fieldConfiguration.getName());
|
||||||
public void setHeaderNames(String[] headerNames) {
|
|
||||||
headerConfiguration.setNames(headerNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getUniqueRuleFor(String column) {
|
|
||||||
return (Boolean)getValue(column, "unique");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getIntegerRuleFor(String column) {
|
|
||||||
return (Boolean)getValue(column, "integer");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getDoubleRuleFor(String column) {
|
|
||||||
return (Boolean)getValue(column, "double");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getNotEmptyRuleFor(String column) {
|
|
||||||
return (Boolean)getValue(column, "not empty");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMinLengthRuleFor(String column) {
|
|
||||||
return doubleToInteger((Double)getValue(column, "minlength"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMaxLengthRuleFor(String column) {
|
|
||||||
Double value = (Double)getValue(column, "maxlength");
|
|
||||||
return value != null ? doubleToInteger(value) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDateRuleFor(String column) {
|
|
||||||
return (String)getValue(column, "date");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getAlphanumericRuleFor(String column) {
|
|
||||||
return (Boolean)getValue(column, "alphanumeric");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRegexpRuleFor(String column) {
|
|
||||||
return (String)getValue(column, "regexp");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getValueOfRuleFor(String column) {
|
|
||||||
return (List<String>)getValue(column, "value of");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGroovyRuleFor(String column) {
|
|
||||||
return (String)getValue(column, "groovy");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIntegerRuleFor(String column, Boolean value) {
|
|
||||||
setValue(column, value, "integer");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDoubleRuleFor(String column, Boolean value) {
|
|
||||||
setValue(column, value, "double");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotEmptyRuleFor(String column, Boolean value) {
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxLengthRuleFor(String column, Integer value) {
|
|
||||||
setValue(column, value == null ? null : value.doubleValue(), "maxlength");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDateRuleFor(String column, String value) {
|
|
||||||
setValue(column, value, "date");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAlphanumericRuleFor(String column, Boolean value) {
|
|
||||||
setValue(column, value, "alphanumeric");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRegexpRuleFor(String column, String value) {
|
|
||||||
setValue(column, value, "regexp");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValueOfRuleFor(String column, List<String> value) {
|
|
||||||
setValue(column, value, "value of");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGroovyRuleFor(String column, String value) {
|
|
||||||
setValue(column, value, "groovy");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setValue(String column, Object value, String key) {
|
|
||||||
if (!columnConfigurations.containsKey(column)) {
|
|
||||||
columnConfigurations.put(column, new HashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == null && columnConfigurations.get(column).containsKey(key)) {
|
|
||||||
columnConfigurations.get(column).remove(key);
|
|
||||||
} else {
|
|
||||||
columnConfigurations.get(column).put(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getValue(String column, String key) {
|
|
||||||
if (columnConfigurations != null) {
|
|
||||||
Map rulesForColumn = columnConfigurations.get(column);
|
|
||||||
if (rulesForColumn != null) {
|
|
||||||
return columnConfigurations.get(column).get(key);
|
|
||||||
}
|
}
|
||||||
|
return headerNames.toArray(new String[headerNames.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean noHeader() {
|
public void setHeaderNames(String[] header) {
|
||||||
return headerConfiguration == null;
|
fieldConfigurations = new FieldConfiguration[header.length];
|
||||||
|
int i = 0;
|
||||||
|
for (String headerName: header) {
|
||||||
|
fieldConfigurations[i] = new FieldConfiguration();
|
||||||
|
fieldConfigurations[i].setName(headerName);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer doubleToInteger(Double value) {
|
|
||||||
if (value == null) return null;
|
|
||||||
return (int)Math.round(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ public class ValidationFileReader implements FileReader<ValidationConfiguration>
|
|||||||
@Override
|
@Override
|
||||||
public void read(File file) throws IOException {
|
public void read(File file) throws IOException {
|
||||||
config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
|
config = new GsonBuilder().create().fromJson(new java.io.FileReader(file), ValidationConfiguration.class);
|
||||||
|
System.out.println("brechpunkt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidationConfiguration getContent() {
|
public ValidationConfiguration getContent() {
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static ninja.javafx.smartcsv.validation.DateFormatHelper.dateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class checks all the validations defined in the
|
* This class checks all the validations defined in the
|
||||||
* Config against a given value
|
* Config against a given value
|
||||||
@@ -134,70 +136,92 @@ public class Validator {
|
|||||||
|
|
||||||
private void initColumnValidations() {
|
private void initColumnValidations() {
|
||||||
if (hasConfig()) {
|
if (hasConfig()) {
|
||||||
String[] columns = validationConfig.headerNames();
|
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
||||||
for (String column : columns) {
|
|
||||||
initializeColumnWithRules(column);
|
initializeColumnWithRules(column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeColumnWithRules(String column) {
|
private void initializeColumnWithRules(String columnName) {
|
||||||
Boolean alphaNumeric = validationConfig.getAlphanumericRuleFor(column);
|
if (hasConfig()) {
|
||||||
if (alphaNumeric != null && alphaNumeric) {
|
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
||||||
add(column, new AlphaNumericValidation());
|
if (column.getName().equals(columnName)) {
|
||||||
|
initializeColumnWithRules(column);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean doubleRule = validationConfig.getDoubleRuleFor(column);
|
}
|
||||||
if (doubleRule != null && doubleRule) {
|
|
||||||
add(column, new DoubleValidation());
|
private void initializeColumnWithRules(FieldConfiguration column) {
|
||||||
|
|
||||||
|
if (column.getType() != null) {
|
||||||
|
if (column.getType().equals("number")) {
|
||||||
|
add(column.getName(), new DoubleValidation());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.getType().equals("integer")) {
|
||||||
|
add(column.getName(), new IntegerValidation());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.getType().equals("date")) {
|
||||||
|
String format = dateFormat(column.getFormat(), "YYYY-MM-DD");
|
||||||
|
add(column.getName(), new DateValidation(format));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.getType().equals("datetime")) {
|
||||||
|
String format = dateFormat(column.getFormat(), "YYYY-MM-DDThh:mm:ssZ");
|
||||||
|
add(column.getName(), new DateValidation(format));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.getType().equals("time")) {
|
||||||
|
String format = dateFormat(column.getFormat(), "hh:mm:ss");
|
||||||
|
add(column.getName(), new DateValidation(format));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean integerRule = validationConfig.getIntegerRuleFor(column);
|
if (column.getConstraints() != null) {
|
||||||
if (integerRule != null && integerRule) {
|
Boolean notEmptyRule = (Boolean)column.getConstraints().get("required");
|
||||||
add(column, new IntegerValidation());
|
if (notEmptyRule != null && notEmptyRule) {
|
||||||
}
|
add(column.getName(), new NotEmptyValidation());
|
||||||
|
}
|
||||||
|
|
||||||
Boolean notEmptyRule = validationConfig.getNotEmptyRuleFor(column);
|
Boolean uniqueRule = (Boolean)column.getConstraints().get("unique");
|
||||||
if (notEmptyRule != null && notEmptyRule) {
|
if (uniqueRule != null && uniqueRule) {
|
||||||
add(column, new NotEmptyValidation());
|
add(column.getName(), new UniqueValidation(columnValueProvider, column.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Boolean uniqueRule = validationConfig.getUniqueRuleFor(column);
|
Integer minLength = doubleToInteger((Double)column.getConstraints().get("minLength"));
|
||||||
if (uniqueRule != null && uniqueRule) {
|
if (minLength != null) {
|
||||||
add(column, new UniqueValidation(columnValueProvider, column));
|
add(column.getName(), new MinLengthValidation(minLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
String dateRule = validationConfig.getDateRuleFor(column);
|
Integer maxLength = doubleToInteger((Double)column.getConstraints().get("maxLength"));
|
||||||
if (dateRule != null && !dateRule.trim().isEmpty()) {
|
if (maxLength != null) {
|
||||||
add(column, new DateValidation(dateRule));
|
add(column.getName(), new MaxLengthValidation(maxLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer minLength = validationConfig.getMinLengthRuleFor(column);
|
String regexp = (String)column.getConstraints().get("pattern");
|
||||||
if (minLength != null) {
|
if (regexp != null && !regexp.trim().isEmpty()) {
|
||||||
add(column, new MinLengthValidation(minLength));
|
add(column.getName(), new RegExpValidation(regexp));
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer maxLength = validationConfig.getMaxLengthRuleFor(column);
|
String groovy = (String)column.getConstraints().get("groovy");
|
||||||
if (maxLength != null) {
|
if (groovy != null && !groovy.trim().isEmpty()) {
|
||||||
add(column, new MaxLengthValidation(maxLength));
|
add(column.getName(), new GroovyValidation(groovy));
|
||||||
}
|
}
|
||||||
|
|
||||||
String regexp = validationConfig.getRegexpRuleFor(column);
|
List<String> valueOfRule = (List<String>)column.getConstraints().get("enum");
|
||||||
if (regexp != null && !regexp.trim().isEmpty()) {
|
if (valueOfRule != null && !valueOfRule.isEmpty()) {
|
||||||
add(column, new RegExpValidation(regexp));
|
add(column.getName(), new ValueOfValidation(valueOfRule));
|
||||||
}
|
}
|
||||||
|
|
||||||
String groovy = validationConfig.getGroovyRuleFor(column);
|
|
||||||
if (groovy != null && !groovy.trim().isEmpty()) {
|
|
||||||
add(column, new GroovyValidation(groovy));
|
|
||||||
}
|
|
||||||
List<String> valueOfRule = validationConfig.getValueOfRuleFor(column);
|
|
||||||
if (valueOfRule != null && !valueOfRule.isEmpty()) {
|
|
||||||
add(column, new ValueOfValidation(valueOfRule));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ValidationError isHeaderValid(String[] headerNames) {
|
public ValidationError isHeaderValid(String[] headerNames) {
|
||||||
ValidationError result = null;
|
ValidationError result = null;
|
||||||
if (validationConfig != null) {
|
if (validationConfig != null) {
|
||||||
@@ -227,4 +251,9 @@ public class Validator {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Integer doubleToInteger(Double value) {
|
||||||
|
if (value == null) return null;
|
||||||
|
return (int)Math.round(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user