Skip to content

Commit 6b8850b

Browse files
committed
0.7.4.5 (2020-12-29)
-------------------- + Added error map based on ID for validator catalog A.P.I.
1 parent df3b97f commit 6b8850b

File tree

13 files changed

+88
-26
lines changed

13 files changed

+88
-26
lines changed

docgen/parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title" : "Jupiter (Fugerit Core A.P.I.)",
33
"name": "Jupiter",
4-
"version" : "0.7.4.4",
4+
"version" : "0.7.4.5",
55
"date" : "29/12/2020",
66
"organization" : {
77
"name" : "Fugerit Org",

docgen/release-notes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
0.7.4.4 (2020-12-29)
1+
0.7.4.5 (2020-12-29)
2+
--------------------
3+
+ Added error map based on ID for validator catalog A.P.I.
4+
5+
0.7.4.4 (2020-12-29)
26
--------------------
37
+ Added info property in BasicValidator
48

fj-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.fugerit.java</groupId>
99
<artifactId>fj-lib</artifactId>
10-
<version>0.7.4.4</version>
10+
<version>0.7.4.5</version>
1111
</parent>
1212

1313
<name>fj-core</name>

fj-core/src/main/java/org/fugerit/java/core/validator/BasicValidator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ public boolean validate( ValidatorContext context ) throws Exception {
126126
boolean valid = this.isOptional() || ( StringUtils.isNotEmpty( context.getValue() ) );
127127
if ( !valid ) {
128128
String message = this.formatMessage( context.getBundle() , ERROR_KEY_REQUIRED, context.getLabel() );
129-
context.getResult().getErrors().add( message );
129+
context.getResult().addError( context.getFieldId(), message );
130130
}
131131
if ( valid && StringUtils.isNotEmpty( context.getValue() ) ) {
132132
int length = context.getValue().length();
133133
if ( this.getMinLength() != NO_LENGTH_CONSTRAINT && length < this.getMinLength() ) {
134134
valid = false;
135135
String message = this.formatMessage( context.getBundle() , ERROR_KEY_LENGTH_MIN, context.getLabel(), String.valueOf( length ), String.valueOf( this.getMinLength() ) );
136-
context.getResult().getErrors().add( message );
136+
context.getResult().addError( context.getFieldId(), message );
137137
}
138138
if ( this.getMaxLength() != NO_LENGTH_CONSTRAINT && length > this.getMaxLength() ) {
139139
valid = false;
140140
String message = this.formatMessage( context.getBundle() , ERROR_KEY_LENGTH_MAX, context.getLabel(), String.valueOf( length ), String.valueOf( this.getMaxLength() ) );
141-
context.getResult().getErrors().add( message );
141+
context.getResult().addError( context.getFieldId(), message );
142142
}
143143
}
144144
return valid;

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorCatalog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public Properties getBundle( Locale l ) {
135135
return bundle;
136136
}
137137

138-
public boolean validate( String validatorId, ValidatorResult result, Locale l, String value, String label, Properties params ) throws Exception {
139-
ValidatorContext context = new ValidatorContext( this , result, l, value, label);
138+
public boolean validate( String validatorId, ValidatorResult result, Locale l, String fieldId, String value, String label, Properties params ) throws Exception {
139+
ValidatorContext context = new ValidatorContext( this , result, l, fieldId, value, label );
140140
for ( Object key : params.keySet() ) {
141141
String k = String.valueOf( key );
142142
context.setAttribute( k , params.getProperty( k ) );

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorContext.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class ValidatorContext extends AttributeHolderDefault {
1818

1919
private Locale locale;
2020

21+
private String fieldId;
22+
2123
private String value;
2224

2325
private String label;
@@ -46,6 +48,14 @@ public void setLocale(Locale locale) {
4648
this.locale = locale;
4749
}
4850

51+
public String getFieldId() {
52+
return fieldId;
53+
}
54+
55+
public void setFieldId(String fieldId) {
56+
this.fieldId = fieldId;
57+
}
58+
4959
public String getValue() {
5060
return value;
5161
}
@@ -62,11 +72,12 @@ public void setLabel(String label) {
6272
this.label = label;
6373
}
6474

65-
public ValidatorContext(ValidatorCatalog catalog, ValidatorResult result, Locale locale, String value, String label) {
75+
public ValidatorContext(ValidatorCatalog catalog, ValidatorResult result, Locale locale, String fieldId, String value, String label) {
6676
super();
6777
this.catalog = catalog;
6878
this.result = result;
6979
this.locale = locale;
80+
this.fieldId = fieldId;
7081
this.value = value;
7182
this.label = label;
7283
}

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorDate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ protected boolean validate( ValidatorContext context, String minDate, String max
9797
if ( StringUtils.isNotEmpty( minDate ) && d.before( sdf.parse( minDate ) ) ) {
9898
valid = false;
9999
String message = this.formatMessage( context.getBundle() , ERROR_KEY_DATE_MIN, context.getLabel(), context.getValue(), minDate );
100-
context.getResult().getErrors().add( message );
100+
context.getResult().addError( context.getFieldId(), message );
101101
}
102102
if ( StringUtils.isNotEmpty( maxDate ) && d.after( sdf.parse( maxDate ) ) ) {
103103
valid = false;
104104
String message = this.formatMessage( context.getBundle() , ERROR_KEY_DATE_MAX, context.getLabel(), context.getValue(), maxDate );
105-
context.getResult().getErrors().add( message );
105+
context.getResult().addError( context.getFieldId(), message );
106106
}
107107
} catch (Exception e) {
108108
valid = false;
109109
String message = this.formatMessage( context.getBundle() , ERROR_KEY_DATE, context.getLabel(), context.getValue(), StringUtils.valueWithDefault( this.getInfo(), this.getDateFormat() ) );
110-
context.getResult().getErrors().add( message );
110+
context.getResult().addError( context.getFieldId(), message );
111111
}
112112
return valid;
113113
}

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorRegex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public boolean validate(ValidatorContext context) throws Exception {
4646
if ( !Pattern.matches( this.getRegex() , context.getValue() ) ) {
4747
valid = false;
4848
String message = this.formatMessage( context.getBundle() , ERROR_KEY_REGEX, context.getLabel(), context.getValue(), StringUtils.valueWithDefault( this.getInfo(), this.getRegex() ) );
49-
context.getResult().getErrors().add( message );
49+
context.getResult().addError( context.getFieldId(), message );
5050
}
5151
return valid;
5252
}

fj-core/src/main/java/org/fugerit/java/core/validator/ValidatorResult.java

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.io.Serializable;
44
import java.util.ArrayList;
55
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import org.fugerit.java.core.cfg.ConfigException;
9+
import org.fugerit.java.core.util.PropertyEntry;
610

711
public class ValidatorResult implements Serializable {
812

@@ -11,21 +15,63 @@ public class ValidatorResult implements Serializable {
1115
*/
1216
private static final long serialVersionUID = -5473162078733130133L;
1317

14-
private List<String> errors;
18+
public static final String GENERIC_ID = ValidatorResult.class.getName()+"_GENERIC_ID";
1519

16-
private List<String> warnings;
20+
private List<PropertyEntry> errors;
1721

22+
private List<PropertyEntry> warnings;
23+
1824
public ValidatorResult() {
19-
this.errors = new ArrayList<String>();
20-
this.warnings = new ArrayList<String>();
25+
this.errors = new ArrayList<PropertyEntry>();
26+
this.warnings = new ArrayList<PropertyEntry>();
2127
}
2228

23-
public List<String> getErrors() {
29+
public void addGenericError( String message ) throws ConfigException {
30+
this.addError( GENERIC_ID, message );
31+
}
32+
33+
public void addGenericWarning( String fieldId, String message ) throws ConfigException {
34+
this.addWarning( GENERIC_ID , message );
35+
}
36+
37+
public void addError( String fieldId, String message ) throws ConfigException {
38+
this.errors.add( PropertyEntry.newEntry( fieldId , message ) );
39+
}
40+
41+
public void addWarning( String fieldId, String message ) throws ConfigException {
42+
this.warnings.add( PropertyEntry.newEntry( fieldId , message ) );
43+
}
44+
45+
public List<PropertyEntry> getErrors() {
2446
return errors;
2547
}
2648

27-
public List<String> getWarnings() {
49+
public List<PropertyEntry> getWarnings() {
2850
return warnings;
2951
}
30-
52+
53+
private List<String> filter( List<PropertyEntry> list, String fieldId ) {
54+
return list.stream().filter(
55+
entry -> fieldId.equals( entry.getKey() )
56+
).map(
57+
entry -> entry.getValue()
58+
).collect( Collectors.toList() );
59+
}
60+
61+
public List<String> getFieldErrors(String fieldId ) {
62+
return filter( this.getErrors() , fieldId );
63+
}
64+
65+
public List<String> getFieldWarning(String fieldId ) {
66+
return filter( this.getWarnings() , fieldId );
67+
}
68+
69+
public List<String> getGenericErrors() {
70+
return this.getFieldErrors( GENERIC_ID );
71+
}
72+
73+
public List<String> getGenericWarning() {
74+
return this.getFieldWarning( GENERIC_ID );
75+
}
76+
3177
}

fj-core/src/test/java/test/org/fugerit/java/core/validator/TestValidatorCatalog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Properties;
77

88
import org.fugerit.java.core.cfg.ConfigException;
9+
import org.fugerit.java.core.util.PropertyEntry;
910
import org.fugerit.java.core.validator.ValidatorCatalog;
1011
import org.fugerit.java.core.validator.ValidatorDate;
1112
import org.fugerit.java.core.validator.ValidatorResult;
@@ -28,7 +29,7 @@ public class TestValidatorCatalog extends BasicTest {
2829

2930
private void validatorWorker( String validatorId, ValidatorResult result, Locale l, String value, String label, boolean expected, Properties params ) {
3031
try {
31-
boolean valid = catalog.validate( validatorId , result, l, value, label, params );
32+
boolean valid = catalog.validate( validatorId , result, l, label, value, label, params );
3233
logger.info( "valid? -> {} ", valid );
3334
if ( expected != valid ) {
3435
fail( "Expected:"+expected+" != Result:"+valid );
@@ -41,8 +42,8 @@ private void validatorWorker( String validatorId, ValidatorResult result, Locale
4142
}
4243

4344
private void printResult( ValidatorResult result ) {
44-
for ( String message : result.getErrors() ) {
45-
logger.info( "Error : {}", message );
45+
for ( PropertyEntry entry : result.getErrors() ) {
46+
logger.info( "Error : {}", entry.getValue() );
4647
}
4748
}
4849

0 commit comments

Comments
 (0)