Skip to content

Commit e2c3ddb

Browse files
EI-backend queryAggregatedObject returns Object instead of string (#230)
* minor change in integration test and controller * correction in functional test * fix integration tests
1 parent 717d160 commit e2c3ddb

File tree

10 files changed

+336
-159
lines changed

10 files changed

+336
-159
lines changed

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

Lines changed: 150 additions & 110 deletions
Large diffs are not rendered by default.

src/integrationtests/java/util/IntegrationTestBase.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,12 @@ private JsonNode queryAggregatedObject(String id) throws URISyntaxException, IOE
293293
.addParam("ID", id)
294294
.setEndpoint(endpoint);
295295

296-
JsonNode actualJSON = null;
297-
298296
//The response contains the aggregated object as a jsonstring. Makes it this wierd to get out.
299297
ResponseEntity<String> response = httpRequest.performRequest();
300298
JsonNode body = objectMapper.readTree(response.getBody());
301-
JsonNode responseEntity = objectMapper.readTree(body.get("responseEntity").asText());
302-
actualJSON = responseEntity.get(0);
299+
JsonNode responseEntity = body.get("queryResponseEntity");
303300

304-
return actualJSON;
301+
return responseEntity;
305302
}
306303

307304
private RabbitTemplate createRabbitMqTemplate() {

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import org.springframework.web.bind.annotation.RequestParam;
2626

2727
import com.ericsson.ei.controller.model.QueryResponse;
28+
import com.ericsson.ei.controller.model.QueryResponseEntity;
2829
import com.ericsson.ei.queryservice.ProcessAggregatedObject;
30+
import com.fasterxml.jackson.databind.ObjectMapper;
31+
2932

3033
/**
3134
* This class represents the REST GET mechanism to extract the aggregated data
@@ -49,24 +52,25 @@ public class QueryAggregatedObjectControllerImpl implements QueryAggregatedObjec
4952
*/
5053
@Override
5154
public ResponseEntity<QueryResponse> getQueryAggregatedObject(@RequestParam("ID") final String id) {
55+
ObjectMapper mapper = new ObjectMapper();
56+
QueryResponseEntity queryResponseEntity = new QueryResponseEntity();
5257
QueryResponse queryResponse = new QueryResponse();
53-
String emptyResponseContent = "[]";
54-
HttpStatus httpStatus;
58+
HttpStatus httpStatus = HttpStatus.NO_CONTENT;
5559
try {
5660
List<String> response = processAggregatedObject.processQueryAggregatedObject(id);
57-
queryResponse.setResponseEntity(response.toString());
58-
LOGGER.debug("The response is: " + response.toString());
59-
if(!queryResponse.getResponseEntity().equalsIgnoreCase(emptyResponseContent)) {
61+
if (!response.isEmpty()) {
62+
queryResponseEntity = mapper.readValue(response.get(0), QueryResponseEntity.class);
6063
httpStatus = HttpStatus.OK;
61-
} else {
62-
httpStatus = HttpStatus.NO_CONTENT;
6364
}
65+
66+
queryResponse.setQueryResponseEntity(queryResponseEntity);
67+
LOGGER.debug("The response is: " + response.toString());
6468
return new ResponseEntity<>(queryResponse, httpStatus);
6569
} catch (Exception e) {
66-
String errorMessage = "Failed to extract the aggregated data from the Aggregated Object based on ID "
67-
+ id + ". Error message:\n" + e.getMessage();
70+
String errorMessage = "Failed to extract the aggregated data from the Aggregated Object based on ID " + id
71+
+ ". Error message:\n" + e.getMessage();
6872
LOGGER.error(errorMessage, e);
69-
queryResponse.setResponseEntity(errorMessage);
73+
queryResponse.setAdditionalProperty("errorMessage", errorMessage);
7074
return new ResponseEntity<>(queryResponse, HttpStatus.INTERNAL_SERVER_ERROR);
7175
}
7276
}

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

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

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

27-
import java.util.List;
27+
import com.ericsson.ei.controller.model.QueryResponse;
28+
import com.ericsson.ei.controller.model.QueryResponseEntity;
29+
import com.ericsson.ei.queryservice.ProcessMissedNotification;
30+
import com.fasterxml.jackson.databind.ObjectMapper;
2831

2932
/**
3033
* This class represents the REST GET mechanism to extract the aggregated data
@@ -34,7 +37,7 @@
3437
@CrossOrigin
3538
public class QueryMissedNotificationControllerImpl implements QueryMissedNotificationController {
3639

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

3942
@Autowired
4043
private ProcessMissedNotification processMissedNotification;
@@ -46,21 +49,30 @@ public class QueryMissedNotificationControllerImpl implements QueryMissedNotific
4649
* @param subscriptionName
4750
* @return ResponseEntity
4851
*/
49-
public ResponseEntity<QueryResponse> getQueryMissedNotifications(@RequestParam("SubscriptionName") final String subscriptionName) {
52+
@Override
53+
public ResponseEntity<QueryResponse> getQueryMissedNotifications(
54+
@RequestParam("SubscriptionName") final String subscriptionName) {
55+
ObjectMapper mapper = new ObjectMapper();
5056
QueryResponse queryResponse = new QueryResponse();
57+
QueryResponseEntity queryResponseEntity = new QueryResponseEntity();
5158
try {
5259
List<String> response = processMissedNotification.processQueryMissedNotification(subscriptionName);
53-
queryResponse.setResponseEntity(response.toString());
60+
if (!response.isEmpty()) {
61+
queryResponseEntity = mapper.readValue(response.get(0), QueryResponseEntity.class);
62+
}
63+
queryResponse.setQueryResponseEntity(queryResponseEntity);
5464
LOGGER.debug("The response is : " + response.toString());
5565
if (processMissedNotification.deleteMissedNotification(subscriptionName)) {
56-
LOGGER.debug("Missed notification with subscription name " + subscriptionName + " was successfully removed from database");
66+
LOGGER.debug("Missed notification with subscription name " + subscriptionName
67+
+ " was successfully removed from database");
5768
}
5869
return new ResponseEntity<>(queryResponse, HttpStatus.OK);
5970
} catch (Exception e) {
6071
String errorMessage = "Failed to extract the data from the Missed Notification Object based on subscription name "
61-
+ subscriptionName + ". Error message:\n" + e.getMessage();
72+
+ subscriptionName + ". Error message:\n" + e.getMessage();
73+
queryResponseEntity.setAdditionalProperty("errorMessage", errorMessage);
6274
LOGGER.error(errorMessage, e);
63-
queryResponse.setResponseEntity(errorMessage);
75+
queryResponse.setQueryResponseEntity(queryResponseEntity);
6476
return new ResponseEntity<>(queryResponse, HttpStatus.INTERNAL_SERVER_ERROR);
6577
}
6678
}

src/main/java/com/ericsson/ei/controller/model/QueryResponse.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@
1616

1717
@JsonInclude(JsonInclude.Include.NON_NULL)
1818
@JsonPropertyOrder({
19-
"responseEntity"
19+
"queryResponseEntity"
2020
})
2121
public class QueryResponse {
2222

23-
@JsonProperty("responseEntity")
24-
private String responseEntity;
23+
@JsonProperty("queryResponseEntity")
24+
@Valid
25+
private QueryResponseEntity queryResponseEntity;
2526
@JsonIgnore
2627
@Valid
2728
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
2829

29-
@JsonProperty("responseEntity")
30-
public String getResponseEntity() {
31-
return responseEntity;
30+
@JsonProperty("queryResponseEntity")
31+
public QueryResponseEntity getQueryResponseEntity() {
32+
return queryResponseEntity;
3233
}
3334

34-
@JsonProperty("responseEntity")
35-
public void setResponseEntity(String responseEntity) {
36-
this.responseEntity = responseEntity;
35+
@JsonProperty("queryResponseEntity")
36+
public void setQueryResponseEntity(QueryResponseEntity queryResponseEntity) {
37+
this.queryResponseEntity = queryResponseEntity;
3738
}
3839

3940
@JsonAnyGetter
@@ -48,12 +49,12 @@ public void setAdditionalProperty(String name, Object value) {
4849

4950
@Override
5051
public String toString() {
51-
return new ToStringBuilder(this).append("responseEntity", responseEntity).append("additionalProperties", additionalProperties).toString();
52+
return new ToStringBuilder(this).append("queryResponseEntity", queryResponseEntity).append("additionalProperties", additionalProperties).toString();
5253
}
5354

5455
@Override
5556
public int hashCode() {
56-
return new HashCodeBuilder().append(responseEntity).append(additionalProperties).toHashCode();
57+
return new HashCodeBuilder().append(queryResponseEntity).append(additionalProperties).toHashCode();
5758
}
5859

5960
@Override
@@ -65,7 +66,7 @@ public boolean equals(Object other) {
6566
return false;
6667
}
6768
QueryResponse rhs = ((QueryResponse) other);
68-
return new EqualsBuilder().append(responseEntity, rhs.responseEntity).append(additionalProperties, rhs.additionalProperties).isEquals();
69+
return new EqualsBuilder().append(queryResponseEntity, rhs.queryResponseEntity).append(additionalProperties, rhs.additionalProperties).isEquals();
6970
}
7071

7172
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
package com.ericsson.ei.controller.model;
3+
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
import javax.validation.Valid;
7+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
8+
import com.fasterxml.jackson.annotation.JsonAnySetter;
9+
import com.fasterxml.jackson.annotation.JsonIgnore;
10+
import com.fasterxml.jackson.annotation.JsonInclude;
11+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
12+
import org.apache.commons.lang3.builder.EqualsBuilder;
13+
import org.apache.commons.lang3.builder.HashCodeBuilder;
14+
import org.apache.commons.lang3.builder.ToStringBuilder;
15+
16+
@JsonInclude(JsonInclude.Include.NON_NULL)
17+
@JsonPropertyOrder({
18+
19+
})
20+
public class QueryResponseEntity {
21+
22+
@JsonIgnore
23+
@Valid
24+
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
25+
26+
@JsonAnyGetter
27+
public Map<String, Object> getAdditionalProperties() {
28+
return this.additionalProperties;
29+
}
30+
31+
@JsonAnySetter
32+
public void setAdditionalProperty(String name, Object value) {
33+
this.additionalProperties.put(name, value);
34+
}
35+
36+
@Override
37+
public String toString() {
38+
return new ToStringBuilder(this).append("additionalProperties", additionalProperties).toString();
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return new HashCodeBuilder().append(additionalProperties).toHashCode();
44+
}
45+
46+
@Override
47+
public boolean equals(Object other) {
48+
if (other == this) {
49+
return true;
50+
}
51+
if ((other instanceof QueryResponseEntity) == false) {
52+
return false;
53+
}
54+
QueryResponseEntity rhs = ((QueryResponseEntity) other);
55+
return new EqualsBuilder().append(additionalProperties, rhs.additionalProperties).isEquals();
56+
}
57+
58+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
package com.ericsson.ei.controller.model;
3+
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import javax.validation.Valid;
8+
9+
import org.apache.commons.lang3.builder.EqualsBuilder;
10+
import org.apache.commons.lang3.builder.HashCodeBuilder;
11+
import org.apache.commons.lang3.builder.ToStringBuilder;
12+
13+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
14+
import com.fasterxml.jackson.annotation.JsonAnySetter;
15+
import com.fasterxml.jackson.annotation.JsonIgnore;
16+
import com.fasterxml.jackson.annotation.JsonInclude;
17+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
18+
19+
@JsonInclude(JsonInclude.Include.NON_NULL)
20+
@JsonPropertyOrder({
21+
22+
})
23+
public class ResponseEntity {
24+
25+
@JsonIgnore
26+
@Valid
27+
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
28+
29+
@JsonAnyGetter
30+
public Map<String, Object> getAdditionalProperties() {
31+
return this.additionalProperties;
32+
}
33+
34+
@JsonAnySetter
35+
public void setAdditionalProperty(String name, Object value) {
36+
this.additionalProperties.put(name, value);
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return new ToStringBuilder(this).append("additionalProperties", additionalProperties).toString();
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return new HashCodeBuilder().append(additionalProperties).toHashCode();
47+
}
48+
49+
@Override
50+
public boolean equals(Object other) {
51+
if (other == this) {
52+
return true;
53+
}
54+
if ((other instanceof ResponseEntity) == false) {
55+
return false;
56+
}
57+
ResponseEntity rhs = ((ResponseEntity) other);
58+
return new EqualsBuilder().append(additionalProperties, rhs.additionalProperties).isEquals();
59+
}
60+
61+
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public class ProcessAggregatedObject {
5050
private MongoDBHandler handler;
5151

5252
/**
53-
* The method is responsible to extract the aggregated data on the basis of
54-
* the ID from the aggregatedObject.
53+
* The method is responsible to extract the aggregated data on the basis of the
54+
* ID from the aggregatedObject.
5555
*
5656
* @param id
5757
* @return ArrayList
@@ -74,8 +74,8 @@ public ArrayList<String> processQueryAggregatedObject(String id) {
7474
}
7575

7676
/**
77-
* The method is responsible to extract the aggregated data on the basis of
78-
* the ID from the aggregatedObject.
77+
* The method is responsible to extract the aggregated data on the basis of the
78+
* ID from the aggregatedObject.
7979
*
8080
* @param templateName
8181
* @return ArrayList
@@ -87,7 +87,8 @@ public ArrayList<String> getAggregatedObjectByTemplateName(String templateName)
8787
}
8888

8989
/**
90-
* The method is responsible for the delete the aggregated object using template name suffix
90+
* The method is responsible for the delete the aggregated object using template
91+
* name suffix
9192
*
9293
* @param templateName
9394
* @return boolean
@@ -99,15 +100,16 @@ public boolean deleteAggregatedObject(String templateName) {
99100
}
100101

101102
/**
102-
* This method is responsible for fetching all the aggregatedObjects from
103-
* the Aggregation database and return it as JSONArray.
103+
* This method is responsible for fetching all the aggregatedObjects from the
104+
* Aggregation database and return it as JSONArray.
104105
*
105106
* @param request
106107
* @param AggregationDataBaseName
107108
* @param AggregationCollectionName
108109
* @return JSONArray
109110
*/
110-
public JSONArray processQueryAggregatedObject(String request, String AggregationDataBaseName, String AggregationCollectionName) {
111+
public JSONArray processQueryAggregatedObject(String request, String AggregationDataBaseName,
112+
String AggregationCollectionName) {
111113
List<String> allDocuments = handler.find(AggregationDataBaseName, AggregationCollectionName, request);
112114
LOGGER.debug("Number of document returned from AggregatedObject collection is : " + allDocuments.size());
113115
Iterator<String> allDocumentsItr = allDocuments.iterator();
@@ -127,7 +129,7 @@ public JSONArray processQueryAggregatedObject(String request, String Aggregation
127129

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

src/main/resources/public/raml/schemas/string_service_response.schema

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"$schema":"http://json-schema.org/draft-04/schema#",
33
"javaType":"com.ericsson.ei.controller.model.QueryResponse",
44
"properties":{
5-
"responseEntity":{
6-
"type":"string"
5+
"queryResponseEntity":{
6+
"type":"object"
77
}
88
},
99
"type":"object"

src/test/java/com/ericsson/ei/subscriptionhandler/test/SubscriptionHandlerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ public void testQueryMissedNotificationEndPoint() throws Exception {
313313
.perform(MockMvcRequestBuilders.get(missedNotificationUrl).param("SubscriptionName", subscriptionName))
314314
.andReturn();
315315
String response = result.getResponse().getContentAsString().replace("\\", "");
316-
assertEquals("{\"responseEntity\":\"[" + input.toString().replace("\\", "") + "]\"}", response);
316+
assertEquals(
317+
"{\"queryResponseEntity\":" + input.toString() + "}",
318+
response);
317319
assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus());
318320
}
319321

0 commit comments

Comments
 (0)