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.SpinnerValueFactory.IntegerSpinnerValueFactory;
|
||||
import ninja.javafx.smartcsv.fx.FXMLController;
|
||||
import ninja.javafx.smartcsv.validation.configuration.ConstraintsConfiguration;
|
||||
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||
import ninja.javafx.smartcsv.validation.configuration.*;
|
||||
import org.fxmisc.richtext.CodeArea;
|
||||
import org.fxmisc.richtext.LineNumberFactory;
|
||||
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.stream.Collectors.joining;
|
||||
import static javafx.beans.binding.Bindings.when;
|
||||
import static javafx.collections.FXCollections.observableList;
|
||||
import static ninja.javafx.smartcsv.validation.configuration.FieldConfiguration.*;
|
||||
import static ninja.javafx.smartcsv.validation.configuration.Type.STRING;
|
||||
|
||||
/**
|
||||
* controller for editing column validations
|
||||
@@ -103,10 +100,10 @@ public class ValidationEditorController extends FXMLController {
|
||||
);
|
||||
|
||||
@FXML
|
||||
private ComboBox<FieldConfiguration.Type> typeComboBox;
|
||||
private ComboBox<Type> typeComboBox;
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> formatComboBox;
|
||||
private ComboBox<StringFormat> formatComboBox;
|
||||
|
||||
@FXML
|
||||
private TextField formatTextField;
|
||||
@@ -156,7 +153,7 @@ public class ValidationEditorController extends FXMLController {
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
initTypeAndFormatInput();
|
||||
initTypeAndFormatInput(resources);
|
||||
initMinMaxSpinner();
|
||||
initSpinner(minLengthSpinner, enableMinLengthRule);
|
||||
initSpinner(maxLengthSpinner, enableMaxLengthRule);
|
||||
@@ -181,89 +178,52 @@ public class ValidationEditorController extends FXMLController {
|
||||
this.validationConfiguration = validationConfiguration;
|
||||
}
|
||||
|
||||
private void initTypeAndFormatInput() {
|
||||
typeComboBox.getItems().addAll(Type.STRING,
|
||||
private void initTypeAndFormatInput(ResourceBundle resources) {
|
||||
typeComboBox.getItems().addAll(STRING,
|
||||
Type.INTEGER,
|
||||
Type.NUMBER,
|
||||
Type.DATE,
|
||||
Type.DATETIME,
|
||||
Type.TIME);
|
||||
formatComboBox.setDisable(true);
|
||||
formatTextField.setDisable(true);
|
||||
typeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> clearFormatComboBox());
|
||||
formatComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> clearFormatTextField());
|
||||
formatComboBox.setCellFactory(new StringFormatEditorCellFactory(resources));
|
||||
formatComboBox.setConverter(new StringFormatStringConverter(resources));
|
||||
formatComboBox.getItems().addAll(
|
||||
StringFormat.DEFAULT,
|
||||
StringFormat.EMAIL,
|
||||
StringFormat.URI,
|
||||
StringFormat.BINARY,
|
||||
StringFormat.UUID
|
||||
);
|
||||
typeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> changeFormat());
|
||||
}
|
||||
|
||||
private void updateFormatTextField() {
|
||||
FieldConfiguration config = getCurrentFieldConfig();
|
||||
switch (config.getType()) {
|
||||
switch (typeComboBox.getValue()) {
|
||||
case DATE:
|
||||
case DATETIME:
|
||||
case TIME:
|
||||
if (config.getFormat().startsWith("fmt:")) {
|
||||
formatTextField.setText(config.getFormat().substring(4));
|
||||
} else {
|
||||
formatTextField.setText(config.getFormat());
|
||||
}
|
||||
formatTextField.setVisible(true);
|
||||
formatTextField.setText(getCurrentFieldConfig().getFormat());
|
||||
break;
|
||||
default:
|
||||
formatTextField.setVisible(false);
|
||||
formatTextField.setText(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void clearFormatTextField() {
|
||||
FieldConfiguration config = getCurrentFieldConfig();
|
||||
formatTextField.setText(null);
|
||||
switch (config.getType()) {
|
||||
case DATE:
|
||||
case DATETIME:
|
||||
case TIME:
|
||||
formatTextField.setDisable(false);
|
||||
private void updateFormatComboBox() {
|
||||
switch (typeComboBox.getValue()) {
|
||||
case STRING:
|
||||
formatComboBox.setVisible(true);
|
||||
formatComboBox.getSelectionModel().select(StringFormat.fromExternalValue(getCurrentFieldConfig().getFormat()));
|
||||
break;
|
||||
default:
|
||||
formatTextField.setDisable(true);
|
||||
formatComboBox.setVisible(false);
|
||||
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 NUMBER:
|
||||
formatComboBox.getSelectionModel().select(config.getFormat());
|
||||
break;
|
||||
case DATE:
|
||||
case DATETIME:
|
||||
case TIME:
|
||||
if (config.getFormat().startsWith("fmt:")) {
|
||||
formatComboBox.getSelectionModel().select(DateFormat.FMT_PATTERN.toString());
|
||||
} else {
|
||||
formatComboBox.getSelectionModel().select(DateFormat.ANY.toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initMinMaxSpinner() {
|
||||
IntegerSpinnerValueFactory minValueFactory = new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0);
|
||||
minLengthSpinner.setValueFactory(minValueFactory);
|
||||
@@ -283,52 +243,61 @@ public class ValidationEditorController extends FXMLController {
|
||||
|
||||
|
||||
private void changeFormat() {
|
||||
formatComboBox.getItems().clear();
|
||||
formatComboBox.getSelectionModel().clearSelection();
|
||||
switch (typeComboBox.getValue()) {
|
||||
case STRING:
|
||||
updateFormatComboBox(getStringFormats());
|
||||
updateFormatComboBox();
|
||||
break;
|
||||
case DATE:
|
||||
case DATETIME:
|
||||
case TIME:
|
||||
updateFormatComboBox(getDateFormats());
|
||||
updateFormatTextField();
|
||||
break;
|
||||
case INTEGER:
|
||||
case NUMBER:
|
||||
default:
|
||||
// format: no options
|
||||
formatComboBox.setDisable(true);
|
||||
formatTextField.setDisable(true);
|
||||
formatTextField.setText(null);
|
||||
formatComboBox.setVisible(false);
|
||||
formatTextField.setVisible(false);
|
||||
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() {
|
||||
|
||||
FieldConfiguration config = getCurrentFieldConfig();
|
||||
Field config = getCurrentFieldConfig();
|
||||
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()) {
|
||||
config.setGroovy(groovyRuleTextArea.getText());
|
||||
} else {
|
||||
config.setGroovy(null);
|
||||
}
|
||||
|
||||
ConstraintsConfiguration constraints = config.getConstraints();
|
||||
Constraints constraints = config.getConstraints();
|
||||
if (constraints == null) {
|
||||
constraints = new ConstraintsConfiguration();
|
||||
constraints = new Constraints();
|
||||
}
|
||||
|
||||
if (enableNotEmptyRule.isSelected()) {
|
||||
@@ -369,7 +338,7 @@ public class ValidationEditorController extends FXMLController {
|
||||
|
||||
}
|
||||
|
||||
private FieldConfiguration getCurrentFieldConfig() {
|
||||
private Field getCurrentFieldConfig() {
|
||||
return validationConfiguration.getFieldConfiguration(getSelectedColumn());
|
||||
}
|
||||
|
||||
@@ -385,15 +354,15 @@ public class ValidationEditorController extends FXMLController {
|
||||
|
||||
public void updateForm() {
|
||||
|
||||
FieldConfiguration config = getCurrentFieldConfig();
|
||||
Field config = getCurrentFieldConfig();
|
||||
|
||||
if (config.getType() != null) {
|
||||
typeComboBox.setValue(config.getType());
|
||||
} else {
|
||||
typeComboBox.setValue(FieldConfiguration.Type.STRING);
|
||||
typeComboBox.setValue(STRING);
|
||||
}
|
||||
|
||||
updateFormInput();
|
||||
updateFormatComboBox();
|
||||
updateFormatTextField();
|
||||
|
||||
updateCodeAreaControl(
|
||||
@@ -402,7 +371,7 @@ public class ValidationEditorController extends FXMLController {
|
||||
enableGroovyRule
|
||||
);
|
||||
|
||||
ConstraintsConfiguration constraints = config.getConstraints();
|
||||
Constraints constraints = config.getConstraints();
|
||||
updateCheckBox(constraints != null ? constraints.getRequired() : FALSE, enableNotEmptyRule);
|
||||
updateCheckBox(constraints != null ? constraints.getUnique() : FALSE, enableUniqueRule);
|
||||
|
||||
|
||||
@@ -28,12 +28,14 @@ package ninja.javafx.smartcsv.validation;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static ninja.javafx.smartcsv.validation.configuration.Type.*;
|
||||
|
||||
/**
|
||||
* This class loads the constraints as json config
|
||||
*/
|
||||
@@ -48,23 +50,23 @@ public class ValidationFileReader implements FileReader<ValidationConfiguration>
|
||||
}
|
||||
|
||||
private void setDefaults() {
|
||||
for (FieldConfiguration fieldConfiguration: config.getFieldConfigurations()) {
|
||||
if (fieldConfiguration.getType() == null) {
|
||||
fieldConfiguration.setType(FieldConfiguration.Type.STRING);
|
||||
for (Field field : config.getFields()) {
|
||||
if (field.getType() == null) {
|
||||
field.setType(STRING);
|
||||
}
|
||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATE) {
|
||||
if (fieldConfiguration.getFormat() == null) {
|
||||
fieldConfiguration.setFormat("yyyy-MM-dd");
|
||||
if (field.getType() == DATE) {
|
||||
if (field.getFormat() == null) {
|
||||
field.setFormat("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.DATETIME) {
|
||||
if (fieldConfiguration.getFormat() == null) {
|
||||
fieldConfiguration.setFormat("yyyy-MM-ddThh:mm:ssZ");
|
||||
if (field.getType() == DATETIME) {
|
||||
if (field.getFormat() == null) {
|
||||
field.setFormat("yyyy-MM-ddThh:mm:ssZ");
|
||||
}
|
||||
}
|
||||
if (fieldConfiguration.getType() == FieldConfiguration.Type.TIME) {
|
||||
if (fieldConfiguration.getFormat() == null) {
|
||||
fieldConfiguration.setFormat("hh:mm:ss");
|
||||
if (field.getType() == TIME) {
|
||||
if (field.getFormat() == null) {
|
||||
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.validation.checker.*;
|
||||
import ninja.javafx.smartcsv.validation.configuration.ConstraintsConfiguration;
|
||||
import ninja.javafx.smartcsv.validation.configuration.FieldConfiguration;
|
||||
import ninja.javafx.smartcsv.validation.configuration.Constraints;
|
||||
import ninja.javafx.smartcsv.validation.configuration.Field;
|
||||
import ninja.javafx.smartcsv.validation.configuration.ValidationConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -37,6 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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
|
||||
@@ -140,7 +141,7 @@ public class Validator {
|
||||
|
||||
private void initColumnValidations() {
|
||||
if (hasConfig()) {
|
||||
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
||||
for (Field column : validationConfig.getFields()) {
|
||||
initializeColumnWithRules(column);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +149,7 @@ public class Validator {
|
||||
|
||||
private void initializeColumnWithRules(String columnName) {
|
||||
if (hasConfig()) {
|
||||
for (FieldConfiguration column : validationConfig.getFieldConfigurations()) {
|
||||
for (Field column : validationConfig.getFields()) {
|
||||
if (column.getName().equals(columnName)) {
|
||||
initializeColumnWithRules(column);
|
||||
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() == FieldConfiguration.Type.NUMBER) {
|
||||
if (column.getType() == NUMBER) {
|
||||
add(column.getName(), new DoubleValidation());
|
||||
}
|
||||
|
||||
if (column.getType() == FieldConfiguration.Type.INTEGER) {
|
||||
if (column.getType() == INTEGER) {
|
||||
add(column.getName(), new IntegerValidation());
|
||||
}
|
||||
|
||||
if (column.getType() == FieldConfiguration.Type.DATE) {
|
||||
if (column.getType() == DATE) {
|
||||
String format = dateFormat(column.getFormat(), "YYYY-MM-DD");
|
||||
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");
|
||||
add(column.getName(), new DateValidation(format));
|
||||
}
|
||||
|
||||
if (column.getType() == FieldConfiguration.Type.TIME) {
|
||||
if (column.getType() == TIME) {
|
||||
String format = dateFormat(column.getFormat(), "hh:mm:ss");
|
||||
add(column.getName(), new DateValidation(format));
|
||||
}
|
||||
@@ -190,7 +191,7 @@ public class Validator {
|
||||
add(column.getName(), new GroovyValidation(groovy));
|
||||
}
|
||||
|
||||
ConstraintsConfiguration constraints = column.getConstraints();
|
||||
Constraints constraints = column.getConstraints();
|
||||
if (constraints != null) {
|
||||
Boolean notEmptyRule = constraints.getRequired();
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
@SerializedName("fields")
|
||||
private FieldConfiguration[] fieldConfigurations;
|
||||
private Field[] fields;
|
||||
|
||||
public FieldConfiguration[] getFieldConfigurations() {
|
||||
return fieldConfigurations;
|
||||
public Field[] getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFieldConfigurations(FieldConfiguration[] fieldConfigurations) {
|
||||
this.fieldConfigurations = fieldConfigurations;
|
||||
public void setFields(Field[] fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public FieldConfiguration getFieldConfiguration(String column) {
|
||||
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
|
||||
if (fieldConfiguration.getName().equals(column)) {
|
||||
return fieldConfiguration;
|
||||
public Field getFieldConfiguration(String column) {
|
||||
for (Field field : fields) {
|
||||
if (field.getName().equals(column)) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] headerNames() {
|
||||
if (fieldConfigurations != null) {
|
||||
if (fields != null) {
|
||||
List<String> headerNames = new ArrayList<>();
|
||||
for (FieldConfiguration fieldConfiguration: fieldConfigurations) {
|
||||
headerNames.add(fieldConfiguration.getName());
|
||||
for (Field field : fields) {
|
||||
headerNames.add(field.getName());
|
||||
}
|
||||
return headerNames.toArray(new String[headerNames.size()]);
|
||||
}
|
||||
@@ -69,11 +70,11 @@ public class ValidationConfiguration {
|
||||
}
|
||||
|
||||
public void setHeaderNames(String[] header) {
|
||||
fieldConfigurations = new FieldConfiguration[header.length];
|
||||
fields = new Field[header.length];
|
||||
int i = 0;
|
||||
for (String headerName: header) {
|
||||
fieldConfigurations[i] = new FieldConfiguration();
|
||||
fieldConfigurations[i].setName(headerName);
|
||||
fields[i] = new Field();
|
||||
fields[i].setName(headerName);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,4 +86,10 @@ lineNumber = Selected line:
|
||||
log.header.message = {0} has {1} errors
|
||||
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
|
||||
|
||||
@@ -96,4 +96,10 @@ lineNumber = Ausgew\u00e4hlte Zeile:
|
||||
log.header.message = {0} hat {1} Fehler
|
||||
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.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="formatComboBox" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||
<TextField fx:id="formatTextField" GridPane.columnIndex="2" GridPane.columnSpan="2" 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="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="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" />
|
||||
|
||||
Reference in New Issue
Block a user