21
21
import java .util .Set ;
22
22
23
23
import org .apache .commons .lang3 .StringUtils ;
24
+ import org .slf4j .Logger ;
25
+ import org .slf4j .LoggerFactory ;
24
26
25
27
import com .ericsson .eiffel .remrem .semantics .LinkType ;
26
28
import com .fasterxml .jackson .databind .ObjectMapper ;
27
29
import com .github .fge .jackson .JsonLoader ;
30
+ import com .github .fge .jsonschema .core .report .LogLevel ;
31
+ import com .github .fge .jsonschema .core .report .ProcessingMessage ;
28
32
import com .github .fge .jsonschema .core .report .ProcessingReport ;
29
33
import com .github .fge .jsonschema .main .JsonSchema ;
30
34
import com .github .fge .jsonschema .main .JsonSchemaFactory ;
35
+ import com .google .gson .Gson ;
36
+ import com .google .gson .GsonBuilder ;
31
37
import com .google .gson .JsonArray ;
32
38
import com .google .gson .JsonElement ;
33
39
import com .google .gson .JsonObject ;
34
-
35
- import org .slf4j .Logger ;
36
- import org .slf4j .LoggerFactory ;
40
+ import com .google .gson .JsonParser ;
37
41
38
42
public class EiffelValidator {
39
43
public static final Logger log = LoggerFactory .getLogger (EiffelValidator .class );
@@ -72,9 +76,8 @@ public void validate(JsonObject jsonObjectInput) throws EiffelValidationExceptio
72
76
try {
73
77
ProcessingReport report = validationSchema .validate (JsonLoader .fromString (jsonObjectInput .toString ()));
74
78
if (!report .isSuccess ()) {
75
- log .warn (report .toString ());
76
79
log .warn (jsonObjectInput .toString ());
77
- throw new EiffelValidationException (report . toString ( ));
80
+ throw new EiffelValidationException (getErrorsList ( report ));
78
81
}
79
82
log .debug ("VALIDATED. Schema used: {}" , schemaResourceName );
80
83
} catch (Exception e ) {
@@ -84,6 +87,26 @@ public void validate(JsonObject jsonObjectInput) throws EiffelValidationExceptio
84
87
}
85
88
}
86
89
90
+ /**
91
+ *
92
+ * @param report json validation report
93
+ * @return error message
94
+ */
95
+ private String getErrorsList (ProcessingReport report ) {
96
+ Gson gson = new GsonBuilder ().setPrettyPrinting ().create ();
97
+ JsonParser parser = new JsonParser ();
98
+ String message = "" ;
99
+ for (ProcessingMessage processingMessage : report ) {
100
+ if (LogLevel .ERROR .equals (processingMessage .getLogLevel ())) {
101
+ JsonElement element =parser .parse (processingMessage .asJson ().toString ());
102
+ element .getAsJsonObject ().remove ("schema" );
103
+ element .getAsJsonObject ().remove ("level" );
104
+ message = gson .toJson (element );
105
+ log .debug (message );
106
+ }
107
+ }
108
+ return message ;
109
+ }
87
110
/**
88
111
* This method is used to validate links in an event
89
112
* @param JsonArray of links in an event
0 commit comments