read constraints into an object instead of some map structure and change form init of validation editor

This commit is contained in:
2016-09-05 22:49:49 +02:00
committed by Andreas Billmann
parent 04a54da798
commit 5694273c51
5 changed files with 171 additions and 77 deletions

View File

@@ -0,0 +1,69 @@
package ninja.javafx.smartcsv.validation;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Created by PC on 04.09.2016.
*/
public class ConstraintsConfiguration {
private Boolean required;
private Boolean unique;
private Integer minLength;
private Integer maxLength;
private String pattern;
@SerializedName("enum")
private List<String> enumeration;
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public Boolean getUnique() {
return unique;
}
public void setUnique(Boolean unique) {
this.unique = unique;
}
public Integer getMinLength() {
return minLength;
}
public void setMinLength(Integer minLength) {
this.minLength = minLength;
}
public Integer getMaxLength() {
return maxLength;
}
public void setMaxLength(Integer maxLength) {
this.maxLength = maxLength;
}
public String getPattern() {
return pattern;
}
public void setPattern(String pattern) {
this.pattern = pattern;
}
public List<String> getEnumeration() {
return enumeration;
}
public void setEnumeration(List<String> enumeration) {
this.enumeration = enumeration;
}
}

View File

@@ -2,9 +2,6 @@ package ninja.javafx.smartcsv.validation;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.Map;
/**
* @author abi
*/
@@ -25,7 +22,9 @@ public class FieldConfiguration {
private String description;
private String format;
private Object missingValue;
private Map<String, Object> constraints;
private ConstraintsConfiguration constraints;
private String groovy;
public String getName() {
return name;
@@ -75,11 +74,20 @@ public class FieldConfiguration {
this.missingValue = missingValue;
}
public Map<String, Object> getConstraints() {
public ConstraintsConfiguration getConstraints() {
return constraints;
}
public void setConstraints(Map<String, Object> constraints) {
public void setConstraints(ConstraintsConfiguration constraints) {
this.constraints = constraints;
}
public String getGroovy() {
return groovy;
}
public void setGroovy(String groovy) {
this.groovy = groovy;
}
}

View File

@@ -182,38 +182,41 @@ public class Validator {
}
}
if (column.getConstraints() != null) {
Boolean notEmptyRule = (Boolean)column.getConstraints().get("required");
String groovy = column.getGroovy();
if (groovy != null && !groovy.trim().isEmpty()) {
add(column.getName(), new GroovyValidation(groovy));
}
ConstraintsConfiguration constraints = column.getConstraints();
if (constraints != null) {
Boolean notEmptyRule = constraints.getRequired();
if (notEmptyRule != null && notEmptyRule) {
add(column.getName(), new NotEmptyValidation());
}
Boolean uniqueRule = (Boolean)column.getConstraints().get("unique");
Boolean uniqueRule = constraints.getUnique();
if (uniqueRule != null && uniqueRule) {
add(column.getName(), new UniqueValidation(columnValueProvider, column.getName()));
}
Integer minLength = doubleToInteger((Double)column.getConstraints().get("minLength"));
Integer minLength = constraints.getMinLength();
if (minLength != null) {
add(column.getName(), new MinLengthValidation(minLength));
}
Integer maxLength = doubleToInteger((Double)column.getConstraints().get("maxLength"));
Integer maxLength = constraints.getMaxLength();
if (maxLength != null) {
add(column.getName(), new MaxLengthValidation(maxLength));
}
String regexp = (String)column.getConstraints().get("pattern");
String regexp = constraints.getPattern();
if (regexp != null && !regexp.trim().isEmpty()) {
add(column.getName(), new RegExpValidation(regexp));
}
String groovy = (String)column.getConstraints().get("groovy");
if (groovy != null && !groovy.trim().isEmpty()) {
add(column.getName(), new GroovyValidation(groovy));
}
List<String> valueOfRule = (List<String>)column.getConstraints().get("enum");
List<String> valueOfRule = constraints.getEnumeration();
if (valueOfRule != null && !valueOfRule.isEmpty()) {
add(column.getName(), new ValueOfValidation(valueOfRule));
}