12
12
import org .slf4j .Logger ;
13
13
import org .slf4j .LoggerFactory ;
14
14
15
+ import com .ericsson .eiffel .remrem .protocol .MsgService ;
16
+ import com .ericsson .eiffel .remrem .protocol .ValidationResult ;
15
17
import com .ericsson .eiffel .remrem .semantics .events .EiffelActivityFinishedEvent ;
16
18
import com .ericsson .eiffel .remrem .semantics .events .EiffelArtifactPublishedEvent ;
17
19
import com .ericsson .eiffel .remrem .semantics .events .Event ;
18
20
import com .ericsson .eiffel .remrem .semantics .factory .EiffelOutputValidatorFactory ;
19
21
import com .ericsson .eiffel .remrem .semantics .validator .EiffelValidationException ;
20
22
import com .ericsson .eiffel .remrem .semantics .validator .EiffelValidator ;
21
- import com .ericsson .eiffel .remrem .shared .MsgService ;
22
23
import com .google .gson .Gson ;
23
24
import com .google .gson .JsonObject ;
24
25
import com .google .gson .JsonParser ;
27
28
@ Named ("eiffel-semantics" )
28
29
public class SemanticsService implements MsgService {
29
30
31
+ private static final String EVENT_PARAMS = "eventParams" ;
32
+ private static final String MSG_PARAMS = "msgParams" ;
33
+ private static final String MESSAGE = "message" ;
34
+ private static final String CAUSE = "cause" ;
35
+ private static final String EIFFELSEMANTICS = "eiffelsemantics" ;
30
36
private static final String ID = "id" ;
31
37
private static final String META = "meta" ;
32
38
@@ -50,8 +56,8 @@ public String generateMsg(String msgType, JsonObject bodyJson){
50
56
}
51
57
Class <? extends Event > eventType = eventTypes .get (eiffelType );
52
58
53
- JsonObject msgNodes = bodyJson .get ("msgParams" ).getAsJsonObject ();
54
- JsonObject eventNodes = bodyJson .get ("eventParams" ).getAsJsonObject ();
59
+ JsonObject msgNodes = bodyJson .get (MSG_PARAMS ).getAsJsonObject ();
60
+ JsonObject eventNodes = bodyJson .get (EVENT_PARAMS ).getAsJsonObject ();
55
61
56
62
Event event = createEvent (eventNodes , eventType );
57
63
event .generateMeta (msgType , msgNodes );
@@ -72,8 +78,8 @@ private Event createEvent(JsonObject eventNodes, Class<? extends Event> eventTyp
72
78
73
79
private String createErrorResponse (final String message , final String cause ){
74
80
JsonObject errorResponse = new JsonObject ();
75
- errorResponse .addProperty ("message" , message );
76
- errorResponse .addProperty ("cause" , cause .replace ("\n " , "" ));
81
+ errorResponse .addProperty (MESSAGE , message );
82
+ errorResponse .addProperty (CAUSE , cause .replace ("\n " , "" ));
77
83
return errorResponse .toString ();
78
84
}
79
85
@@ -92,4 +98,32 @@ public String getEventId(JsonObject json) {
92
98
}
93
99
return null ;
94
100
}
101
+
102
+ @ Override
103
+ public String getFamily (JsonObject eiffelMessage ) {
104
+ return null ;
105
+ }
106
+
107
+ @ Override
108
+ public String getType (JsonObject eiffelMessage ) {
109
+ return null ;
110
+ }
111
+ @ Override
112
+ public String getServiceName () {
113
+ return EIFFELSEMANTICS ;
114
+ }
115
+
116
+ @ Override
117
+ public ValidationResult validateMsg (String msgType , JsonObject jsonvalidateMessage ) {
118
+ ValidationResult validationResult = null ;
119
+ EiffelEventType eiffelType = EiffelEventType .fromString (msgType );
120
+ String result = gson .toJson (jsonvalidateMessage );
121
+ try {
122
+ outputValidate (eiffelType , result );
123
+ validationResult = new ValidationResult (true , "" );
124
+ } catch (EiffelValidationException e ) {
125
+ validationResult = new ValidationResult (false , e .getLocalizedMessage ());
126
+ }
127
+ return validationResult ;
128
+ }
95
129
}
0 commit comments