reorganize validation package

This commit is contained in:
2016-09-12 04:48:22 +02:00
committed by Andreas Billmann
parent 7723906935
commit 4002219dfe
27 changed files with 274 additions and 167 deletions

View File

@@ -0,0 +1,69 @@
package ninja.javafx.smartcsv.validation.configuration;
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

@@ -0,0 +1,142 @@
package ninja.javafx.smartcsv.validation.configuration;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author abi
*/
public class FieldConfiguration {
public enum Type {
@SerializedName("string") STRING,
@SerializedName("integer") INTEGER,
@SerializedName("number") NUMBER,
@SerializedName("date") DATE,
@SerializedName("datetime") DATETIME,
@SerializedName("time") TIME
// TODO: currently not supported
// @SerializedName("object") OBJECT,
// @SerializedName("array") ARRAY,
// @SerializedName("duration") DURATION,
// @SerializedName("geopoint") GEOPOINT,
// @SerializedName("geojson") GEOJSON
}
public enum StringFormat {
@SerializedName("default") DEFAULT,
@SerializedName("email") EMAIL,
@SerializedName("uri") URI,
@SerializedName("binary") BINARY,
@SerializedName("uuid") UUID
}
public static List<String> getStringFormats() {
return Stream.of(StringFormat.values())
.map(StringFormat::name)
.collect(Collectors.toList());
}
public enum NumberFormat {
@SerializedName("decimalChar") DECIMAL_CHAR,
@SerializedName("groupChar") GROUP_CHAR,
@SerializedName("currency") CURRENCY
}
public static List<String> getNumberFormats() {
return Stream.of(NumberFormat.values())
.map(NumberFormat::name)
.collect(Collectors.toList());
}
public enum DateFormat {
@SerializedName("default") DEFAULT,
@SerializedName("any") ANY,
@SerializedName("fmtPattern") FMT_PATTERN
}
public static List<String> getDateFormats() {
return Stream.of(DateFormat.values())
.map(DateFormat::name)
.collect(Collectors.toList());
}
private String name;
private String title;
private Type type;
private String description;
private String format;
private Object missingValue;
private ConstraintsConfiguration constraints;
private String groovy;
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 Type getType() {
return type;
}
public void setType(Type 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 ConstraintsConfiguration getConstraints() {
return constraints;
}
public void setConstraints(ConstraintsConfiguration constraints) {
this.constraints = constraints;
}
public String getGroovy() {
return groovy;
}
public void setGroovy(String groovy) {
this.groovy = groovy;
}
}

View File

@@ -0,0 +1,80 @@
/*
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.configuration;
import com.google.gson.annotations.SerializedName;
import java.util.ArrayList;
import java.util.List;
/**
* validation configuration
*/
public class ValidationConfiguration {
@SerializedName("fields")
private FieldConfiguration[] fieldConfigurations;
public FieldConfiguration[] getFieldConfigurations() {
return fieldConfigurations;
}
public void setFieldConfigurations(FieldConfiguration[] fieldConfigurations) {
this.fieldConfigurations = fieldConfigurations;
}
public FieldConfiguration getFieldConfiguration(String column) {
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
if (fieldConfiguration.getName().equals(column)) {
return fieldConfiguration;
}
}
return null;
}
public String[] headerNames() {
if (fieldConfigurations != null) {
List<String> headerNames = new ArrayList<>();
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
headerNames.add(fieldConfiguration.getName());
}
return headerNames.toArray(new String[headerNames.size()]);
}
return null;
}
public void setHeaderNames(String[] header) {
fieldConfigurations = new FieldConfiguration[header.length];
int i = 0;
for (String headerName: header) {
fieldConfigurations[i] = new FieldConfiguration();
fieldConfigurations[i].setName(headerName);
i++;
}
}
}