Skip to content

Commit 6b5512c

Browse files
authored
Merge pull request #10 from Ericsson/master
Merge
2 parents 119f42d + f2e0a12 commit 6b5512c

Some content is hidden

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

43 files changed

+2918
-1471
lines changed

pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.ericsson</groupId>
55
<artifactId>eiffel-intelligence</artifactId>
6-
<version>0.0.3</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/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/erqueryservice/ERQueryService.java

Lines changed: 75 additions & 80 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,29 +29,26 @@
3329
import org.springframework.http.MediaType;
3430
import org.springframework.http.ResponseEntity;
3531
import org.springframework.stereotype.Component;
32+
import org.springframework.web.client.RestClientException;
3633
import org.springframework.web.client.RestOperations;
34+
import org.springframework.web.util.UriComponents;
3735
import org.springframework.web.util.UriComponentsBuilder;
3836

39-
import com.fasterxml.jackson.databind.JsonNode;
40-
import com.fasterxml.jackson.databind.ObjectMapper;
41-
import com.fasterxml.jackson.databind.node.ArrayNode;
42-
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;
4343

4444
/**
4545
* @author evasiba
46-
*
4746
*/
4847
@Component
4948
public class ERQueryService {
5049

5150
static Logger log = (Logger) LoggerFactory.getLogger(ERQueryService.class);
52-
5351
private RestOperations rest;
54-
55-
public final static int DOWNSTREAM = 0;
56-
public final static int UPSTREAM = 1;
57-
public final static int DOWNANDUPSTREAM = 2;
58-
5952
@Getter
6053
@Value("${er.url}")
6154
private String url;
@@ -73,102 +66,104 @@ public void setRest(RestOperations rest) {
7366
* eventID.
7467
*
7568
* @param eventId
69+
* the id of the event.
7670
* @return ResponseEntity
7771
*/
7872
public ResponseEntity<String> getEventDataById(String eventId) {
79-
String erUrl = url.trim() + "{id}";
80-
log.info("The url is : " + erUrl);
81-
Map<String, String> params = new HashMap<>();
82-
params.put("id", eventId);
83-
ResponseEntity<String> response = null;
84-
log.info("The ID parameter is set");
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");
8578
try {
86-
response = rest.getForEntity(erUrl, String.class, params);
87-
log.info("The response is : " + response.toString());
88-
} catch (Exception e) {
89-
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);
9083
}
91-
return response;
84+
85+
return null;
9286
}
9387

9488
/**
9589
* This method is used to fetch only the upstream or downstream or both
96-
* event information from ER2.0 based on the eventID and searchAction
90+
* event information from ER2.0 based on the eventID and searchOption
9791
* conditions.
9892
*
9993
* @param eventId
100-
* @param searchAction
101-
* @param limitParam
102-
* @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.
103104
* @param tree
105+
* whether or not to retain the tree structure in the result.
104106
* @return ResponseEntity
105107
*/
108+
public ResponseEntity<JsonNode> getEventStreamDataById(String eventId, SearchOption searchOption, int limit,
109+
int levels, boolean tree) {
106110

107-
public ResponseEntity<JsonNode> getEventStreamDataById(String eventId, int searchAction, int limitParam,
108-
int levelsParam, boolean tree) {
109-
110-
String erUrl = url.trim() + eventId;
111-
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);
112113

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

120-
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();
121121
headers.setContentType(MediaType.APPLICATION_JSON);
122122

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

142127
try {
143-
uriParams = objectmapper.readTree("{}");
144-
if (searchAction == DOWNSTREAM) {
145-
putSearchParameter(uriParams, "dlt", linkTypes);
146-
} else if (searchAction == UPSTREAM) {
147-
putSearchParameter(uriParams, "ult", linkTypes);
148-
} else if (searchAction == DOWNANDUPSTREAM) {
149-
putSearchParameter(uriParams, "dlt", linkTypes);
150-
putSearchParameter(uriParams, "ult", linkTypes);
151-
}
152-
} catch (Exception e) {
153-
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);
154131
}
155-
return uriParams;
132+
133+
return null;
156134
}
157135

158-
/** Create an array node with link types for upstream or downstream query
159-
* @param params
160-
* @param actionString
161-
* @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
162142
*/
163-
public void putSearchParameter(JsonNode params, String actionString, String[] linkTypes) {
164-
ArrayNode node =((ObjectNode) params).putArray(actionString);
165-
for (String string : linkTypes) {
166-
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;
167159
}
160+
161+
return searchParameters;
168162
}
169163

170164
@PostConstruct
171165
public void init() {
166+
// TODO: is this needed?
172167
log.debug("The url parameter is : " + url);
173168
}
174169
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
3+
Copyright 2017 Ericsson AB.
4+
For a full list of individual contributors, please see the commit history.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
package com.ericsson.ei.erqueryservice;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
public enum LinkType {
24+
// Link types
25+
CAUSE,
26+
CONTEXT,
27+
FLOW_CONTEXT,
28+
ACTIVITY_EXECUTION,
29+
PREVIOUS_ACTIVITY_EXECUTION,
30+
PREVIOUS_VERSION,
31+
COMPOSITION,
32+
ENVIRONMENT,
33+
ARTIFACT,
34+
SUBJECT,
35+
ELEMENT,
36+
BASE,
37+
CHANGE,
38+
TEST_SUITE_EXECUTION,
39+
TEST_CASE_EXECUTION,
40+
IUT,
41+
TERC,
42+
MODIFIED_ANNOUNCEMENT,
43+
SUB_CONFIDENCE_LEVEL,
44+
REUSED_ARTIFACT,
45+
VERIFICATION_BASIS,
46+
ALL;
47+
48+
public static List<LinkType> asList() {
49+
return Arrays.asList(values());
50+
}
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
3+
Copyright 2017 Ericsson AB.
4+
For a full list of individual contributors, please see the commit history.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
package com.ericsson.ei.erqueryservice;
19+
20+
public enum SearchOption {
21+
DOWN_STREAM,
22+
UP_STREAM,
23+
UP_AND_DOWN_STREAM
24+
}

0 commit comments

Comments
 (0)