Skip to content

Commit 5ff2ddf

Browse files
Aggregated objects endpoint (#380)
* query end point changes to aggregated-objects/query
1 parent 4290636 commit 5ff2ddf

File tree

18 files changed

+341
-431
lines changed

18 files changed

+341
-431
lines changed

src/functionaltests/java/com/ericsson/ei/query/QueryAggregatedObjectsTestSteps.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.http.ResponseEntity;
2020
import org.springframework.test.context.TestPropertySource;
2121

22+
import com.ericsson.ei.controller.EntryPointConstantsUtils;
2223
import com.ericsson.ei.mongo.MongoCondition;
2324
import com.ericsson.ei.mongo.MongoDBHandler;
2425
import com.ericsson.ei.utils.FunctionalTestBase;
@@ -41,6 +42,8 @@
4142
@AutoConfigureMockMvc
4243
public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
4344

45+
private static final String CONTENT_TYPE = "application/json";
46+
4447
private static final Logger LOGGER = LoggerFactory.getLogger(QueryAggregatedObjectsTestSteps.class);
4548

4649
private static final String AGGREGATED_OBJ_JSON_PATH = "src/test/resources/AggregatedDocumentInternalCompositionLatest.json";
@@ -79,9 +82,8 @@ public class QueryAggregatedObjectsTestSteps extends FunctionalTestBase {
7982

8083
private ObjectMapper objMapper;
8184

82-
final static private String entryPointQueryAggregatedObject = "/queryAggregatedObject";
83-
final static private String entryPointQuery = "/query";
84-
final static private String entryPointFailedNotifications = "/failed-notifications";
85+
final static private String ENTRY_POINT_QUERY = "/aggregated-objects/query";
86+
final static private String ENTRY_POINT_FAILED_NOTIFICATIONS = "/failed-notifications";
8587

8688
public QueryAggregatedObjectsTestSteps() {
8789
objMapper = new ObjectMapper();
@@ -124,13 +126,11 @@ public void perform_valid_query_on_newly_created_aggregated_object() throws Thro
124126
HttpRequest getRequest = new HttpRequest(HttpMethod.GET);
125127
response = getRequest.setPort(applicationPort)
126128
.setHost(hostName)
127-
.addHeader("content-type", "application/json")
128-
.addHeader("Accept", "application/json")
129-
.setEndpoint(entryPointQueryAggregatedObject)
130-
.addParam("ID", documentId)
131-
.performRequest();
129+
.addHeader("content-type", CONTENT_TYPE)
130+
.addHeader("Accept", CONTENT_TYPE)
131+
.setEndpoint(EntryPointConstantsUtils.AGGREGATED_OBJECTS + "/" + documentId).performRequest();
132132

133-
LOGGER.debug("Response of /queryAggregatedObject RestApi, Status Code: " + response.getStatusCodeValue()
133+
LOGGER.debug("Response of /aggregated-objects RestApi, Status Code: " + response.getStatusCodeValue()
134134
+ "\nResponse: " + response.getBody().toString());
135135

136136
JsonNode jsonNodeResult = objMapper.readValue(response.getBody().toString(), JsonNode.class);
@@ -159,10 +159,9 @@ public void perform_invalid_query_on_created_aggregated_object() throws Throwabl
159159
HttpRequest getRequest = new HttpRequest(HttpMethod.GET);
160160
response = getRequest.setPort(applicationPort)
161161
.setHost(hostName)
162-
.addHeader("content-type", "application/json")
163-
.addHeader("Accept", "application/json")
164-
.setEndpoint(entryPointQueryAggregatedObject)
165-
.addParam("ID", invalidDocumentId)
162+
.addHeader("content-type", CONTENT_TYPE)
163+
.addHeader("Accept", CONTENT_TYPE)
164+
.setEndpoint(EntryPointConstantsUtils.AGGREGATED_OBJECTS + "/" + invalidDocumentId)
166165
.performRequest();
167166

168167
String responseAsString = response.getBody().toString();
@@ -196,9 +195,9 @@ public void perform_several_valid_freestyle_queries_on_created_Aggregated_object
196195
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
197196
response = postRequest.setPort(applicationPort)
198197
.setHost(hostName)
199-
.addHeader("content-type", "application/json")
200-
.addHeader("Accept", "application/json")
201-
.setEndpoint(entryPointQuery)
198+
.addHeader("content-type", CONTENT_TYPE)
199+
.addHeader("Accept", CONTENT_TYPE)
200+
.setEndpoint(ENTRY_POINT_QUERY)
202201
.setBody(formattedQuery)
203202
.performRequest();
204203

@@ -231,9 +230,9 @@ public void perform_invalid_freestyle_query_on_created_aggregated_object() throw
231230
HttpRequest getRequest = new HttpRequest(HttpMethod.POST);
232231
response = getRequest.setPort(applicationPort)
233232
.setHost(hostName)
234-
.addHeader("content-type", "application/json")
235-
.addHeader("Accept", "application/json")
236-
.setEndpoint(entryPointQuery)
233+
.addHeader("content-type", CONTENT_TYPE)
234+
.addHeader("Accept", CONTENT_TYPE)
235+
.setEndpoint(ENTRY_POINT_QUERY)
237236
.setBody(queryAggrObj)
238237
.performRequest();
239238

@@ -268,9 +267,9 @@ public void perform_a_query_for_missed_notification() throws Throwable {
268267
HttpRequest getRequest = new HttpRequest(HttpMethod.GET);
269268
response = getRequest.setPort(applicationPort)
270269
.setHost(hostName)
271-
.addHeader("content-type", "application/json")
272-
.addHeader("Accept", "application/json")
273-
.setEndpoint(entryPointFailedNotifications)
270+
.addHeader("content-type", CONTENT_TYPE)
271+
.addHeader("Accept", CONTENT_TYPE)
272+
.setEndpoint(ENTRY_POINT_FAILED_NOTIFICATIONS)
274273
.addParam("subscriptionName", subscriptionName)
275274
.performRequest();
276275

@@ -306,9 +305,9 @@ public void check_missed_notification_has_been_returned() throws Throwable {
306305
HttpRequest getRequest = new HttpRequest(HttpMethod.GET);
307306
response = getRequest.setPort(applicationPort)
308307
.setHost(hostName)
309-
.addHeader("content-type", "application/json")
310-
.addHeader("Accept", "application/json")
311-
.setEndpoint(entryPointFailedNotifications)
308+
.addHeader("content-type", CONTENT_TYPE)
309+
.addHeader("Accept", CONTENT_TYPE)
310+
.setEndpoint(ENTRY_POINT_FAILED_NOTIFICATIONS)
312311
.addParam("SubscriptionName", subscriptionName)
313312
.performRequest();
314313

@@ -338,9 +337,9 @@ public void perform_valid_query_and_filter_on_aggregated_object() throws Throwab
338337
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
339338
response = postRequest.setPort(applicationPort)
340339
.setHost(hostName)
341-
.addHeader("content-type", "application/json")
342-
.addHeader("Accept", "application/json")
343-
.setEndpoint(entryPointQuery)
340+
.addHeader("content-type", CONTENT_TYPE)
341+
.addHeader("Accept", CONTENT_TYPE)
342+
.setEndpoint(ENTRY_POINT_QUERY)
344343
.setBody(query)
345344
.performRequest();
346345

@@ -382,9 +381,9 @@ public void perform__query_and_filter_with_part_of_path() throws Throwable {
382381
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
383382
response = postRequest.setPort(applicationPort)
384383
.setHost(hostName)
385-
.addHeader("content-type", "application/json")
386-
.addHeader("Accept", "application/json")
387-
.setEndpoint(entryPointQuery )
384+
.addHeader("content-type", CONTENT_TYPE)
385+
.addHeader("Accept", CONTENT_TYPE)
386+
.setEndpoint(ENTRY_POINT_QUERY)
388387
.setBody(query)
389388
.performRequest();
390389

@@ -415,13 +414,14 @@ public void perform_query_to_retrieve_and_filter_out_confidence_level_informatio
415414
HttpRequest postRequest = new HttpRequest(HttpMethod.POST);
416415
response = postRequest.setPort(applicationPort)
417416
.setHost(hostName)
418-
.addHeader("content-type", "application/json")
419-
.addHeader("Accept", "application/json")
420-
.setEndpoint(entryPointQuery)
417+
.addHeader("content-type", CONTENT_TYPE)
418+
.addHeader("Accept", CONTENT_TYPE)
419+
.setEndpoint(ENTRY_POINT_QUERY)
421420
.setBody(formattedQuery)
422421
.performRequest();
423422

424-
LOGGER.debug("Response of /query RestApi, Status Code: " + response.getStatusCodeValue() + "\nResponse: "
423+
LOGGER.debug("Response of /aggregated-objects/query RestApi, Status Code: " + response.getStatusCodeValue()
424+
+ "\nResponse: "
425425
+ response.getBody().toString());
426426

427427
JsonNode jsonNodeResult = objMapper.readValue(response.getBody().toString(), JsonNode.class);

src/integrationtests/java/util/IntegrationTestBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ private void checkResult(final Map<String, JsonNode> expectedData)
279279
*/
280280
private JsonNode queryAggregatedObject(String id) throws URISyntaxException, IOException {
281281
HttpRequest httpRequest = new HttpRequest(HttpMethod.GET);
282-
String endpoint = "/queryAggregatedObject";
282+
String endpoint = "/aggregated-objects/" + id;
283283

284284
httpRequest.setHost(eiHost)
285285
.setPort(port)
286286
.addHeader("Content-type", "application/json")
287-
.addParam("ID", id)
288287
.setEndpoint(endpoint);
289288

290289
ResponseEntity<String> response = httpRequest.performRequest();

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,39 @@
66
import com.ericsson.ei.controller.model.QueryBody;
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.validation.annotation.Validated;
9+
import org.springframework.web.bind.annotation.PathVariable;
910
import org.springframework.web.bind.annotation.RequestBody;
1011
import org.springframework.web.bind.annotation.RequestMapping;
1112
import org.springframework.web.bind.annotation.RequestMethod;
1213
import org.springframework.web.bind.annotation.RestController;
1314

1415

1516
/**
16-
* This class retrieves aggregated objects given a free style query. Criteria is required to have in the request body, while options and filter are optional.
17+
* This class returns aggregated data given a specific ID of an aggregated object and can perform free style query as well..
1718
* (Generated with springmvc-raml-parser v.2.0.5)
1819
*
1920
*/
2021
@RestController
2122
@Validated
22-
@RequestMapping(value = "/query", produces = "application/json")
23-
public interface QueryController {
23+
@RequestMapping(value = "/aggregated-objects", produces = "application/json")
24+
public interface AggregatedObjectController {
2425

2526

27+
/**
28+
* This method retrieves aggregated data on a specific aggregated object, given an ID.
29+
*
30+
*/
31+
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
32+
public ResponseEntity<?> getAggregatedObjectById(
33+
@PathVariable
34+
String id, HttpServletRequest httpRequest);
35+
2636
/**
2737
* The REST POST method is used to query aggregated objects with the requested criteria, which are present in the request body.
2838
*
2939
*/
30-
@RequestMapping(value = "", method = RequestMethod.POST)
31-
public ResponseEntity<?> createQuery(
40+
@RequestMapping(value = "/query", method = RequestMethod.POST)
41+
public ResponseEntity<?> createAggregatedObjectsQuery(
3242
@Valid
3343
@RequestBody
3444
QueryBody queryBody, HttpServletRequest httpRequest);

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,45 @@
1717

1818
import javax.servlet.http.HttpServletRequest;
1919

20-
import io.swagger.annotations.Api;
21-
import io.swagger.annotations.ApiOperation;
20+
import org.json.JSONArray;
21+
import org.json.JSONObject;
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.http.HttpStatus;
2626
import org.springframework.http.ResponseEntity;
2727
import org.springframework.stereotype.Component;
2828
import org.springframework.web.bind.annotation.CrossOrigin;
29-
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.PathVariable;
30+
import org.springframework.web.bind.annotation.RequestBody;
3031

32+
import com.ericsson.ei.controller.model.QueryBody;
3133
import com.ericsson.ei.controller.model.QueryResponse;
3234
import com.ericsson.ei.controller.model.QueryResponseEntity;
3335
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
36+
import com.ericsson.ei.queryservice.ProcessQueryParams;
3437
import com.ericsson.ei.utils.ResponseMessage;
3538
import com.fasterxml.jackson.databind.ObjectMapper;
3639

40+
import io.swagger.annotations.Api;
41+
import io.swagger.annotations.ApiOperation;
42+
3743
/**
3844
* This class represents the REST GET mechanism to extract the aggregated data on the basis of the ID from the aggregatedObject.
3945
*/
4046
@Component
4147
@CrossOrigin
42-
@Api(value = "queryAggregatedObject", tags = {"Query aggregated object"})
43-
public class QueryAggregatedObjectControllerImpl implements QueryAggregatedObjectController {
48+
@Api(value = "aggregatedObject", tags = { "aggregated object" })
49+
public class AggregatedObjectControllerImpl implements AggregatedObjectController {
4450

45-
private static final Logger LOGGER = LoggerFactory.getLogger(QueryAggregatedObjectControllerImpl.class);
51+
private static final Logger LOGGER = LoggerFactory.getLogger(AggregatedObjectControllerImpl.class);
4652

4753
@Autowired
4854
private ProcessAggregatedObject processAggregatedObject;
4955

56+
@Autowired
57+
private ProcessQueryParams processQueryParams;
58+
5059
/**
5160
* This method is responsible for the REST Get mechanism to extract the aggregated data on the basis of the ID from the aggregatedObject.
5261
*
@@ -55,7 +64,8 @@ public class QueryAggregatedObjectControllerImpl implements QueryAggregatedObjec
5564
*/
5665
@Override
5766
@ApiOperation(value = "")
58-
public ResponseEntity<?> getQueryAggregatedObject(@RequestParam("ID") final String id, final HttpServletRequest httpRequest) {
67+
public ResponseEntity<?> getAggregatedObjectById(@PathVariable final String id,
68+
final HttpServletRequest httpRequest) {
5969
ObjectMapper mapper = new ObjectMapper();
6070
QueryResponseEntity queryResponseEntity = new QueryResponseEntity();
6171
QueryResponse queryResponse = new QueryResponse();
@@ -77,4 +87,38 @@ public ResponseEntity<?> getQueryAggregatedObject(@RequestParam("ID") final Stri
7787
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);
7888
}
7989
}
90+
91+
@Override
92+
@CrossOrigin
93+
@ApiOperation(value = "Perform a freestyle query to retrieve aggregated objects")
94+
public ResponseEntity<?> createAggregatedObjectsQuery(@RequestBody final QueryBody body,
95+
final HttpServletRequest httpRequest) {
96+
String emptyResponseContent = "[]";
97+
HttpStatus httpStatus;
98+
try {
99+
JSONObject criteria = new JSONObject(body.getCriteria().getAdditionalProperties());
100+
JSONObject options = null;
101+
String filter = "";
102+
if (body.getOptions() != null) {
103+
options = new JSONObject(body.getOptions().getAdditionalProperties());
104+
}
105+
if (body.getFilter() != null) {
106+
filter = body.getFilter();
107+
}
108+
109+
JSONArray result = processQueryParams.runQuery(criteria, options, filter);
110+
if (!result.toString().equalsIgnoreCase(emptyResponseContent)) {
111+
httpStatus = HttpStatus.OK;
112+
} else {
113+
httpStatus = HttpStatus.NO_CONTENT;
114+
}
115+
return new ResponseEntity<>(result.toString(), httpStatus);
116+
} catch (Exception e) {
117+
String errorMessage = "Internal Server Error: Failed to extract data from the Aggregated Object using freestyle query.";
118+
LOGGER.error(errorMessage, e);
119+
String errorJsonAsString = ResponseMessage.createJsonMessage(errorMessage);
120+
return new ResponseEntity<>(errorJsonAsString, HttpStatus.INTERNAL_SERVER_ERROR);
121+
}
122+
}
123+
80124
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ericsson.ei.controller;
2+
3+
public final class EntryPointConstantsUtils {
4+
5+
public static final String AGGREGATED_OBJECTS = "/aggregated-objects";
6+
7+
private EntryPointConstantsUtils() {
8+
throw new AssertionError();
9+
}
10+
}
11+

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)