Skip to content

Commit e3d2fc0

Browse files
Add configuration documentation and JMESPath examples (#286)
Add configuration documentation. Add section about JMESPath expressions in documentation. Improved javadoc, extracted method in ProcessQueryParams, renamed methods. Set which rules to in functional tests.
1 parent f64353f commit e3d2fc0

File tree

16 files changed

+441
-190
lines changed

16 files changed

+441
-190
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Visit [Eiffel Community](https://eiffel-community.github.io) to get started and
5757
- [**Email notification**](wiki/markdown/subscription-with-email-notification.md)
5858
- [**Step by Step Subscription Notification**](wiki/markdown/step-by-step-subscription-notification.md)
5959
1. [**Understanding rules**](wiki/markdown/rules.md)
60-
- [**Introduction**](wiki/markdown/rules.md#Introduction)
60+
- [**What is JMESPath?**](wiki/markdown/rules.md#What-is-JMESPath?)
6161
- [**Rule set up**](wiki/markdown/rules.md#Rule-set-up)
6262
- [**MergeResolverRules**](wiki/markdown/merge-resolver-rules.md)
6363
- [**History Rules**](wiki/markdown/history-rules.md)

src/functionaltests/java/com/ericsson/ei/utils/TestConfigs.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class TestConfigs {
2424

2525
protected static Map<Integer, AMQPBrokerManager> amqpBrokerMap = new HashMap<>();
2626

27-
AMQPBrokerManager createAmqpBroker() throws Exception {
27+
protected AMQPBrokerManager createAmqpBroker() throws Exception {
2828
// Generates a random port for amqpBroker and starts up a new broker
2929
int port = SocketUtils.findAvailableTcpPort();
3030

@@ -47,7 +47,7 @@ AMQPBrokerManager createAmqpBroker() throws Exception {
4747
return amqpBroker;
4848
}
4949

50-
void startUpMongoClient() throws IOException {
50+
protected void startUpMongoClient() throws IOException {
5151
try {
5252
MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
5353
mongoClient = testsFactory.newMongo();
@@ -59,7 +59,7 @@ void startUpMongoClient() throws IOException {
5959
}
6060
}
6161

62-
void setAuthorization() {
62+
protected void setAuthorization() {
6363
String password = StringUtils.newStringUtf8(Base64.encodeBase64("password".getBytes()));
6464
System.setProperty("ldap.enabled", "true");
6565
System.setProperty("ldap.url", "ldap://ldap.forumsys.com:389/dc=example,dc=com");
@@ -69,6 +69,10 @@ void setAuthorization() {
6969
System.setProperty("ldap.user.filter", "uid={0}");
7070
}
7171

72+
protected void setRules() {
73+
System.setProperty("rules", " /rules/ArtifactRules-Eiffel-Agen-Version.json");
74+
}
75+
7276
public static AMQPBrokerManager getBroker(int port) {
7377
return amqpBrokerMap.get(port);
7478
}

src/functionaltests/java/com/ericsson/ei/utils/TestContextInitializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class TestContextInitializer extends TestConfigs
1515
@Override
1616
public void initialize(ConfigurableApplicationContext ac) {
1717

18+
setRules();
19+
1820
try {
1921
createAmqpBroker();
2022
startUpMongoClient();
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"criteria": {
2+
"criteria": {
33
"$where" : "function() {
44
var searchKey = 'id';
5-
var value = 'JIRA-1234';
5+
var value = 'JIRA-1234';
66
return searchInObj(obj);
7-
function searchInObj(obj){
8-
for (var k in obj){
9-
if (obj[k] == value && k == searchKey) {
10-
return true;
7+
function searchInObj(obj){
8+
for (var k in obj){
9+
if (obj[k] == value && k == searchKey) {
10+
return true;
1111
}
12-
13-
if (isObject(obj[k]) && obj[k] !== null) {
12+
13+
if (isObject(obj[k]) && obj[k] !== null) {
1414
if (searchInObj(obj[k])) {
1515
return true;
1616
}
17-
}
18-
}
17+
}
18+
}
1919
return false;
20-
}
21-
}"
20+
}
21+
}"
2222
},
23-
"filter": "{id: aggregatedObject.id, artifactGav:aggregatedObject.gav, confidenceLevels:aggregatedObject.confidenceLevels[?value=='SUCCESS'].{name: name, value: value}}"
23+
"filter": "{id:aggregatedObject.id, artifactIdentity:aggregatedObject.identity, confidenceLevels:aggregatedObject.confidenceLevels[?value=='SUCCESS'].{name: name, value: value}}"
2424
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import io.swagger.annotations.ApiOperation;
3535

3636
/**
37-
* This class represents the REST end-points for the query service. It can take
38-
* both query parameters and form parameters as criterias.
37+
* This class represents the REST end-points for the query service. Criteria is
38+
* required to have in the request body, while options and filter are optional.
3939
*/
4040
@Component
4141
@CrossOrigin
@@ -64,7 +64,7 @@ public ResponseEntity<?> createQuery(@RequestBody final QueryBody body) {
6464
filter = body.getFilter();
6565
}
6666

67-
JSONArray result = processQueryParams.filterFormParam(criteria, options, filter);
67+
JSONArray result = processQueryParams.runQuery(criteria, options, filter);
6868
if(!result.toString().equalsIgnoreCase(emptyResponseContent)) {
6969
httpStatus = HttpStatus.OK;
7070
} else {

src/main/java/com/ericsson/ei/queryservice/ProcessAggregatedObject.java

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import java.util.Iterator;
1818
import java.util.List;
1919

20-
import javax.annotation.PostConstruct;
21-
2220
import org.json.JSONArray;
2321
import org.json.JSONObject;
2422
import org.slf4j.Logger;
@@ -32,8 +30,8 @@
3230
import com.fasterxml.jackson.databind.ObjectMapper;
3331

3432
/**
35-
* This class represents the mechanism to extract the aggregated data on the
36-
* basis of the ID from the aggregatedObject.
33+
* This class represents the mechanism to extract the aggregated object, which
34+
* matches the given search criteria, from the database.
3735
*/
3836
@Component
3937
public class ProcessAggregatedObject {
@@ -47,71 +45,72 @@ public class ProcessAggregatedObject {
4745
private String aggregationDataBaseName;
4846

4947
@Autowired
50-
private MongoDBHandler handler;
48+
private MongoDBHandler mongoDBHandler;
5149

5250
/**
53-
* The method is responsible to extract the aggregated data on the basis of the
54-
* ID from the aggregatedObject.
51+
* The method is responsible to extract the aggregated data given the
52+
* ID from the aggregated object.
5553
*
5654
* @param id
5755
* @return ArrayList
5856
*/
5957
public ArrayList<String> processQueryAggregatedObject(String id) {
6058
ObjectMapper mapper = new ObjectMapper();
6159
String query = "{\"_id\": \"" + id + "\"}";
62-
63-
LOGGER.debug("The condition is : " + query);
6460
JsonNode jsonCondition = null;
61+
6562
try {
6663
jsonCondition = mapper.readTree(query);
6764
} catch (Exception e) {
6865
LOGGER.error(e.getMessage(), e);
6966
}
70-
LOGGER.debug("The Json condition is : " + jsonCondition);
71-
ArrayList<String> response = handler.find(aggregationDataBaseName, aggregationCollectionName,
67+
LOGGER.debug("The JSON condition is: {}", jsonCondition);
68+
ArrayList<String> response = mongoDBHandler.find(aggregationDataBaseName, aggregationCollectionName,
7269
jsonCondition.toString());
7370
return response;
7471
}
7572

7673
/**
77-
* The method is responsible to extract the aggregated data on the basis of the
78-
* ID from the aggregatedObject.
74+
* The method is responsible to extract the aggregated data given the
75+
* templateName from the aggregated object.
7976
*
8077
* @param templateName
8178
* @return ArrayList
8279
*/
8380
public ArrayList<String> getAggregatedObjectByTemplateName(String templateName) {
8481
String condition = "{\"aggregatedObject.id\": /.*" + templateName + "/}";
85-
LOGGER.debug("The Json condition is : " + condition);
86-
return handler.find(aggregationDataBaseName, aggregationCollectionName, condition);
82+
LOGGER.debug("The JSON condition is: {}", condition);
83+
return mongoDBHandler.find(aggregationDataBaseName, aggregationCollectionName, condition);
8784
}
8885

8986
/**
90-
* The method is responsible for the delete the aggregated object using template
91-
* name suffix
87+
* This method is responsible for deleting the aggregated object with given
88+
* template name suffix
9289
*
9390
* @param templateName
9491
* @return boolean
9592
*/
9693
public boolean deleteAggregatedObject(String templateName) {
9794
String condition = "{\"aggregatedObject.id\": /.*" + templateName + "/}";
98-
LOGGER.debug("The Json condition for delete aggregated object is : " + condition);
99-
return handler.dropDocument(aggregationDataBaseName, aggregationCollectionName, condition);
95+
LOGGER.debug("The JSON condition for deleting aggregated object is: {}", condition);
96+
return mongoDBHandler.dropDocument(aggregationDataBaseName, aggregationCollectionName, condition);
10097
}
10198

10299
/**
103-
* This method is responsible for fetching all the aggregatedObjects from the
104-
* Aggregation database and return it as JSONArray.
100+
* This method is responsible for fetching all the aggregated objects from the
101+
* aggregation database based on the given query and returns the result as a
102+
* JSONArray.
105103
*
106-
* @param request
104+
* @param query
105+
* A String containing search criteria to use
107106
* @param AggregationDataBaseName
108107
* @param AggregationCollectionName
109108
* @return JSONArray
110109
*/
111-
public JSONArray processQueryAggregatedObject(String request, String AggregationDataBaseName,
110+
public JSONArray processQueryAggregatedObject(String query, String AggregationDataBaseName,
112111
String AggregationCollectionName) {
113-
List<String> allDocuments = handler.find(AggregationDataBaseName, AggregationCollectionName, request);
114-
LOGGER.debug("Number of document returned from AggregatedObject collection is : " + allDocuments.size());
112+
List<String> allDocuments = mongoDBHandler.find(AggregationDataBaseName, AggregationCollectionName, query);
113+
LOGGER.debug("Number of documents returned from {} collection is : {}", AggregationCollectionName, allDocuments.size());
115114
Iterator<String> allDocumentsItr = allDocuments.iterator();
116115
JSONArray jsonArray = new JSONArray();
117116
JSONObject doc = null;
@@ -127,9 +126,4 @@ public JSONArray processQueryAggregatedObject(String request, String Aggregation
127126
return jsonArray;
128127
}
129128

130-
@PostConstruct
131-
public void init() {
132-
LOGGER.debug("The Aggregated Database is : " + aggregationDataBaseName + "\nThe Aggregated Collection is : "
133-
+ aggregationCollectionName);
134-
}
135129
}

0 commit comments

Comments
 (0)