Skip to content

Commit 9431bd2

Browse files
author
Vasile Baluta
committed
2 parents eef7d67 + 31be0a5 commit 9431bd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2796
-1578
lines changed

pom.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.ericsson.ei</groupId>
4+
<groupId>com.github.ericsson</groupId>
55
<artifactId>eiffel-intelligence</artifactId>
6-
<version>0.0.2</version>
6+
<version>0.0.4</version>
77

88
<packaging>war</packaging>
99

@@ -192,7 +192,7 @@
192192
<groupId>org.springframework.boot</groupId>
193193
<artifactId>spring-boot-maven-plugin</artifactId>
194194
</plugin>
195-
195+
196196
<!-- PhoenixNAP RAML Code Generator plugin used to generate sources
197197
from raml -->
198198
<plugin>
@@ -224,8 +224,8 @@
224224
</goals>
225225
</execution>
226226
</executions>
227-
</plugin>
228-
227+
</plugin>
228+
229229
<!-- required for adding generated sources -->
230230
<plugin>
231231
<groupId>org.codehaus.mojo</groupId>
@@ -244,13 +244,15 @@
244244
</configuration>
245245
</execution>
246246
</executions>
247-
</plugin>
248-
247+
</plugin>
248+
249249
<plugin>
250250
<groupId>org.apache.maven.plugins</groupId>
251251
<artifactId>maven-surefire-plugin</artifactId>
252252
<version>2.20</version>
253253
<configuration>
254+
<forkCount>1</forkCount>
255+
<reuseForks>false</reuseForks>
254256
<excludes>
255257
<exclude>${someModule.test.excludes}</exclude>
256258
</excludes>

src/main/java/com/ericsson/ei/controller/AggregatedObjectController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package com.ericsson.ei.controller;
33

4-
import com.ericsson.ei.controller.model.QueryResponse;
54
import org.springframework.http.ResponseEntity;
65
import org.springframework.web.bind.annotation.RequestMapping;
76
import org.springframework.web.bind.annotation.RequestMethod;

src/main/java/com/ericsson/ei/controller/MissedNotificationController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package com.ericsson.ei.controller;
33

4-
import com.ericsson.ei.controller.model.QueryResponse;
54
import org.springframework.http.ResponseEntity;
65
import org.springframework.web.bind.annotation.RequestMapping;
76
import org.springframework.web.bind.annotation.RequestMethod;

src/main/java/com/ericsson/ei/controller/RuleCheckControllerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public class RuleCheckControllerImpl implements RuleCheckController {
4646
JmesPathInterface jmesPathInterface;
4747

4848
/**
49-
* This method interacts with JmesPathInterface class method runRuleOnEvent to
50-
* evaluate a rule on JSON object.
49+
* This method interacts with JmesPathInterface class method runRuleOnEvent
50+
* to evaluate a rule on JSON object.
5151
*
5252
* @param rule-
53-
* takes a String as a rule that need to be evaluated on JSON content
53+
* takes a String as a rule that need to be evaluated on JSON
54+
* content
5455
* @param jsonContent-
5556
* takes JSON object as a String
5657
* @return return a String object

src/main/java/com/ericsson/ei/controller/SubscriptionController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface SubscriptionController {
2424
*
2525
*/
2626
@RequestMapping(value = "", method = RequestMethod.GET)
27-
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptions();
27+
public ResponseEntity<List<String>> getSubscriptions();
2828

2929
/**
3030
* Takes the subscription rules, the name for subscription and the user name of the person registering this subscription and saves the subscription in subscription database. The name needs to be unique.
@@ -34,34 +34,34 @@ public interface SubscriptionController {
3434
public ResponseEntity<?> createSubscription(
3535
@javax.validation.Valid
3636
@org.springframework.web.bind.annotation.RequestBody
37-
com.ericsson.ei.controller.model.Subscription subscription);
37+
Subscription subscription);
3838

3939
/**
4040
* Modify an existing Subscription.
4141
*
4242
*/
4343
@RequestMapping(value = "", method = RequestMethod.PUT)
44-
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> updateSubscriptions(
44+
public ResponseEntity<SubscriptionResponse> updateSubscriptions(
4545
@javax.validation.Valid
4646
@org.springframework.web.bind.annotation.RequestBody
47-
com.ericsson.ei.controller.model.Subscription subscription);
47+
Subscription subscription);
4848

4949
/**
5050
* Returns the subscription rules for given subscription name.
5151
*
5252
*/
5353
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.GET)
54-
public ResponseEntity<List<com.ericsson.ei.controller.model.Subscription>> getSubscriptionById(
54+
public ResponseEntity<List<String>> getSubscriptionById(
5555
@PathVariable(required = false)
56-
String subscriptionName);
56+
java.lang.String subscriptionName);
5757

5858
/**
5959
* Removes the subscription from the database.
6060
*
6161
*/
6262
@RequestMapping(value = "/{subscriptionName}", method = RequestMethod.DELETE)
63-
public ResponseEntity<com.ericsson.ei.controller.model.SubscriptionResponse> deleteSubscriptionById(
63+
public ResponseEntity<SubscriptionResponse> deleteSubscriptionById(
6464
@PathVariable(required = false)
65-
String subscriptionName);
65+
java.lang.String subscriptionName);
6666

6767
}

src/main/java/com/ericsson/ei/erqueryservice/ERQueryService.java

Lines changed: 76 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
*/
1818
package com.ericsson.ei.erqueryservice;
1919

20-
import java.util.HashMap;
21-
import java.util.Map;
22-
23-
import javax.annotation.PostConstruct;
24-
20+
import com.fasterxml.jackson.databind.JsonNode;
2521
import lombok.Getter;
2622
import org.slf4j.Logger;
2723
import org.slf4j.LoggerFactory;
@@ -33,30 +29,26 @@
3329
import org.springframework.http.MediaType;
3430
import org.springframework.http.ResponseEntity;
3531
import org.springframework.stereotype.Component;
36-
import org.springframework.util.LinkedMultiValueMap;
32+
import org.springframework.web.client.RestClientException;
3733
import org.springframework.web.client.RestOperations;
34+
import org.springframework.web.util.UriComponents;
3835
import org.springframework.web.util.UriComponentsBuilder;
3936

40-
import com.fasterxml.jackson.databind.JsonNode;
41-
import com.fasterxml.jackson.databind.ObjectMapper;
42-
import com.fasterxml.jackson.databind.node.ArrayNode;
43-
import com.fasterxml.jackson.databind.node.ObjectNode;
37+
import javax.annotation.PostConstruct;
38+
import java.net.URI;
39+
import java.util.ArrayList;
40+
import java.util.Collections;
41+
import java.util.List;
42+
import java.util.Map;
4443

4544
/**
4645
* @author evasiba
47-
*
4846
*/
4947
@Component
5048
public class ERQueryService {
5149

5250
static Logger log = (Logger) LoggerFactory.getLogger(ERQueryService.class);
53-
5451
private RestOperations rest;
55-
56-
public final static int DOWNSTREAM = 0;
57-
public final static int UPSTREAM = 1;
58-
public final static int DOWNANDUPSTREAM = 2;
59-
6052
@Getter
6153
@Value("${er.url}")
6254
private String url;
@@ -74,102 +66,104 @@ public void setRest(RestOperations rest) {
7466
* eventID.
7567
*
7668
* @param eventId
69+
* the id of the event.
7770
* @return ResponseEntity
7871
*/
79-
public ResponseEntity getEventDataById(String eventId) {
80-
String erUrl = url.trim() + "{id}";
81-
log.info("The url is : " + erUrl);
82-
Map<String, String> params = new HashMap<String, String>();
83-
params.put("id", eventId);
84-
ResponseEntity<String> response = null;
85-
log.info("The ID parameter is set");
72+
public ResponseEntity<String> getEventDataById(String eventId) {
73+
final String erUrl = URI.create(url.trim() + "/" + "{id}").normalize().toString();
74+
log.debug("The URL to ER is: " + erUrl);
75+
76+
final Map<String, String> params = Collections.singletonMap("id", eventId);
77+
log.trace("The ID parameter is set");
8678
try {
87-
response = rest.getForEntity(erUrl, String.class, params);
88-
log.info("The response is : " + response.toString());
89-
} catch (Exception e) {
90-
log.error(e.getMessage(), e);
79+
final ResponseEntity<String> response = rest.getForEntity(erUrl, String.class, params);
80+
log.trace("The response is : " + response.toString());
81+
} catch (RestClientException e) {
82+
log.error("Error occurred while executing REST GET to: " + erUrl + " for " + eventId, e);
9183
}
92-
return response;
84+
85+
return null;
9386
}
9487

9588
/**
9689
* This method is used to fetch only the upstream or downstream or both
97-
* event information from ER2.0 based on the eventID and searchAction
90+
* event information from ER2.0 based on the eventID and searchOption
9891
* conditions.
9992
*
10093
* @param eventId
101-
* @param searchAction
102-
* @param limitParam
103-
* @param levelsParam
94+
* the id of the event.
95+
* @param searchOption
96+
* the SearchOption to indicate whether to search up, down or
97+
* both ways from the eventId.
98+
* @param limit
99+
* sets the limit of how many events up and/or down stream from
100+
* the eventId to include in the result.
101+
* @param levels
102+
* sets the limit of how many levels up and/or down stream from
103+
* the eventId to include in the result.
104104
* @param tree
105+
* whether or not to retain the tree structure in the result.
105106
* @return ResponseEntity
106107
*/
108+
public ResponseEntity<JsonNode> getEventStreamDataById(String eventId, SearchOption searchOption, int limit,
109+
int levels, boolean tree) {
107110

108-
public ResponseEntity getEventStreamDataById(String eventId, int searchAction, int limitParam,
109-
int levelsParam, boolean tree) {
110-
111-
String erUrl = url.trim() + eventId;
112-
log.info("The url is : " + erUrl);
111+
final String erUrl = URI.create(url.trim() + "/" + eventId).normalize().toString();
112+
log.debug("The URL to ER is: " + erUrl);
113113

114114
// Request Body parameters
115-
JsonNode uriParams = getSearchParameters(searchAction);
116-
117-
// Add query parameter
118-
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(erUrl).queryParam("limit", limitParam)
119-
.queryParam("levels", levelsParam).queryParam("tree", tree);
115+
final SearchParameters searchParameters = getSearchParameters(searchOption);
120116

121-
HttpHeaders headers = new HttpHeaders();
117+
// Build query parameters
118+
final UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(erUrl).queryParam("limit", limit)
119+
.queryParam("levels", levels).queryParam("tree", tree);
120+
final HttpHeaders headers = new HttpHeaders();
122121
headers.setContentType(MediaType.APPLICATION_JSON);
123122

124-
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity(uriParams, headers);
125-
log.info("The request is : " + builder.buildAndExpand(uriParams).toUri().toString());
126-
127-
ResponseEntity response = rest.exchange(builder.buildAndExpand(uriParams).toUri(), HttpMethod.POST,
128-
requestEntity, JsonNode.class);
129-
return response;
130-
}
131-
132-
/** Generates the json object used as body for downstream/upstream
133-
* query requests
134-
* @param searchAction - one of DOWNSTREAM, UPSTREAM or DOWNANDUPSTREAM
135-
* @return
136-
*/
137-
public JsonNode getSearchParameters(int searchAction) {
138-
JsonNode uriParams = null;
139-
ObjectMapper objectmapper = new ObjectMapper();
140-
141-
String[] linkTypes = {"ALL"};
123+
final HttpEntity<SearchParameters> requestEntity = new HttpEntity<>(searchParameters, headers);
124+
final UriComponents uriComponents = builder.buildAndExpand(searchParameters);
125+
log.debug("The request is : " + uriComponents.toUri().toString());
142126

143127
try {
144-
uriParams = objectmapper.readTree("{}");
145-
if (searchAction == DOWNSTREAM) {
146-
putSearchParameter(uriParams, "dlt", linkTypes);
147-
} else if (searchAction == UPSTREAM) {
148-
putSearchParameter(uriParams, "ult", linkTypes);
149-
} else if (searchAction == DOWNANDUPSTREAM) {
150-
putSearchParameter(uriParams, "dlt", linkTypes);
151-
putSearchParameter(uriParams, "ult", linkTypes);
152-
}
153-
} catch (Exception e) {
154-
log.error(e.getMessage(), e);
128+
return rest.exchange(uriComponents.toUri(), HttpMethod.POST, requestEntity, JsonNode.class);
129+
} catch (RestClientException e) {
130+
log.error("Error occurred while executing REST POST to: " + erUrl + " for\n" + requestEntity, e);
155131
}
156-
return uriParams;
132+
133+
return null;
157134
}
158135

159-
/** Create an array node with link types for upstream or downstream query
160-
* @param params
161-
* @param actionString
162-
* @param linkTypes
136+
/**
137+
* Build the search parameters to be used to query ER.
138+
*
139+
* @param searchOption
140+
* one of UP_STREAM, DOWN_STREAM or UP_AND_DOWN_STREAM
141+
* @return the search parameters to be used
163142
*/
164-
public void putSearchParameter(JsonNode params, String actionString, String[] linkTypes) {
165-
ArrayNode node =((ObjectNode) params).putArray(actionString);
166-
for (String string : linkTypes) {
167-
node.add(string);
143+
private SearchParameters getSearchParameters(SearchOption searchOption) {
144+
final SearchParameters searchParameters = new SearchParameters();
145+
final List<LinkType> allLinkTypes = Collections.singletonList(LinkType.ALL);
146+
switch (searchOption) {
147+
case DOWN_STREAM:
148+
searchParameters.setUlt(new ArrayList<>());
149+
searchParameters.setDlt(allLinkTypes);
150+
break;
151+
case UP_STREAM:
152+
searchParameters.setUlt(allLinkTypes);
153+
searchParameters.setDlt(new ArrayList<>());
154+
break;
155+
case UP_AND_DOWN_STREAM:
156+
searchParameters.setUlt(allLinkTypes);
157+
searchParameters.setDlt(allLinkTypes);
158+
break;
168159
}
160+
161+
return searchParameters;
169162
}
170163

171164
@PostConstruct
172165
public void init() {
166+
// TODO: is this needed?
173167
log.debug("The url parameter is : " + url);
174168
}
175169
}

0 commit comments

Comments
 (0)