|
14 | 14 | */
|
15 | 15 | package com.ericsson.eiffel.remrem.semantics;
|
16 | 16 |
|
17 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ACTIVITY_CANCELED; |
18 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ACTIVITY_FINISHED; |
19 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ACTIVITY_STARTED; |
20 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ACTIVITY_TRIGGERED; |
21 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ANNOUNCEMENT_PUBLISHED; |
22 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ARTIFACT_CREATED; |
23 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ARTIFACT_PUBLISHED; |
24 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.COMPOSITION_DEFINED; |
25 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.CONFIDENCELEVEL_MODIFIED; |
26 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTCASE_CANCELED; |
27 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTCASE_TRIGGERED; |
28 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.EXECUTION_RECIPE_COLLECTION_CREATED; |
29 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ENVIRONMENT_DEFINED; |
30 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.FLOWCONTEXT_DEFINED; |
31 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_ALLOCATED; |
32 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_DEPLOYED; |
33 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_DISCONTINUED; |
34 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_RETURNED; |
35 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_STARTED; |
36 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SERVICE_STOPPED; |
37 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ANNOUNCEMENT_ACKNOWLEDGED; |
38 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ARTIFACT_DEPLOYED; |
39 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SOURCECHANGE_CREATED; |
40 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.SOURCECHANGE_SUBMITTED; |
41 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTCASE_FINISHED; |
42 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTCASE_STARTED; |
43 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTSUITE_FINISHED; |
44 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.TESTSUITE_STARTED; |
45 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ISSUE_VERIFIED; |
46 |
| -import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.ARTIFACT_REUSED; |
| 17 | +import static com.ericsson.eiffel.remrem.semantics.EiffelEventType.*; |
47 | 18 |
|
48 | 19 | import java.io.InputStream;
|
49 | 20 | import java.io.InputStreamReader;
|
|
69 | 40 | import com.ericsson.eiffel.semantics.events.EiffelActivityFinishedEvent;
|
70 | 41 | import com.ericsson.eiffel.semantics.events.EiffelActivityStartedEvent;
|
71 | 42 | import com.ericsson.eiffel.semantics.events.EiffelActivityTriggeredEvent;
|
72 |
| -import com.ericsson.eiffel.semantics.events.EiffelAnnouncementAcknowledgedEvent; |
| 43 | +import com.ericsson.eiffel.semantics.events.EiffelAlertAcknowledgedEvent; |
| 44 | +import com.ericsson.eiffel.semantics.events.EiffelAlertCeasedEvent; |
| 45 | +import com.ericsson.eiffel.semantics.events.EiffelAlertRaisedEvent; |
73 | 46 | import com.ericsson.eiffel.semantics.events.EiffelAnnouncementPublishedEvent;
|
74 | 47 | import com.ericsson.eiffel.semantics.events.EiffelArtifactCreatedEvent;
|
75 | 48 | import com.ericsson.eiffel.semantics.events.EiffelArtifactDeployedEvent;
|
76 | 49 | import com.ericsson.eiffel.semantics.events.EiffelArtifactPublishedEvent;
|
| 50 | +import com.ericsson.eiffel.semantics.events.EiffelArtifactReusedEvent; |
77 | 51 | import com.ericsson.eiffel.semantics.events.EiffelCompositionDefinedEvent;
|
78 | 52 | import com.ericsson.eiffel.semantics.events.EiffelConfidenceLevelModifiedEvent;
|
79 |
| -import com.ericsson.eiffel.semantics.events.EiffelTestCaseCanceledEvent; |
80 |
| -import com.ericsson.eiffel.semantics.events.EiffelTestExecutionRecipeCollectionCreatedEvent; |
81 |
| -import com.ericsson.eiffel.semantics.events.EiffelTestCaseTriggeredEvent; |
82 | 53 | import com.ericsson.eiffel.semantics.events.EiffelEnvironmentDefinedEvent;
|
83 | 54 | import com.ericsson.eiffel.semantics.events.EiffelFlowContextDefinedEvent;
|
| 55 | +import com.ericsson.eiffel.semantics.events.EiffelIssueVerifiedEvent; |
84 | 56 | import com.ericsson.eiffel.semantics.events.EiffelServiceAllocatedEvent;
|
85 | 57 | import com.ericsson.eiffel.semantics.events.EiffelServiceDeployedEvent;
|
86 | 58 | import com.ericsson.eiffel.semantics.events.EiffelServiceDiscontinuedEvent;
|
|
89 | 61 | import com.ericsson.eiffel.semantics.events.EiffelServiceStoppedEvent;
|
90 | 62 | import com.ericsson.eiffel.semantics.events.EiffelSourceChangeCreatedEvent;
|
91 | 63 | import com.ericsson.eiffel.semantics.events.EiffelSourceChangeSubmittedEvent;
|
| 64 | +import com.ericsson.eiffel.semantics.events.EiffelTestCaseCanceledEvent; |
92 | 65 | import com.ericsson.eiffel.semantics.events.EiffelTestCaseFinishedEvent;
|
93 | 66 | import com.ericsson.eiffel.semantics.events.EiffelTestCaseStartedEvent;
|
| 67 | +import com.ericsson.eiffel.semantics.events.EiffelTestCaseTriggeredEvent; |
| 68 | +import com.ericsson.eiffel.semantics.events.EiffelTestExecutionRecipeCollectionCreatedEvent; |
94 | 69 | import com.ericsson.eiffel.semantics.events.EiffelTestSuiteFinishedEvent;
|
95 | 70 | import com.ericsson.eiffel.semantics.events.EiffelTestSuiteStartedEvent;
|
96 |
| -import com.ericsson.eiffel.semantics.events.EiffelIssueVerifiedEvent; |
97 |
| -import com.ericsson.eiffel.semantics.events.EiffelArtifactReusedEvent; |
98 | 71 | import com.ericsson.eiffel.semantics.events.Event;
|
99 | 72 | import com.ericsson.eiffel.semantics.events.Gav;
|
100 | 73 | import com.ericsson.eiffel.semantics.events.Serializer;
|
|
103 | 76 | import com.google.gson.JsonElement;
|
104 | 77 | import com.google.gson.JsonObject;
|
105 | 78 | import com.google.gson.JsonParser;
|
| 79 | +import com.google.gson.JsonSyntaxException; |
106 | 80 |
|
107 | 81 | @Named("eiffel-semantics")
|
108 | 82 | public class SemanticsService implements MsgService {
|
@@ -177,50 +151,55 @@ public static Map<EiffelEventType, Class<? extends Event>> eventType() {
|
177 | 151 | eventTypes.put(SERVICE_DEPLOYED, EiffelServiceDeployedEvent.class);
|
178 | 152 | eventTypes.put(SERVICE_ALLOCATED, EiffelServiceAllocatedEvent.class);
|
179 | 153 | eventTypes.put(ARTIFACT_DEPLOYED, EiffelArtifactDeployedEvent.class);
|
180 |
| - eventTypes.put(ANNOUNCEMENT_ACKNOWLEDGED, EiffelAnnouncementAcknowledgedEvent.class); |
| 154 | + eventTypes.put(ALERT_ACKNOWLEDGED, EiffelAlertAcknowledgedEvent.class); |
| 155 | + eventTypes.put(ALERT_CEASED, EiffelAlertCeasedEvent.class); |
| 156 | + eventTypes.put(ALERT_RAISED, EiffelAlertRaisedEvent.class); |
181 | 157 |
|
182 | 158 | return eventTypes;
|
183 | 159 | }
|
184 | 160 |
|
185 | 161 | @Override
|
186 | 162 | public String generateMsg(String msgType, JsonObject bodyJson) {
|
187 |
| - if (semanticsGavFlag) { |
188 |
| - return createErrorResponse("GAV info of eiffel-remrem-semantics is missing", |
189 |
| - "Required Serializer GAV information of eiffel-remrem-semantics is missing in MANIFEST.MF"); |
190 |
| - } |
191 |
| - EiffelEventType eiffelType = EiffelEventType.fromString(msgType); |
192 |
| - if (eiffelType == null) { |
193 |
| - log.error("Unknown message type requested: " + msgType); |
194 |
| - return createErrorResponse(msgType, supportedEventTypes); |
195 |
| - } |
196 |
| - Class<? extends Event> eventType = eventTypes.get(eiffelType); |
197 |
| - |
198 |
| - JsonObject msgNodes = bodyJson.get(MSG_PARAMS).getAsJsonObject(); |
199 |
| - JsonObject eventNodes = bodyJson.get(EVENT_PARAMS).getAsJsonObject(); |
200 |
| - |
201 |
| - // Compare the input JSON EventType with query parameter(-t) and also |
202 |
| - // check type exist or not, |
203 |
| - // if input JSON EventType is missing adding query parameter as Type. |
204 |
| - String inputEventType = getInputEventType(bodyJson); |
205 |
| - if (inputEventType == null || inputEventType.isEmpty()) { |
206 |
| - bodyJson.get(MSG_PARAMS).getAsJsonObject().get(META).getAsJsonObject().addProperty(TYPE, |
207 |
| - eiffelType.getEventName()); |
208 |
| - } else if (!(inputEventType.equals(eiffelType.getEventName()))) { |
209 |
| - log.error("check the input json message type : " + inputEventType); |
210 |
| - return createErrorResponse(eiffelType.getEventName(), |
211 |
| - "Mismatch of eventype in request query parameter with property 'type' in the input json message"); |
212 |
| - } |
| 163 | + try { |
| 164 | + if (semanticsGavFlag) { |
| 165 | + return createErrorResponse("GAV info of eiffel-remrem-semantics is missing", |
| 166 | + "Required Serializer GAV information of eiffel-remrem-semantics is missing in MANIFEST.MF"); |
| 167 | + } |
| 168 | + EiffelEventType eiffelType = EiffelEventType.fromString(msgType); |
| 169 | + if (eiffelType == null) { |
| 170 | + log.error("Unknown message type requested: " + msgType); |
| 171 | + return createErrorResponse(msgType, supportedEventTypes); |
| 172 | + } |
| 173 | + Class<? extends Event> eventType = eventTypes.get(eiffelType); |
213 | 174 |
|
214 |
| - Event event = eventCreation(eventType, msgNodes, eventNodes); |
| 175 | + JsonObject msgNodes = bodyJson.get(MSG_PARAMS).getAsJsonObject(); |
| 176 | + JsonObject eventNodes = bodyJson.get(EVENT_PARAMS).getAsJsonObject(); |
215 | 177 |
|
216 |
| - String result = gson.toJson(event); |
217 |
| - try { |
| 178 | + // Compare the input JSON EventType with query parameter(-t) and also |
| 179 | + // check type exist or not, |
| 180 | + // if input JSON EventType is missing adding query parameter as Type. |
| 181 | + String inputEventType = getInputEventType(bodyJson); |
| 182 | + if (inputEventType == null || inputEventType.isEmpty()) { |
| 183 | + bodyJson.get(MSG_PARAMS).getAsJsonObject().get(META).getAsJsonObject().addProperty(TYPE, eiffelType.getEventName()); |
| 184 | + } else if (!(inputEventType.equals(eiffelType.getEventName()))) { |
| 185 | + log.error("check the input json message type : " + inputEventType); |
| 186 | + return createErrorResponse(eiffelType.getEventName(), |
| 187 | + "Mismatch of eventype in request query parameter with property 'type' in the input json message"); |
| 188 | + } |
| 189 | + |
| 190 | + Event event = eventCreation(eventType, msgNodes, eventNodes); |
| 191 | + |
| 192 | + String result = gson.toJson(event); |
218 | 193 | outputValidate(eiffelType, result);
|
| 194 | + return result; |
219 | 195 | } catch (EiffelValidationException e) {
|
220 | 196 | log.error("Could not validate message. Reason:" + e.getMessage() + "\nCause: " + e.getCause().toString());
|
221 | 197 | return createErrorResponse(e.getMessage(), e.getCause().toString());
|
| 198 | + } catch (JsonSyntaxException e) { |
| 199 | + log.error("Json Syntax exception occured. Reason:" + e.getMessage() + "\nCause: " + e.getCause().toString()); |
| 200 | + return createErrorResponse("Json Syntax exception occured while processing input schema", e.getCause().toString()); |
222 | 201 | }
|
223 |
| - return result; |
| 202 | + |
224 | 203 | }
|
225 | 204 |
|
226 | 205 | private static Event eventCreation(Class<? extends Event> eventType, JsonObject msgNodes, JsonObject eventNodes) {
|
|
0 commit comments