mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
the editor can handle the support subset of JSON Table Schema
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
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.fx.validation;
|
||||||
|
|
||||||
|
import javafx.scene.control.ListCell;
|
||||||
|
import javafx.scene.control.ListView;
|
||||||
|
import javafx.util.Callback;
|
||||||
|
import ninja.javafx.smartcsv.validation.configuration.StringFormat;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cell factory for string formats
|
||||||
|
*/
|
||||||
|
public class StringFormatEditorCellFactory implements Callback<ListView<StringFormat>, ListCell<StringFormat>> {
|
||||||
|
|
||||||
|
private ResourceBundle resourceBundle;
|
||||||
|
|
||||||
|
public StringFormatEditorCellFactory(ResourceBundle resourceBundle) {
|
||||||
|
this.resourceBundle = resourceBundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListCell<StringFormat> call(ListView<StringFormat> param) {
|
||||||
|
return new ListCell<StringFormat>(){
|
||||||
|
@Override
|
||||||
|
protected void updateItem(StringFormat item, boolean empty) {
|
||||||
|
super.updateItem(item, empty);
|
||||||
|
if (item == null || empty) {
|
||||||
|
setGraphic(null);
|
||||||
|
} else {
|
||||||
|
setText(resourceBundle.getString("format.type."+item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
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.fx.validation;
|
||||||
|
|
||||||
|
import javafx.util.StringConverter;
|
||||||
|
import ninja.javafx.smartcsv.validation.configuration.StringFormat;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converter for string formats
|
||||||
|
*/
|
||||||
|
public class StringFormatStringConverter extends StringConverter<StringFormat> {
|
||||||
|
|
||||||
|
private ResourceBundle resourceBundle;
|
||||||
|
|
||||||
|
public StringFormatStringConverter(ResourceBundle resourceBundle) {
|
||||||
|
this.resourceBundle = resourceBundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(StringFormat item) {
|
||||||
|
return resourceBundle.getString("format.type."+item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StringFormat fromString(String string) {
|
||||||
|
return StringFormat.fromExternalValue(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,9 +32,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
|
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
|
||||||
import ninja.javafx.smartcsv.fx.FXMLController;
|
import ninja.javafx.smartcsv.fx.FXMLController;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ConstraintsConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.*;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
|
||||||
import org.fxmisc.richtext.CodeArea;
|
import org.fxmisc.richtext.CodeArea;
|
||||||
import org.fxmisc.richtext.LineNumberFactory;
|
import org.fxmisc.richtext.LineNumberFactory;
|
||||||
import org.fxmisc.richtext.StyleSpans;
|
import org.fxmisc.richtext.StyleSpans;
|
||||||
@@ -54,8 +52,7 @@ import static java.lang.Boolean.FALSE;
|
|||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
import static javafx.beans.binding.Bindings.when;
|
import static javafx.beans.binding.Bindings.when;
|
||||||
import static javafx.collections.FXCollections.observableList;
|
import static ninja.javafx.smartcsv.validation.configuration.Type.STRING;
|
||||||
import static ninja.javafx.smartcsv.validation.configuration.FieldConfiguration.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* controller for editing column validations
|
* controller for editing column validations
|
||||||
@@ -103,10 +100,10 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<FieldConfiguration.Type> typeComboBox;
|
private ComboBox<Type> typeComboBox;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> formatComboBox;
|
private ComboBox<StringFormat> formatComboBox;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField formatTextField;
|
private TextField formatTextField;
|
||||||
@@ -156,7 +153,7 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
initTypeAndFormatInput();
|
initTypeAndFormatInput(resources);
|
||||||
initMinMaxSpinner();
|
initMinMaxSpinner();
|
||||||
initSpinner(minLengthSpinner, enableMinLengthRule);
|
initSpinner(minLengthSpinner, enableMinLengthRule);
|
||||||
initSpinner(maxLengthSpinner, enableMaxLengthRule);
|
initSpinner(maxLengthSpinner, enableMaxLengthRule);
|
||||||
@@ -181,88 +178,51 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
this.validationConfiguration = validationConfiguration;
|
this.validationConfiguration = validationConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTypeAndFormatInput() {
|
private void initTypeAndFormatInput(ResourceBundle resources) {
|
||||||
typeComboBox.getItems().addAll(Type.STRING,
|
typeComboBox.getItems().addAll(STRING,
|
||||||
Type.INTEGER,
|
Type.INTEGER,
|
||||||
Type.NUMBER,
|
Type.NUMBER,
|
||||||
Type.DATE,
|
Type.DATE,
|
||||||
Type.DATETIME,
|
Type.DATETIME,
|
||||||
Type.TIME);
|
Type.TIME);
|
||||||
formatComboBox.setDisable(true);
|
formatComboBox.setCellFactory(new StringFormatEditorCellFactory(resources));
|
||||||
formatTextField.setDisable(true);
|
formatComboBox.setConverter(new StringFormatStringConverter(resources));
|
||||||
typeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> clearFormatComboBox());
|
formatComboBox.getItems().addAll(
|
||||||
formatComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> clearFormatTextField());
|
StringFormat.DEFAULT,
|
||||||
|
StringFormat.EMAIL,
|
||||||
|
StringFormat.URI,
|
||||||
|
StringFormat.BINARY,
|
||||||
|
StringFormat.UUID
|
||||||
|
);
|
||||||
|
typeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> changeFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFormatTextField() {
|
private void updateFormatTextField() {
|
||||||
FieldConfiguration config = getCurrentFieldConfig();
|
switch (typeComboBox.getValue()) {
|
||||||
switch (config.getType()) {
|
|
||||||
case DATE:
|
case DATE:
|
||||||
case DATETIME:
|
case DATETIME:
|
||||||
case TIME:
|
case TIME:
|
||||||
if (config.getFormat().startsWith("fmt:")) {
|
formatTextField.setVisible(true);
|
||||||
formatTextField.setText(config.getFormat().substring(4));
|
formatTextField.setText(getCurrentFieldConfig().getFormat());
|
||||||
} else {
|
|
||||||
formatTextField.setText(config.getFormat());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
formatTextField.setVisible(false);
|
||||||
formatTextField.setText(null);
|
formatTextField.setText(null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearFormatTextField() {
|
private void updateFormatComboBox() {
|
||||||
FieldConfiguration config = getCurrentFieldConfig();
|
switch (typeComboBox.getValue()) {
|
||||||
formatTextField.setText(null);
|
|
||||||
switch (config.getType()) {
|
|
||||||
case DATE:
|
|
||||||
case DATETIME:
|
|
||||||
case TIME:
|
|
||||||
formatTextField.setDisable(false);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
formatTextField.setDisable(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void clearFormatComboBox() {
|
|
||||||
formatTextField.setText(null);
|
|
||||||
formatTextField.setDisable(true);
|
|
||||||
changeFormat();
|
|
||||||
|
|
||||||
if (!formatComboBox.isDisable()) {
|
|
||||||
formatComboBox.getSelectionModel().selectFirst();
|
|
||||||
} else {
|
|
||||||
formatComboBox.getSelectionModel().clearSelection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateFormInput() {
|
|
||||||
FieldConfiguration config = getCurrentFieldConfig();
|
|
||||||
if (!formatComboBox.isDisable()) {
|
|
||||||
if (config.getFormat() == null) {
|
|
||||||
formatComboBox.getSelectionModel().selectFirst();
|
|
||||||
} else {
|
|
||||||
switch (config.getType()) {
|
|
||||||
case STRING:
|
case STRING:
|
||||||
case NUMBER:
|
formatComboBox.setVisible(true);
|
||||||
formatComboBox.getSelectionModel().select(config.getFormat());
|
formatComboBox.getSelectionModel().select(StringFormat.fromExternalValue(getCurrentFieldConfig().getFormat()));
|
||||||
break;
|
break;
|
||||||
case DATE:
|
default:
|
||||||
case DATETIME:
|
formatComboBox.setVisible(false);
|
||||||
case TIME:
|
|
||||||
if (config.getFormat().startsWith("fmt:")) {
|
|
||||||
formatComboBox.getSelectionModel().select(DateFormat.FMT_PATTERN.toString());
|
|
||||||
} else {
|
|
||||||
formatComboBox.getSelectionModel().select(DateFormat.ANY.toString());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initMinMaxSpinner() {
|
private void initMinMaxSpinner() {
|
||||||
IntegerSpinnerValueFactory minValueFactory = new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0);
|
IntegerSpinnerValueFactory minValueFactory = new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0);
|
||||||
@@ -283,52 +243,61 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
|
|
||||||
private void changeFormat() {
|
private void changeFormat() {
|
||||||
formatComboBox.getItems().clear();
|
|
||||||
formatComboBox.getSelectionModel().clearSelection();
|
|
||||||
switch (typeComboBox.getValue()) {
|
switch (typeComboBox.getValue()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
updateFormatComboBox(getStringFormats());
|
updateFormatComboBox();
|
||||||
break;
|
break;
|
||||||
case DATE:
|
case DATE:
|
||||||
case DATETIME:
|
case DATETIME:
|
||||||
case TIME:
|
case TIME:
|
||||||
updateFormatComboBox(getDateFormats());
|
updateFormatTextField();
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
case NUMBER:
|
case NUMBER:
|
||||||
default:
|
default:
|
||||||
// format: no options
|
// format: no options
|
||||||
formatComboBox.setDisable(true);
|
formatComboBox.setVisible(false);
|
||||||
formatTextField.setDisable(true);
|
formatTextField.setVisible(false);
|
||||||
formatTextField.setText(null);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateFormInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFormatComboBox(List<String> values) {
|
|
||||||
formatComboBox.getItems().setAll(observableList(values));
|
|
||||||
formatComboBox.setEditable(false);
|
|
||||||
formatComboBox.setDisable(false);
|
|
||||||
formatTextField.setDisable(true);
|
|
||||||
formatTextField.setText(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void updateConfiguration() {
|
public void updateConfiguration() {
|
||||||
|
|
||||||
FieldConfiguration config = getCurrentFieldConfig();
|
Field config = getCurrentFieldConfig();
|
||||||
config.setType(typeComboBox.getValue());
|
config.setType(typeComboBox.getValue());
|
||||||
|
|
||||||
|
switch (typeComboBox.getValue()) {
|
||||||
|
case STRING:
|
||||||
|
config.setFormat(formatComboBox.getValue().getExternalValue());
|
||||||
|
break;
|
||||||
|
case DATE:
|
||||||
|
case DATETIME:
|
||||||
|
case TIME:
|
||||||
|
if (formatTextField.getText().trim().isEmpty()) {
|
||||||
|
config.setFormat(null);
|
||||||
|
} else {
|
||||||
|
// TODO: validate input
|
||||||
|
config.setFormat(formatTextField.getText());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case INTEGER:
|
||||||
|
case NUMBER:
|
||||||
|
default:
|
||||||
|
// format: no options
|
||||||
|
config.setFormat(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (enableGroovyRule.isSelected()) {
|
if (enableGroovyRule.isSelected()) {
|
||||||
config.setGroovy(groovyRuleTextArea.getText());
|
config.setGroovy(groovyRuleTextArea.getText());
|
||||||
} else {
|
} else {
|
||||||
config.setGroovy(null);
|
config.setGroovy(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstraintsConfiguration constraints = config.getConstraints();
|
Constraints constraints = config.getConstraints();
|
||||||
if (constraints == null) {
|
if (constraints == null) {
|
||||||
constraints = new ConstraintsConfiguration();
|
constraints = new Constraints();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enableNotEmptyRule.isSelected()) {
|
if (enableNotEmptyRule.isSelected()) {
|
||||||
@@ -369,7 +338,7 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldConfiguration getCurrentFieldConfig() {
|
private Field getCurrentFieldConfig() {
|
||||||
return validationConfiguration.getFieldConfiguration(getSelectedColumn());
|
return validationConfiguration.getFieldConfiguration(getSelectedColumn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,15 +354,15 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
|
|
||||||
public void updateForm() {
|
public void updateForm() {
|
||||||
|
|
||||||
FieldConfiguration config = getCurrentFieldConfig();
|
Field config = getCurrentFieldConfig();
|
||||||
|
|
||||||
if (config.getType() != null) {
|
if (config.getType() != null) {
|
||||||
typeComboBox.setValue(config.getType());
|
typeComboBox.setValue(config.getType());
|
||||||
} else {
|
} else {
|
||||||
typeComboBox.setValue(FieldConfiguration.Type.STRING);
|
typeComboBox.setValue(STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFormInput();
|
updateFormatComboBox();
|
||||||
updateFormatTextField();
|
updateFormatTextField();
|
||||||
|
|
||||||
updateCodeAreaControl(
|
updateCodeAreaControl(
|
||||||
@@ -402,7 +371,7 @@ public class ValidationEditorController extends FXMLController {
|
|||||||
enableGroovyRule
|
enableGroovyRule
|
||||||
);
|
);
|
||||||
|
|
||||||
ConstraintsConfiguration constraints = config.getConstraints();
|
Constraints constraints = config.getConstraints();
|
||||||
updateCheckBox(constraints != null ? constraints.getRequired() : FALSE, enableNotEmptyRule);
|
updateCheckBox(constraints != null ? constraints.getRequired() : FALSE, enableNotEmptyRule);
|
||||||
updateCheckBox(constraints != null ? constraints.getUnique() : FALSE, enableUniqueRule);
|
updateCheckBox(constraints != null ? constraints.getUnique() : FALSE, enableUniqueRule);
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import ninja.javafx.smartcsv.FileReader;
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.Field;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class loads the constraints as json config
|
* This class loads the constraints as json config
|
||||||
*/
|
*/
|
||||||
@@ -48,23 +50,23 @@ public class ValidationFileReader implements FileReader<ValidationConfiguration>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaults() {
|
private void setDefaults() {
|
||||||
for (FieldConfiguration fieldConfiguration: config.getFieldConfigurations()) {
|
for (Field field : config.getFields()) {
|
||||||
if (fieldConfiguration.getType() == null) {
|
if (field.getType() == null) {
|
||||||
fieldConfiguration.setType(FieldConfiguration.Type.STRING);
|
field.setType(STRING);
|
||||||
}
|
}
|
||||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATE) {
|
if (field.getType() == DATE) {
|
||||||
if (fieldConfiguration.getFormat() == null) {
|
if (field.getFormat() == null) {
|
||||||
fieldConfiguration.setFormat("yyyy-MM-dd");
|
field.setFormat("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATETIME) {
|
if (field.getType() == DATETIME) {
|
||||||
if (fieldConfiguration.getFormat() == null) {
|
if (field.getFormat() == null) {
|
||||||
fieldConfiguration.setFormat("yyyy-MM-ddThh:mm:ssZ");
|
field.setFormat("yyyy-MM-ddThh:mm:ssZ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.TIME) {
|
if (field.getType() == TIME) {
|
||||||
if (fieldConfiguration.getFormat() == null) {
|
if (field.getFormat() == null) {
|
||||||
fieldConfiguration.setFormat("hh:mm:ss");
|
field.setFormat("hh:mm:ss");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ package ninja.javafx.smartcsv.validation;
|
|||||||
|
|
||||||
import ninja.javafx.smartcsv.fx.table.model.ColumnValueProvider;
|
import ninja.javafx.smartcsv.fx.table.model.ColumnValueProvider;
|
||||||
import ninja.javafx.smartcsv.validation.checker.*;
|
import ninja.javafx.smartcsv.validation.checker.*;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ConstraintsConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.Constraints;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.Field;
|
||||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -37,6 +37,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.dateFormat;
|
import static ninja.javafx.smartcsv.validation.ValidationFormatHelper.dateFormat;
|
||||||
|
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class checks all the validations defined in the
|
* This class checks all the validations defined in the
|
||||||
@@ -140,7 +141,7 @@ public class Validator {
|
|||||||
|
|
||||||
private void initColumnValidations() {
|
private void initColumnValidations() {
|
||||||
if (hasConfig()) {
|
if (hasConfig()) {
|
||||||
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
for (Field column : validationConfig.getFields()) {
|
||||||
initializeColumnWithRules(column);
|
initializeColumnWithRules(column);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +149,7 @@ public class Validator {
|
|||||||
|
|
||||||
private void initializeColumnWithRules(String columnName) {
|
private void initializeColumnWithRules(String columnName) {
|
||||||
if (hasConfig()) {
|
if (hasConfig()) {
|
||||||
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
for (Field column : validationConfig.getFields()) {
|
||||||
if (column.getName().equals(columnName)) {
|
if (column.getName().equals(columnName)) {
|
||||||
initializeColumnWithRules(column);
|
initializeColumnWithRules(column);
|
||||||
break;
|
break;
|
||||||
@@ -158,28 +159,28 @@ public class Validator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeColumnWithRules(FieldConfiguration column) {
|
private void initializeColumnWithRules(Field column) {
|
||||||
|
|
||||||
if (column.getType() != null) {
|
if (column.getType() != null) {
|
||||||
if (column.getType() == FieldConfiguration.Type.NUMBER) {
|
if (column.getType() == NUMBER) {
|
||||||
add(column.getName(), new DoubleValidation());
|
add(column.getName(), new DoubleValidation());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.getType() == FieldConfiguration.Type.INTEGER) {
|
if (column.getType() == INTEGER) {
|
||||||
add(column.getName(), new IntegerValidation());
|
add(column.getName(), new IntegerValidation());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.getType() == FieldConfiguration.Type.DATE) {
|
if (column.getType() == DATE) {
|
||||||
String format = dateFormat(column.getFormat(), "YYYY-MM-DD");
|
String format = dateFormat(column.getFormat(), "YYYY-MM-DD");
|
||||||
add(column.getName(), new DateValidation(format));
|
add(column.getName(), new DateValidation(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.getType() == FieldConfiguration.Type.DATETIME) {
|
if (column.getType() == DATETIME) {
|
||||||
String format = dateFormat(column.getFormat(), "YYYY-MM-DDThh:mm:ssZ");
|
String format = dateFormat(column.getFormat(), "YYYY-MM-DDThh:mm:ssZ");
|
||||||
add(column.getName(), new DateValidation(format));
|
add(column.getName(), new DateValidation(format));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.getType() == FieldConfiguration.Type.TIME) {
|
if (column.getType() == TIME) {
|
||||||
String format = dateFormat(column.getFormat(), "hh:mm:ss");
|
String format = dateFormat(column.getFormat(), "hh:mm:ss");
|
||||||
add(column.getName(), new DateValidation(format));
|
add(column.getName(), new DateValidation(format));
|
||||||
}
|
}
|
||||||
@@ -190,7 +191,7 @@ public class Validator {
|
|||||||
add(column.getName(), new GroovyValidation(groovy));
|
add(column.getName(), new GroovyValidation(groovy));
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstraintsConfiguration constraints = column.getConstraints();
|
Constraints constraints = column.getConstraints();
|
||||||
if (constraints != null) {
|
if (constraints != null) {
|
||||||
Boolean notEmptyRule = constraints.getRequired();
|
Boolean notEmptyRule = constraints.getRequired();
|
||||||
if (notEmptyRule != null && notEmptyRule) {
|
if (notEmptyRule != null && notEmptyRule) {
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
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.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* contraints defined in JSON Table Schema
|
||||||
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
||||||
|
*/
|
||||||
|
public class Constraints {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this class represents a field in the configuration
|
||||||
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
||||||
|
*/
|
||||||
|
public class Field {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String title;
|
||||||
|
private Type type;
|
||||||
|
private String description;
|
||||||
|
private String format;
|
||||||
|
private Object missingValue;
|
||||||
|
private Constraints 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 Constraints getConstraints() {
|
||||||
|
return constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstraints(Constraints constraints) {
|
||||||
|
this.constraints = constraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroovy() {
|
||||||
|
return groovy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroovy(String groovy) {
|
||||||
|
this.groovy = groovy;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration for format values for type string in JSON Table Schema
|
||||||
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
||||||
|
*/
|
||||||
|
public enum StringFormat {
|
||||||
|
DEFAULT(null),
|
||||||
|
EMAIL("email"),
|
||||||
|
URI("uri"),
|
||||||
|
BINARY("binary"),
|
||||||
|
UUID("uuid");
|
||||||
|
|
||||||
|
private String externalValue;
|
||||||
|
|
||||||
|
StringFormat(String externalValue) {
|
||||||
|
this.externalValue = externalValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExternalValue() {
|
||||||
|
return externalValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringFormat fromExternalValue(String externalValue) {
|
||||||
|
for (StringFormat value: StringFormat.values()) {
|
||||||
|
if (value.name().equals(externalValue)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types of JSON Table Schema
|
||||||
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -32,35 +32,36 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* validation configuration
|
* Configuration based on JSON Table Schema
|
||||||
|
* @see <a href="http://specs.frictionlessdata.io/json-table-schema/">JSON Table Schema</a>
|
||||||
*/
|
*/
|
||||||
public class ValidationConfiguration {
|
public class ValidationConfiguration {
|
||||||
|
|
||||||
@SerializedName("fields")
|
@SerializedName("fields")
|
||||||
private FieldConfiguration[] fieldConfigurations;
|
private Field[] fields;
|
||||||
|
|
||||||
public FieldConfiguration[] getFieldConfigurations() {
|
public Field[] getFields() {
|
||||||
return fieldConfigurations;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFieldConfigurations(FieldConfiguration[] fieldConfigurations) {
|
public void setFields(Field[] fields) {
|
||||||
this.fieldConfigurations = fieldConfigurations;
|
this.fields = fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldConfiguration getFieldConfiguration(String column) {
|
public Field getFieldConfiguration(String column) {
|
||||||
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
|
for (Field field : fields) {
|
||||||
if (fieldConfiguration.getName().equals(column)) {
|
if (field.getName().equals(column)) {
|
||||||
return fieldConfiguration;
|
return field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] headerNames() {
|
public String[] headerNames() {
|
||||||
if (fieldConfigurations != null) {
|
if (fields != null) {
|
||||||
List<String> headerNames = new ArrayList<>();
|
List<String> headerNames = new ArrayList<>();
|
||||||
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
|
for (Field field : fields) {
|
||||||
headerNames.add(fieldConfiguration.getName());
|
headerNames.add(field.getName());
|
||||||
}
|
}
|
||||||
return headerNames.toArray(new String[headerNames.size()]);
|
return headerNames.toArray(new String[headerNames.size()]);
|
||||||
}
|
}
|
||||||
@@ -69,11 +70,11 @@ public class ValidationConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setHeaderNames(String[] header) {
|
public void setHeaderNames(String[] header) {
|
||||||
fieldConfigurations = new FieldConfiguration[header.length];
|
fields = new Field[header.length];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (String headerName: header) {
|
for (String headerName: header) {
|
||||||
fieldConfigurations[i] = new FieldConfiguration();
|
fields[i] = new Field();
|
||||||
fieldConfigurations[i].setName(headerName);
|
fields[i].setName(headerName);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,3 +87,9 @@ log.header.message = {0} has {1} errors
|
|||||||
log.message = row {0} column {1} : {2}
|
log.message = row {0} column {1} : {2}
|
||||||
|
|
||||||
column = column
|
column = column
|
||||||
|
|
||||||
|
format.type.DEFAULT = default
|
||||||
|
format.type.EMAIL = email
|
||||||
|
format.type.URI = uri
|
||||||
|
format.type.BINARY = binary
|
||||||
|
format.type.UUID = uuid
|
||||||
|
|||||||
@@ -97,3 +97,9 @@ log.header.message = {0} hat {1} Fehler
|
|||||||
log.message = Zeile {0} Spalte {1} : {2}
|
log.message = Zeile {0} Spalte {1} : {2}
|
||||||
|
|
||||||
column = Spalte
|
column = Spalte
|
||||||
|
|
||||||
|
format.type.DEFAULT = Standard
|
||||||
|
format.type.EMAIL = Email
|
||||||
|
format.type.URI = URI
|
||||||
|
format.type.BINARY = Binär
|
||||||
|
format.type.UUID = UUID
|
||||||
|
|||||||
@@ -35,8 +35,8 @@
|
|||||||
<Label text="%validation.rule.type" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
|
<Label text="%validation.rule.type" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
|
||||||
<Label text="%validation.rule.format" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
|
<Label text="%validation.rule.format" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
|
||||||
<ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
|
<ComboBox fx:id="typeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.hgrow="ALWAYS" />
|
||||||
<ComboBox fx:id="formatComboBox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
<ComboBox fx:id="formatComboBox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" visible="false" />
|
||||||
<TextField fx:id="formatTextField" GridPane.columnIndex="2" GridPane.columnSpan="2" GridPane.rowIndex="1" />
|
<TextField fx:id="formatTextField" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" visible="false" />
|
||||||
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" text="%validation.rule.label.not_empty" GridPane.rowIndex="3" />
|
<CheckBox fx:id="enableNotEmptyRule" mnemonicParsing="false" text="%validation.rule.label.not_empty" GridPane.rowIndex="3" />
|
||||||
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" text="%validation.rule.label.unique" GridPane.columnIndex="2" GridPane.rowIndex="3" />
|
<CheckBox fx:id="enableUniqueRule" mnemonicParsing="false" text="%validation.rule.label.unique" GridPane.columnIndex="2" GridPane.rowIndex="3" />
|
||||||
<CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" text="%validation.rule.label.minlength" GridPane.rowIndex="4" />
|
<CheckBox fx:id="enableMinLengthRule" mnemonicParsing="false" text="%validation.rule.label.minlength" GridPane.rowIndex="4" />
|
||||||
|
|||||||
Reference in New Issue
Block a user