22
22
import static com .ericsson .eiffel .remrem .semantics .EiffelEventType .ISSUE_VERIFIED ;
23
23
import static com .ericsson .eiffel .remrem .semantics .EiffelEventType .ARTIFACT_REUSED ;
24
24
25
+ import java .util .ArrayList ;
25
26
import java .util .HashMap ;
26
27
import java .util .Map ;
27
28
62
63
63
64
@ Named ("eiffel-semantics" )
64
65
public class SemanticsService implements MsgService {
65
-
66
+ private static final String ERROR = "error" ;
67
+ private static final String SUPPORTED_EVENT_TYPES = "SUPPORTED_EVENT_TYPES" ;
68
+ private static final String RESULT = "result" ;
69
+ private static final String UNKNOWN_EVENT_TYPE_REQUESTED = "Unknown event type requested" ;
66
70
private static final String EVENT_PARAMS = "eventParams" ;
67
71
private static final String MSG_PARAMS = "msgParams" ;
68
72
private static final String MESSAGE = "message" ;
@@ -71,12 +75,18 @@ public class SemanticsService implements MsgService{
71
75
private static final String ID = "id" ;
72
76
private static final String META = "meta" ;
73
77
private static final String TYPE = "type" ;
74
-
78
+ private static final ArrayList < String > supportedEventTypes = new ArrayList < String >();
75
79
public static final Logger log = LoggerFactory .getLogger (SemanticsService .class );
76
80
77
81
private static Gson gson = new Gson ();
78
82
private static Map <EiffelEventType , Class <? extends Event >> eventTypes =SemanticsService .eventType ();
79
83
84
+ public SemanticsService (){
85
+ for (final EiffelEventType msg : EiffelEventType .values ()) {
86
+ supportedEventTypes .add (msg .getEventName ());
87
+ }
88
+ }
89
+
80
90
public static Map <EiffelEventType , Class <? extends Event >> eventType ()
81
91
{
82
92
eventTypes = new HashMap <>();
@@ -107,7 +117,7 @@ public String generateMsg(String msgType, JsonObject bodyJson){
107
117
EiffelEventType eiffelType = EiffelEventType .fromString (msgType );
108
118
if (eiffelType == null ) {
109
119
log .error ("Unknown message type requested: " + msgType );
110
- return createErrorResponse ("Unknown message type requested" , "'" + msgType + "' is not in the vocabulary of this service" );
120
+ return createErrorResponse (msgType , supportedEventTypes );
111
121
}
112
122
Class <? extends Event > eventType = eventTypes .get (eiffelType );
113
123
@@ -143,7 +153,13 @@ private String createErrorResponse(final String message, final String cause){
143
153
errorResponse .addProperty (CAUSE , cause .replace ("\n " , "" ));
144
154
return errorResponse .toString ();
145
155
}
146
-
156
+ private String createErrorResponse (final String message , final ArrayList <String > supportedEventTypes ){
157
+ JsonObject errorResponse = new JsonObject ();
158
+ errorResponse .addProperty (RESULT , ERROR );
159
+ errorResponse .addProperty (MESSAGE , UNKNOWN_EVENT_TYPE_REQUESTED +" - " + message );
160
+ errorResponse .addProperty (SUPPORTED_EVENT_TYPES ,supportedEventTypes .toString ());
161
+ return errorResponse .toString ();
162
+ }
147
163
private void outputValidate (EiffelEventType eiffelType , String jsonStringInput ) throws EiffelValidationException {
148
164
EiffelValidator validator = EiffelOutputValidatorFactory .getEiffelValidator (eiffelType );
149
165
JsonObject jsonObject = new JsonParser ().parse (jsonStringInput ).getAsJsonObject ();
0 commit comments