Skip to content

Commit 4b29c03

Browse files
authored
Free style query (#60)
* ADD: freestyle query service * ADD: RAML implementation * ADD: RAML implementation * fixes * ADD: unit test * Fix: merge conflict * fixes * Update service * FIX: test * CHANGE: loggers, endpoints and raml * Fix test * ADD: tests scenarios * FIX: test * FIX: response entity
1 parent f7cebe0 commit 4b29c03

18 files changed

+565
-125
lines changed

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ before_install:
1313
- chmod +x pom.xml
1414

1515
script:
16-
- mvn -DsomeModule.test.excludes="**/FlowTest.java, **/FlowTest2.java, **/TrafficGeneratedTest.java, **/FlowTestExternalComposition.java, **/FlowTestTestExecution.java, **/FlowSourceChangeObject.java" test
17-
- mvn -DsomeModule.test.includes="**/FlowTest.java" test
18-
- mvn -DsomeModule.test.includes="**/FlowTest2.java" test
19-
- mvn -DsomeModule.test.includes="**/TrafficGeneratedTest.java" test
20-
- mvn -DsomeModule.test.includes="**/FlowTestExternalComposition.java" test
21-
- mvn -DsomeModule.test.includes="**/FlowSourceChangeObject.java" test
22-
- mvn -DsomeModule.test.includes="**/FlowTestTestExecution.java" test
16+
- mvn clean install

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@
185185
<version>1.16.16</version>
186186
<scope>provided</scope>
187187
</dependency>
188+
<dependency>
189+
<groupId>org.jongo</groupId>
190+
<artifactId>jongo</artifactId>
191+
<version>1.3.0</version>
192+
</dependency>
188193
</dependencies>
189194
<build>
190195
<plugins>

src/main/java/com/ericsson/ei/controller/AggregatedObjectController.java renamed to src/main/java/com/ericsson/ei/controller/QueryAggregatedObjectController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
*/
1717
@RestController
18-
@RequestMapping(value = "/query/aggregatedObject", produces = "application/json")
19-
public interface AggregatedObjectController {
18+
@RequestMapping(value = "/queryAggregatedObject", produces = "application/json")
19+
public interface QueryAggregatedObjectController {
2020

2121

2222
/**

src/main/java/com/ericsson/ei/controller/AggregatedObjectControllerImpl.java renamed to src/main/java/com/ericsson/ei/controller/QueryAggregatedObjectControllerImpl.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
*/
1414
package com.ericsson.ei.controller;
1515

16-
import java.util.ArrayList;
17-
16+
import com.ericsson.ei.controller.model.QueryResponse;
17+
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,34 +24,33 @@
2424
import org.springframework.web.bind.annotation.CrossOrigin;
2525
import org.springframework.web.bind.annotation.RequestParam;
2626

27-
import com.ericsson.ei.controller.model.QueryResponse;
28-
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
27+
import java.util.ArrayList;
2928

3029
/**
3130
* This class represents the REST GET mechanism to extract the aggregated data
3231
* on the basis of the ID from the aggregatedObject.
33-
*
3432
*/
3533
@Component
3634
@CrossOrigin
37-
public class AggregatedObjectControllerImpl implements AggregatedObjectController {
35+
public class QueryAggregatedObjectControllerImpl implements QueryAggregatedObjectController {
3836

39-
static Logger log = (Logger) LoggerFactory.getLogger(AggregatedObjectControllerImpl.class);
37+
private static Logger LOGGER = (Logger) LoggerFactory.getLogger(QueryAggregatedObjectControllerImpl.class);
4038

4139
@Autowired
4240
private ProcessAggregatedObject processAggregatedObject;
4341

4442
/**
4543
* This method is responsible for the REST Get mechanism to extract the
4644
* aggregated data on the basis of the ID from the aggregatedObject.
47-
*
45+
*
4846
* @param id
4947
* @return ResponseEntity
5048
*/
5149
public ResponseEntity<QueryResponse> getQueryAggregatedObject(@RequestParam("ID") final String id) {
50+
QueryResponse queryResponse= new QueryResponse();
5251
ArrayList<String> response = processAggregatedObject.processQueryAggregatedObject(id);
53-
log.info("The response is : " + response.toString());
54-
return new ResponseEntity(response.toString(), HttpStatus.OK);
52+
queryResponse.setResponseEntity(response.toString());
53+
LOGGER.debug("The response is : " + response.toString());
54+
return new ResponseEntity(queryResponse, HttpStatus.OK);
5555
}
56-
57-
}
56+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
package com.ericsson.ei.controller;
3+
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
11+
/**
12+
* No description
13+
* (Generated with springmvc-raml-parser v.0.10.11)
14+
*
15+
*/
16+
@RestController
17+
@RequestMapping(value = "/query", produces = "application/json")
18+
public interface QueryController {
19+
20+
21+
/**
22+
* The REST GET method is used to query Aggregated Objects with the criterias requested, which are present as query parameters in the request URL.
23+
*
24+
*/
25+
@RequestMapping(value = "", method = RequestMethod.GET)
26+
public ResponseEntity<?> getQuery(
27+
@RequestParam
28+
String request);
29+
30+
/**
31+
* The REST POST method is used to query Aggregated Objects with the criterias requested, which are present in the request body of the request URL.
32+
*
33+
*/
34+
@RequestMapping(value = "", method = RequestMethod.POST)
35+
public ResponseEntity<?> updateQuery(
36+
@RequestParam
37+
String request);
38+
39+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2018 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.ericsson.ei.controller;
18+
19+
import com.ericsson.ei.controller.model.QueryResponse;
20+
import com.ericsson.ei.queryservice.ProcessQueryParams;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import io.swagger.annotations.Api;
23+
import io.swagger.annotations.ApiOperation;
24+
import org.json.JSONArray;
25+
import org.slf4j.Logger;
26+
import org.slf4j.LoggerFactory;
27+
import org.springframework.beans.factory.annotation.Autowired;
28+
import org.springframework.http.HttpStatus;
29+
import org.springframework.http.ResponseEntity;
30+
import org.springframework.stereotype.Component;
31+
import org.springframework.web.bind.annotation.CrossOrigin;
32+
import org.springframework.web.bind.annotation.RequestParam;
33+
34+
/**
35+
* This class represents the REST end-points for the query service. It can take
36+
* both query parameters and form parameters as criterias.
37+
*/
38+
@Component
39+
@CrossOrigin
40+
@Api(value = "query", description = "REST end-points for the freestyle query service")
41+
public class QueryControllerImpl implements QueryController {
42+
43+
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(QueryControllerImpl.class);
44+
45+
@Autowired
46+
private ProcessQueryParams processQueryParams;
47+
48+
private JSONArray result = null;
49+
50+
@Override
51+
@CrossOrigin
52+
@ApiOperation(value = "")
53+
public ResponseEntity<?> updateQuery(@RequestParam(value = "request") String request) {
54+
try {
55+
result = processQueryParams.filterFormParam(new ObjectMapper().readTree(request));
56+
} catch (Exception e) {
57+
LOGGER.error(e.getMessage());
58+
}
59+
return new ResponseEntity(result.toString(), HttpStatus.OK);
60+
}
61+
62+
@Override
63+
@CrossOrigin
64+
@ApiOperation(value = "")
65+
public ResponseEntity<?> getQuery(@RequestParam(value = "request") final String request) {
66+
try {
67+
result = processQueryParams.filterQueryParam(request);
68+
} catch (Exception e) {
69+
LOGGER.error(e.getMessage());
70+
}
71+
LOGGER.debug("Final Output : " + result.toString());
72+
return new ResponseEntity(result.toString(), HttpStatus.OK);
73+
}
74+
}

src/main/java/com/ericsson/ei/controller/MissedNotificationController.java renamed to src/main/java/com/ericsson/ei/controller/QueryMissedNotificationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*
1616
*/
1717
@RestController
18-
@RequestMapping(value = "/query/missedNotifications", produces = "application/json")
19-
public interface MissedNotificationController {
18+
@RequestMapping(value = "/queryMissedNotifications", produces = "application/json")
19+
public interface QueryMissedNotificationController {
2020

2121

2222
/**

src/main/java/com/ericsson/ei/controller/MissedNotificationControllerImpl.java renamed to src/main/java/com/ericsson/ei/controller/QueryMissedNotificationControllerImpl.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
*/
1414
package com.ericsson.ei.controller;
1515

16-
import java.util.ArrayList;
17-
import java.util.List;
18-
16+
import com.ericsson.ei.controller.model.QueryResponse;
17+
import com.ericsson.ei.queryservice.ProcessMissedNotification;
1918
import org.slf4j.Logger;
2019
import org.slf4j.LoggerFactory;
2120
import org.springframework.beans.factory.annotation.Autowired;
@@ -25,35 +24,34 @@
2524
import org.springframework.web.bind.annotation.CrossOrigin;
2625
import org.springframework.web.bind.annotation.RequestParam;
2726

28-
import com.ericsson.ei.controller.model.QueryResponse;
29-
import com.ericsson.ei.queryservice.ProcessMissedNotification;
27+
import java.util.List;
3028

3129
/**
3230
* This class represents the REST GET mechanism to extract the aggregated data
3331
* on the basis of the SubscriptionName from the Missed Notification Object.
34-
*
3532
*/
3633
@Component
3734
@CrossOrigin
38-
public class MissedNotificationControllerImpl implements MissedNotificationController {
35+
public class QueryMissedNotificationControllerImpl implements QueryMissedNotificationController {
3936

40-
static Logger log = (Logger) LoggerFactory.getLogger(MissedNotificationControllerImpl.class);
37+
private final static Logger LOGGER = (Logger) LoggerFactory.getLogger(QueryMissedNotificationControllerImpl.class);
4138

4239
@Autowired
4340
private ProcessMissedNotification processMissedNotification;
4441

4542
/**
4643
* This method is responsible for the REST GET mechanism to extract the data on
4744
* the basis of the SubscriptionName from the Missed Notification Object.
48-
*
45+
*
4946
* @param subscriptionName
5047
* @return ResponseEntity
5148
*/
52-
public ResponseEntity<QueryResponse> getQueryMissedNotifications(
53-
@RequestParam("SubscriptionName") final String subscriptionName) {
49+
public ResponseEntity<QueryResponse> getQueryMissedNotifications(@RequestParam("SubscriptionName") final String subscriptionName) {
50+
QueryResponse queryResponse = new QueryResponse();
5451
List<String> response = processMissedNotification.processQueryMissedNotification(subscriptionName);
55-
log.info("The response is : " + response.toString());
56-
return new ResponseEntity(response.toString(), HttpStatus.OK);
52+
queryResponse.setResponseEntity(response.toString());
53+
LOGGER.debug("The response is : " + response.toString());
54+
return new ResponseEntity(queryResponse, HttpStatus.OK);
5755
}
5856

5957
}

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

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,29 @@
1313
*/
1414
package com.ericsson.ei.queryservice;
1515

16-
import java.util.ArrayList;
17-
18-
import javax.annotation.PostConstruct;
19-
16+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
17+
import com.fasterxml.jackson.databind.JsonNode;
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import com.mongodb.DB;
20+
import com.mongodb.MongoClient;
21+
import org.bson.Document;
22+
import org.jongo.Jongo;
23+
import org.jongo.MongoCollection;
24+
import org.jongo.MongoCursor;
25+
import org.json.JSONArray;
26+
import org.json.JSONObject;
2027
import org.slf4j.Logger;
2128
import org.slf4j.LoggerFactory;
2229
import org.springframework.beans.factory.annotation.Autowired;
2330
import org.springframework.beans.factory.annotation.Value;
2431
import org.springframework.stereotype.Component;
2532

26-
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
27-
import com.fasterxml.jackson.databind.JsonNode;
28-
import com.fasterxml.jackson.databind.ObjectMapper;
33+
import javax.annotation.PostConstruct;
34+
import java.util.ArrayList;
2935

3036
/**
3137
* This class represents the mechanism to extract the aggregated data on the
3238
* basis of the ID from the aggregatedObject.
33-
*
34-
*
3539
*/
3640
@Component
3741
public class ProcessAggregatedObject {
@@ -42,38 +46,67 @@ public class ProcessAggregatedObject {
4246
@Value("${database.name}")
4347
private String aggregationDataBaseName;
4448

45-
static Logger log = (Logger) LoggerFactory.getLogger(ProcessAggregatedObject.class);
49+
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(ProcessAggregatedObject.class);
4650

4751
@Autowired
48-
MongoDBHandler handler;
52+
private MongoDBHandler handler;
4953

5054
/**
5155
* The method is responsible to extract the aggregated data on the basis of
5256
* the ID from the aggregatedObject.
53-
*
57+
*
5458
* @param id
5559
* @return ArrayList
5660
*/
5761
public ArrayList<String> processQueryAggregatedObject(String id) {
5862
ObjectMapper mapper = new ObjectMapper();
5963
String condition = "{\"_id\" : \"" + id + "\"}";
60-
log.info("The condition is : " + condition);
64+
LOGGER.debug("The condition is : " + condition);
6165
JsonNode jsonCondition = null;
6266
try {
6367
jsonCondition = mapper.readTree(condition);
6468
} catch (Exception e) {
65-
log.error(e.getMessage(), e);
69+
LOGGER.error(e.getMessage(), e);
6670
}
67-
log.info("The Json condition is : " + jsonCondition);
71+
LOGGER.debug("The Json condition is : " + jsonCondition);
6872
ArrayList<String> response = handler.find(aggregationDataBaseName, aggregationCollectionName,
6973
jsonCondition.toString());
7074
return response;
7175
}
7276

77+
/**
78+
* This method is responsible for fetching all the aggregatedObjects from
79+
* the Aggregation database and return it as JSONArray.
80+
*
81+
* @param request
82+
* @param AggregationDataBaseName
83+
* @param AggregationCollectionName
84+
* @return JSONArray
85+
*/
86+
public JSONArray processQueryAggregatedObject(JsonNode request, String AggregationDataBaseName, String AggregationCollectionName) {
87+
DB db = new MongoClient().getDB(AggregationDataBaseName);
88+
Jongo jongo = new Jongo(db);
89+
MongoCollection aggObjects = jongo.getCollection(AggregationCollectionName);
90+
LOGGER.debug("Successfully connected to AggregatedObject database");
91+
MongoCursor<Document> allDocuments = aggObjects.find(request.toString()).as(Document.class);
92+
LOGGER.debug("Number of document returned from AggregatedObject collection is : " + allDocuments.count());
93+
JSONArray jsonArray = new JSONArray();
94+
JSONObject doc = null;
95+
while (allDocuments.hasNext()) {
96+
Document temp = allDocuments.next();
97+
try {
98+
doc = new JSONObject(temp.toJson());
99+
} catch (Exception e) {
100+
LOGGER.error(e.getMessage(), e);
101+
}
102+
jsonArray.put(doc);
103+
}
104+
return jsonArray;
105+
}
106+
73107
@PostConstruct
74108
public void init() {
75-
log.debug("The Aggregated Database is : " + aggregationDataBaseName);
76-
log.debug("The Aggregated Collection is : " + aggregationCollectionName);
109+
LOGGER.debug("The Aggregated Database is : " + aggregationDataBaseName);
110+
LOGGER.debug("The Aggregated Collection is : " + aggregationCollectionName);
77111
}
78-
79-
}
112+
}

0 commit comments

Comments
 (0)